// JavaScript Document

  $(document).ready(function(){
	$variables = {};  
	$("body").append("<div id='box'><a class='closeBtn'><span class='closeMessage'>Close window</span></a></div><div id='boxBG'></div>");
	$("#boxBG").height($(document).height());
	$("#boxBG").css( {'opacity': 0.6, 'filter':'alpha(opacity=60)' }) ; 
		
	$("a.frontBox").click(function(event){  
		event.preventDefault();
		$variables.linkPath = $(this).attr("href");
			$variables.linkAlt = $(this).find("img").attr('alt'); 
				if ( $("#box img").length > 0 ) {
				$("#box img").remove();
			} 
			
			$("#boxBG").fadeIn(function() {
			$("#box span").remove();
				////console.log(" LOAD IMAGE HERE");
				var img = new Image();
			  // wrap our new image in jQuery, then:
				$(img).load(function () { 
				//  once the image has loaded, execute this code
			   //set the image hidden by default  
				
					//console.log("Image loaded");
					$("div#box a").html("<span>Close window</span>");
					$("div#box a").append(img);
					$("div#box img").css( { display:"block" });
					$variables.imageWidth = $("div#box").width();
					$variables.width = 0;
					$variables.height = 0;
					  if (document.documentElement) {
						  $variables.width = document.documentElement.offsetWidth;
						  $variables.height = document.documentElement.offsetHeight;
					  } else if (window.innerWidth && window.innerHeight) {
						  $variables.width = window.innerWidth;
						  $variables.height = window.innerHeight;
					  }


					$variables.diffwidth = (($variables.width - $variables.imageWidth) /2);
					$("div#box").fadeIn();
					
					if ($.browser.msie && $.browser.version == 6.0) { 
						$("div#box").css( { "position": "absolute"});
					} else {
						$("div#box").css( { "position": "fixed"});
					}
					$("div#box").css( { "left": $variables.diffwidth});

					
				})  
				$(img).error(function () {
					$("#box span").remove();
					$("div#box").fadeIn();
					$("div#box a").html("Sorry that image can not be found, please try another");
					// notify the user that the image could not be loaded
					////console.log("ERROR");
				 })
				$(img).attr('src', $variables.linkPath);
				$(img).attr('alt', $variables.linkAlt);
				//$("div#box a").after("<span></span>");
			//	$("div#box span").html("<span class='imageTitle'>"+$variables.linkTitle+"</span>"+$variables.linkDescription);
				
				}); 
			//	} 

			 });  
	   
			 $("div#box a").click(function(event){ 
				////console.log(" OUT");
				$("div#box").fadeOut();
				$("div#boxBG").fadeOut();
				event.preventDefault();
			})
	
}); 