﻿$(document).ready(function(){
	$("#furn").hover(
		function(){
			$("img.menupopupfur").fadeIn("fast");
	},
		function(){
			$("img.menupopupfur").fadeOut("fast");
	});
	$("#pen").hover(
		function(){
			$("img.menupopuppen").fadeIn("fast");
	},
		function(){
			$("img.menupopuppen").fadeOut("fast");
	});
	$("#box").hover(
		function(){
			$("img.menupopupbox").fadeIn("fast");
	},
		function(){
			$("img.menupopupbox").fadeOut("fast");
	});
	
	
	//Gray out contact popup
	$(".popup_image, .boxthumbnailImg, .penthumbnailImg, .furniturethumbnailImg").click(function(e){
	  var s = this.alt;
	  var w = this.id+"px"; //The ID of the img stores the width value of the popup img.
	  var ImgSrc = "images/image_items/" + s + "grayout.png";		
		
		centerPopup(w);
		loadPopup(ImgSrc);
	});
	
	//Close the popup
	$("#popup, #popupClose, #backgroundPopup").click(function(){ 
		 disablePopup();  
	});  
	
});	
	
	//Contact grayout popup
	var popupstarus = 0;

	function loadPopup(ImgSrc){
	  
		if(popupstarus==0){
			$("#backgroundPopup").css({"opacity" : "0.8"});
			$("#backgroundPopup").fadeIn("slow");
			$("#popup").append("<div id='popupClose'><img src='images/closelabel.gif' alt='' /></div><img id='grayoutImg' src='" + ImgSrc + "' alt='' />");
			$("#popup").slideDown("slow");
			popupstarus = 1;
			}
		}
		function disablePopup(){
			if(popupstarus==1){
				$("#backgroundPopup").fadeOut("slow");
				$("#popup").fadeOut("slow");
				$("#grayoutImg, #popupClose").remove();
				popupstarus = 0;
			}
		}	
		function centerPopup(w){
			$("#popup").css({"width" : w}); //Must set width first so popup centers correctly
			var windowWidth = document.documentElement.clientWidth;
			var windowHeight = document.documentElement.clientHeight;
			var popupHeight = $("#popup").height();
			var popupWidth = $("#popup").width();
			var scrolledY = document.documentElement.scrollTop;
			
		  
			$("#popup").css({"position" : "absolute", "top" : scrolledY, "left" : windowWidth/2-popupWidth/2, "margin-top" : "35px"});
			//IE6 fix
			$("backgroundPopup").css({"height" : windowHeight});
		}