// JavaScript Document

//function imageShow

$(document).ready(function()
{
	var imageId = 0;
	
	$("#boxBg").css('opacity',0.4);
	$("#largeImage").load(function()
	 { 
		reposition();
		$("#showBox").show();
		btnCheck();
	})
	$(".showBoxNext").click(function()
	{
		imageId--;
		$.ajax({
		   type: "POST",
		   url: "/snippets/image.php",
		   data: "imageId=" + imageId,
		   success: function(html){
				$("#largeImage").attr('src',html);
			}
		 })		
	})
	$(".showBoxPrev").click(function()
	{
		imageId++;
		$.ajax({
		   type: "POST",
		   url: "/snippets/image.php",
		   data: "imageId=" + imageId,
		   success: function(html){
				$("#largeImage").attr('src',html);
			}
		 })		
	})
	$(".thumb").click(function()
	{
		//Add background layer Add Content Layer			
		$("#boxBg").show();
		//Get new image
		$.ajax({
		   type: "POST",
		   url: "/snippets/image.php",
		   data: "imageId=" + this.title,
		   success: function(html){
				$("#largeImage").attr('src',html);
			}
		 })
		imageId = this.title;
	})
	 $.closePopup = function()
	 {
		 $("#boxBg, #showBox").hide();
	 }
	function btnCheck()
	{
		if(imageId < 2)
		{//Hide Next button
			$(".showBoxNext").hide();
		}else
		{
			$(".showBoxNext").show();		
		}
		if(imageId >= newestId)
		{
			$(".showBoxPrev").hide();	
		}else
		{
			$(".showBoxPrev").show();				
		}
	}
	function reposition()
	{ //calculate the position
		var left = 0;
		var top = 0;
		var winWidth = $(window).width();
		var winHeight =  $(window).height();
		var dialogHeight = $("#showBox").height();
		var dialogWidth = $("#showBox").width();
	
		if ($.browser.msie) {
			left = document.body.scrollLeft || document.documentElement.scrollLeft;
			top = document.body.scrollTop || document.documentElement.scrollTop;
		}
		else {
			left = window.pageXOffset;
			top = window.pageYOffset;
		}
	
		var topOff = top + winHeight/2 - dialogHeight/2; //offset for IE6
		var	leftOff = left + winWidth/2 - dialogWidth/2; //offset for IE6
		var topFixed = topOff - top;
		var	leftFixed = leftOff - left;
		
		if ($.browser.msie && parseInt($.browser.version) < 7) { // IE6
			//IE 6 fix
			$("select").hide();
			//IE 6 fix
			$("#showBox select").show(); 
			//IE6 doesn't support fixed position
			$("#showBox").css({
				top: topOff,
				left: leftOff,
				position: "absolute",
				zIndex: (2001)
			}).show(); 
		}
		else{	// firefox and IE7
			$("#showBox").css({
				top: topFixed, 
				left: leftFixed, 
				position: "fixed", 
				zIndex: (2001)
			}).show();
		}
	}
});


