
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
};

var currentSelectionId = 1;
var currentZoomId = 1;


function showSelection(sectionId, zoomId) {
	if(currentSelectionId == sectionId && currentZoomId == zoomId) return;
	$("#zoom_" + currentSelectionId + "_" + currentZoomId).hide("fade");
	$("#descr_" + currentSelectionId + "_" + currentZoomId).hide("fade");
	$("#lnk_" + currentSelectionId + "_" + currentZoomId).hide("fade");
	currentSelectionId = sectionId;
	currentZoomId = zoomId;
	$("#zoom_" + currentSelectionId + "_" + currentZoomId).show("fade");
	$("#descr_" + currentSelectionId + "_" + currentZoomId).show("fade");
	
}
$(function() {
	var currentImage = 1;
	var totImage = $("#totimage").val()>>0;
	
	$(".lnkimage").hover( 
	    function() { 
	      $(this).attr("src", "img/selection_hover.png");
	    }, 
	    function() { 
	    	$(this).attr("src", "img/selection.png");
	    }
	);
	
	$(".thumb").hover( 
	    function() { 
	      $("img", this).addClass("over");
	    }, 
	    function() { 
	    	$("img", this).removeClass("over");
	    }
	);
	$(".navigator").hover( 
	    function() { 
	      $(this).addClass("over");
	      $("img", this).show();
	    }, 
	    function() { 
	    	$(this).removeClass("over");
	    	$("img", this).hide();		
	    }
	);
	$("[id^='thumb']").click(
			function() {
				var id = $(this).attr("id");
				id = id.replace(/thumb_/gi, "");
				id = id>>0;
				$("img").removeClass("sel");
				$("#image_" + currentImage).toggle("fade");
				$("#section_" + currentImage).toggle("fade");
				currentImage = id;
				$("#image_" + currentImage).toggle("fade");
				$("#section_" + currentImage).toggle("fade");
				$("img", this).addClass("sel");
				$("[id^='lnk_" + currentSelectionId + "']").hide();				
				showSelection(currentImage, 1);
				$("[id^='lnk_" + currentSelectionId + "']").show();
			}
	);
	$("#nextimage").click(
			function() {
				
				$("#image_" + currentImage).toggle("fade");
				if(currentImage == totImage) currentImage = 0;
				currentImage++;
				$("#image_" + currentImage).toggle("fade");
				$("img").removeClass("sel");
				$("#thumb_" + currentImage + " img").addClass("sel");
			}
	);
	$("#previmage").click(
			function() {
				$("#image_" + currentImage).toggle("fade");
				currentImage--;
				if(currentImage == 0) currentImage = totImage;
				$("#image_" + currentImage).toggle("fade");
				$("img").removeClass("sel");
				$("#thumb_" + currentImage + " img").addClass("sel");
			}
	);
	
});
