/***************************/
//@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(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").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;
	if(windowHeight<1 || windowWidth<1){
//IE non supporta correttamente l'oggetto DOCUMENT
		windowWidth = $(window).width();
		windowHeight = $(window).height();
	}

	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	//correzione altezza per IE
	var explorerAlignCorrection=0;
	if(navigator.userAgent.indexOf("MSIE")>0){ 
		explorerAlignCorrection=15;
	}

	$("#popupContact").css({
		"position": "absolute",
//		"top": (windowHeight/2-popupHeight/2)- (14+explorerAlignCorrection),
		"top": 19+114,
		"left": windowWidth/2-popupWidth/2 -10
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
	function loadAdv(){
		var corrente = $(location).attr('href');
		//alert (corrente);
		// nomi delle pagine che presentano il popup
		if( 0 < corrente.indexOf("home1") || //home+home1
			//test
			0< corrente.indexOf("localhost") || 
		
		//costan
			corrente == "http://costan.com/" ||
			corrente == "http://www.costan.it/" || 
			corrente == "http://costan.it/" ||
			corrente == "http://www.costan.com/" ||
		//georgebarker	
			corrente == "http://www.georgebarker.co.uk/" ||
			corrente == "http://georgebarker.co.uk/" ||
		//bonnetneve
			corrente == "http://www.bonnetneve.fr/" ||
			corrente == "http://bonnetneve.fr/" ||
			corrente == "http://www.bonnetneve.com/" || 
			corrente == "http://bonnetneve.com/" ||
		//bkt
			corrente == "http://www.bkt.de/" ||
			corrente == "http://bkt.de/" ||
		//epta argentina
			corrente == "http://www.argentina.costan.com/" ||
			corrente == "http://argentina.costan.com/" ||
		//epta-china
			corrente == "http://www.epta-china.com/" ||
			corrente == "http://epta-china.com/" ||
		//eurocryor
			corrente == "http://eurocryor.eptarefrigeration.com/" ||
			corrente == "http://eurocryor.s4win.com/" ||
			corrente == "http://www.eurocryor.com/" ||
			corrente == "http://www.eurocryor.us/" ||
			corrente == "http://www.eurocryor.it/" ||
			corrente == "http://www.eurocryor.at/" ||
			corrente == "http://www.eurocryor.fr/" ||
			corrente == "http://www.eurocryor.se/" ||
			corrente == "http://www.eurocryor.eu/"  
		){
			
			centerPopup();
			loadPopup();
		}
	}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	/**
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	**/
});
