﻿/***************************/
//@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 loadPopupSize(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupSize").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupSize").fadeIn("slow");
		$("#sizingChart").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopupShipping(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupShipping").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupShipping").fadeIn("slow");
		$("#shippingInfo").fadeIn("slow");
		popupStatus = 2;
	}
}
function loadPopupReturn(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupReturn").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupReturn").fadeIn("slow");
		$("#returnInfo").fadeIn("slow");
		popupStatus = 3;
	}
}
function loadPopupCustomization(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupCustomization").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupCustomization").fadeIn("slow");
		$("#customizationInfo").fadeIn("slow");
		popupStatus = 4;
	}
}

//disabling popup with jQuery magic!
function disablePopupSize(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupSize").fadeOut("slow");
		$("#sizingChart").fadeOut("slow");
		popupStatus = 0;
	}
}

function disablePopupShipping(){
	//disables popup only if it is enabled
	if(popupStatus==2){
		$("#backgroundPopupShipping").fadeOut("slow");
		$("#shippingInfo").fadeOut("slow");
		popupStatus = 0;
	}
}

function disablePopupReturn(){
	//disables popup only if it is enabled
	if(popupStatus==3){
		$("#backgroundPopupReturn").fadeOut("slow");
		$("#returnInfo").fadeOut("slow");
		popupStatus = 0;
	}
}

function disablePopupCustomization(){
	//disables popup only if it is enabled
	if(popupStatus==4){
		$("#backgroundPopupCustomization").fadeOut("slow");
		$("#customizationInfo").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopupSize(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#sizingChart").height();
	var popupWidth = $("#sizingChart").width();
	//centering
	$("#sizingChart").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupSize").css({
		"height": windowHeight
	});
	
}

function centerPopupShipping(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#shippingInfo").height();
	var popupWidth = $("#shippingInfo").width();
	//centering
	$("#shippingInfo").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupShipping").css({
		"height": windowHeight
	});
	
}

function centerPopupReturn(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#returnInfo").height();
	var popupWidth = $("#returnInfo").width();
	//centering
	$("#returnInfo").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupReturn").css({
		"height": windowHeight
	});
	
}

function centerPopupCustomization(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#customizationInfo").height();
	var popupWidth = $("#customizationInfo").width();
	//centering
	$("#customizationInfo").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupCustomization").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#popupInfoSectionSize").click(function(){
		//centering with css
		centerPopupSize();
		//load popup
		loadPopupSize();
	});
	$("#popupInfoSectionShipping").click(function(){
		//centering with css
		centerPopupShipping();
		//load popup
		loadPopupShipping();
	});
	$("#popupInfoSectionReturn").click(function(){
		//centering with css
		centerPopupReturn();
		//load popup
		loadPopupReturn();
	});
	$("#popupInfoSectionCustomization").click(function(){
		//centering with css
		centerPopupCustomization();
		//load popup
		loadPopupCustomization();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#sizingChartClose").click(function(){
		disablePopupSize();
	});
	$("#returnInfoClose").click(function(){
		disablePopupReturn();
	});
	$("#shippingInfoClose").click(function(){
		disablePopupShipping();
	});
	$("#customizationInfoClose").click(function(){
		disablePopupCustomization();
	});
	//Click out event!
	$("#backgroundPopupSize").click(function(){
		disablePopupSize();
	});
	$("#backgroundPopupShipping").click(function(){
		disablePopupShipping();
	});
	$("#backgroundPopupReturn").click(function(){
		disablePopupReturn();
	});
	$("#backgroundPopupCustomization").click(function(){
		disablePopupCustomization();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopupSize();
		}
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==2){
			disablePopupShipping();
		}
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==3){
			disablePopupReturn();
		}
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==4){
			disablePopupCustomization();
		}
	});

});
