﻿

//alert('gallery');
$(document).ready(function() {

    $("div#imgthumbs ul li").click(doSmallImageClick);

});

var first_zoomhref = '';
var first_imgsrc = '';

function doSmallImageClick() {
    var itemCount = $("div#fullframe img").length;

    if (first_zoomhref.length == 0) {
        first_zoomhref = $("div#fullframe a:eq(0)").attr("href"); ;
        first_imgsrc = $("div#fullframe a:eq(0)").children().eq(0).attr("src"); ;
    }

    if (itemCount > 1) {
        
        $(".jqzoom").unbind();
		/***ORIGINAL****
	   $("div#fullframe a:eq(0)").fadeOut("slow",
            function doFade() { $("div#fullframe a:eq(0)").fadeIn("slow");
            });
			
			var classname = ($(this).attr('class'));
        rExp = /img/gi;
        var imageIndex = parseInt(classname.replace(rExp, "")) - 1;

        if (imageIndex == 0) {
            $("div#fullframe a:eq(0)").attr("href", first_zoomhref);
            $("div#fullframe a:eq(0)").children().eq(0).attr("src", first_imgsrc);            
        }
        else {
            var zoomhref = $("div#fullframe a:eq(" + imageIndex + ")").attr("href");
            var imgsrc = $("div#fullframe a:eq(" + imageIndex + ")").children().eq(0).attr("src");
            $("div#fullframe a:eq(0)").attr("href", zoomhref);
            $("div#fullframe a:eq(0)").children().eq(0).attr("src", imgsrc);
        }
			**/
      
			
			 $("div#fullframe a:eq(0)").fadeOut("slow",
            function doFade() { 

			if (imageIndex == 0) {
			
				$("div#fullframe a:eq(0)").attr("href", first_zoomhref);
				$("div#fullframe a:eq(0)").children().eq(0).attr("src", first_imgsrc);            
			}
			else {			
				var zoomhref = $("div#fullframe a:eq(" + imageIndex + ")").attr("href");
				var imgsrc = $("div#fullframe a:eq(" + imageIndex + ")").children().eq(0).attr("src");
				$("div#fullframe a:eq(0)").attr("href", zoomhref);
				$("div#fullframe a:eq(0)").children().eq(0).attr("src", imgsrc);
			}
			/*************************************************************************
			Make sure that we dont initiate the zoom until the image is at its place
			*************************************************************************/
			$("div#fullframe a:eq(0)").fadeIn("slow",
			function() {

					  $(".jqzoom").jqzoom();
		  });
            });
     			var classname = ($(this).attr('class'));
				rExp = /img/gi;
				var imageIndex = parseInt(classname.replace(rExp, "")) - 1;
/*
        for (var i = 0; i < itemCount; i++) {
            
        if (i == itemCount - 1)

        else    
        $("div#fullframe a:eq(" + i + ")").fadeOut("slow");
        }
        */
    }
}

