/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(family){

	//loads popup only if it is disabled
	if(popupStatus==0){
		$(family+".zp-backgroundPopup").css({
			"opacity": "0.6"  //FF
			//"filter": "alpha(opacity=95)" //IE
		});
 		$(family+".zp-backgroundPopup").fadeIn("slow");
 		$(family+".zp-popupContact").fadeIn("slow");
		popupStatus = 1;
		
	}
}


//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$(".zp-backgroundPopup").fadeOut("slow");
		$(".zp-popupContact").fadeOut("slow");
		popupStatus = 0;
		$(".zp-block").css({"display":"none"});
	}
}



//centering popup
function centerPopup(family){

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(family+".zp-popupContact").height(); //css styling
	var popupWidth = $(family+".zp-popupContact").width();  //css styling
	//find top of current window display for when scrolled
	var scrollHeight = $(window).scrollTop(); //RY - distance window has scrolled

	
	
	//centering	
	$(family+".zp-popupContact").css({
		"position": "absolute",
//original:		"top": windowHeight/2-popupHeight/2,
//original: 		"left": windowWidth/2-popupWidth/2
		"top": windowHeight/2-popupHeight/2+scrollHeight, //RY - for dynamic vertical positioning
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$(family+".zp-backgroundPopup").css({
		"height": windowHeight
	});
	
}






//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
    //set ids - panador custom modification
	//-- size block selection -- in conjunction w/ zp-lighttext
    //html code: <div id="zp-hat" class="zp-popup-link">Getting a perfect fit</div>
	if ($('#zp-breadcrumbs a[href*="panama-straw-hats"]').length > 0) {
	  $('.zp-cart .zp-popup-link').attr('id','zp-hat');
	}
	else if ($('#zp-breadcrumbs a[href*="leather-jackets"]').length > 0){
	  $('.zp-cart .zp-popup-link').attr('id','zp-jacket');
	}
	else { //do nothing
	}
	//-- end size block selection -->




	//LOADING POPUP
	//Click the button event!
	//$("#button").click(function(){
	$(".zp-popup-link").click(function(){ //RY modified from button to link
		//centering with css
		var family; //content family group
		//following if statments are pulling from the clicked link (actually a div not an anchor) id
//html code: <div id="zp-hat" class="zp-popup-link">Getting a perfect fit</div>
		if ($(this).attr("id") == "zp-shipping") { family=".zp-shipping";} 
		else if ($(this).attr("id") == "zp-hat") {family =".zp-hat";}
		else if ($(this).attr("id") == "zp-jacket") {family =".zp-jacket";}
		else if ($(this).attr("id") == "zp-value") {family =".zp-value";} 
		else if ($(this).hasClass("zp-value-icon")) {family =".zp-value";}
		else { alert("No content blocks exist matching this link's id"); }
		var custom_block = family+"-block";
		$(custom_block).css({"display":"block"});
		centerPopup(family);
		//load popup
		loadPopup(family);
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".zp-popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$(".zp-backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});








//from thickbox - it's more complete perhaps but the current means (copied and commented out below) seems to be working fine
// function tb_getPageSize(){
// 	var de = document.documentElement;
// 	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
// 	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
// 	arrayPageSize = [w,h];
// 	return arrayPageSize;
// }
//above function seems to work the same as this scripts lines: 
//	var windowWidth = document.documentElement.clientWidth;
//	var windowHeight = document.documentElement.clientHeight;