//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup3").css({
			"opacity": "0.8"
		});
		$("#backgroundPopup3").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup3").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		$("#popupContact").remove(); //cerco di terminare la musica del div nascosto
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	
	//test
	windowHeight = $(window).height();
	windowWidth = $(window).width();

	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();

	//correzione altezza per IE
	var explorerAlignCorrection=0;
	if(navigator.userAgent.indexOf("MSIE")>0){ 
		explorerAlignCorrection=15;
	}

	$("#popupContact").css({
		"position": "absolute",
		"top": 12+80,
		"left": windowWidth/2-popupWidth/2
	});

	$("#backgroundPopup3").css({
		"height": windowHeight
	});
	
}
	function loadAdv(){
		var corrente = $(location).attr('href');
		// nomi delle pagine che presentano il popup
		if( 0 < corrente.indexOf("home") || //home+home1
			corrente == "http://www.eptarefrigeration.com/" ||
			corrente == "http://eptarefrigeration.com/" ||

			corrente == "http://www.epta-italia.com/" ||
			corrente == "http://epta-italia.com/" ||

			corrente == "http://www.epta-iberia.com/" ||
			corrente == "http://epta-iberia.com/" ||

			corrente == "http://www.epta-france.com/" ||
			corrente == "http://epta-france.com/" ||

			corrente == "http://www.epta-deutschland.com/" ||
			corrente == "http://epta-deutschland.com/" ||

			corrente == "http://www.epta-russia.com/" ||
			corrente == "http://epta-russia.com/" ||

			corrente == "http://www.epta-argentina.com/" ||
			corrente == "http://epta-argentina.com/" ||

			corrente == "http://www.epta-uk.com/" ||
			corrente == "http://epta-uk.com/" ||

			corrente == "http://www.epta-austria.com/" ||
			corrente == "http://epta-austria.com/" ||

			corrente == "http://www.epta-sweden.com/" ||
			corrente == "http://epta-sweden.com/"
		){
			centerPopup();
			loadPopup();
		}
	}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	$("#popupContactClose").click(function(){
		disablePopup();
	});
});
