/***************************/
//@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 popupStatusVentajas = 0;
var popupStatusNoches = 0;
var popupStatusAmigo = 0;
var popupStatusCorte = 0;

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	$("#backgroundPopupVentajas").hide();
	$("#ventajasContainer").hide();
	$("#backgroundPopupNoches").hide();
	$("#noches-hotelContainer").hide();
	$("#backgroundPopupAmigo").hide();
	$("#amigoContainer").hide();
	$("#backgroundPopupCorte").hide();
	$("#corteContainer").hide();
	//LOADING POPUP
	//Click the button event!
	$("#ventajas").click(function(){
		//centering with css
		centerPopupVentajas();
		//load popup
		cargarVentajas();
	});
	$("#noches-hotel").click(function(){
		//centering with css
		centerPopupNoches();
		//load popup
		cargarNoches();
	});
	$("#amigo").click(function(){
		//centering with css
		centerPopupAmigo();
		//load popup
		cargarAmigo();
	});
	$("#regalo_corte_ingles").click(function(){
		//centering with css
		centerPopupCorte();
		//load popup
		cargarCorte();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseVentajas").click(function(){
		disablePopupVentajas();
	});
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseNoches").click(function(){
		disablePopupNoches();
	});
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseAmigo").click(function(){
		disablePopupAmigo();
	});
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseCorte").click(function(){
		disablePopupCorte();
	});
	//Click out event!
	$("#backgroundPopupVentajas").click(function(){
		disablePopupVentajas();
	});
	//Click out event!
	$("#backgroundPopupNoches").click(function(){
		disablePopupNoches();
	});
	//Click out event!
	$("#backgroundPopupAmigo").click(function(){
		disablePopupAmigo();
	});
	//Click out event!
	$("#backgroundPopupCorte").click(function(){
		disablePopupCorte();
	});
	//Press Escape event!
	$(document).keyup(function(e){
		if(e.keyCode==27){
			disablePopupVentajas();
			disablePopupNoches();
			disablePopupAmigo();
			disablePopupCorte();
		}
	});
});

//loading popup with jQuery magic!
function cargarVentajas(){
	//loads popup only if it is disabled
	if(popupStatusVentajas==0){
		$("#backgroundPopupVentajas").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupVentajas").fadeIn("slow");
		$("#ventajasContainer").fadeIn("slow");
		popupStatusVentajas = 1;
	}
}

function cargarNoches(){
	//loads popup only if it is disabled
	if(popupStatusNoches==0){
		$("#backgroundPopupNoches").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupNoches").fadeIn("slow");
		$("#noches-hotelContainer").fadeIn("slow");
		popupStatusNoches = 1;
	}
}
function cargarAmigo(){
	//loads popup only if it is disabled
	if(popupStatusAmigo==0){
		$("#backgroundPopupAmigo").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupAmigo").fadeIn("slow");
		$("#amigoContainer").fadeIn("slow");
		popupStatusAmigo = 1;
	}
}
function cargarCorte(){
	//loads popup only if it is disabled
	if(popupStatusCorte==0){
		$("#backgroundPopupCorte").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupCorte").fadeIn("slow");
		$("#corteContainer").fadeIn("slow");
		popupStatusCorte = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupVentajas(){
	//disables popup only if it is enabled
	if(popupStatusVentajas==1){
		$("#backgroundPopupVentajas").fadeOut("slow");
		$("#ventajasContainer").fadeOut("slow");
		popupStatusVentajas = 0;
	}
}
//disabling popup with jQuery magic!
function disablePopupNoches(){
	//disables popup only if it is enabled
	if(popupStatusNoches==1){
		$("#backgroundPopupNoches").fadeOut("slow");
		$("#noches-hotelContainer").fadeOut("slow");
		popupStatusNoches = 0;
	}
}
//disabling popup with jQuery magic!
function disablePopupAmigo(){
	//disables popup only if it is enabled
	if(popupStatusAmigo==1){
		$("#backgroundPopupAmigo").fadeOut("slow");
		$("#amigoContainer").fadeOut("slow");
		popupStatusAmigo = 0;
	}
}
//disabling popup with jQuery magic!
function disablePopupCorte(){
	//disables popup only if it is enabled
	if(popupStatusCorte==1){
		$("#backgroundPopupCorte").fadeOut("slow");
		$("#corteContainer").fadeOut("slow");
		popupStatusCorte = 0;
	}
}

//centering popup
function centerPopupVentajas(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#ventajasContainer").height();
	var popupWidth = $("#ventajasContainer").width();
	//centering
	if(popupHeight>windowHeight) {
		$("#ventajasContainer").css({
			"position": "absolute",		
			"top": 25,
			"left": windowWidth/2-popupWidth/2
		});
	}
	else {
		$("#ventajasContainer").css({
			"position": "absolute",		
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
	}
	$("#backgroundPopupVentajas").css({
		"height": windowHeight
	});
}
//centering popup
function centerPopupNoches(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#noches-hotelContainer").height();
	var popupWidth = $("#noches-hotelContainer").width();
	//centering
	if(popupHeight>windowHeight) {
		$("#noches-hotelContainer").css({
			"position": "absolute",		
			"top": 25,
			"left": windowWidth/2-popupWidth/2
		});
	}
	else {
		$("#noches-hotelContainer").css({
			"position": "absolute",		
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
	}
	//only need force for IE6
	
	$("#backgroundPopupNoches").css({
		"height": windowHeight
	});
	
}
//centering popup
function centerPopupAmigo(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#amigoContainer").height();
	var popupWidth = $("#amigoContainer").width();
	//centering
	if(popupHeight>windowHeight) {
		$("#amigoContainer").css({
			"position": "absolute",		
			"top": 25,
			"left": windowWidth/2-popupWidth/2
		});
	}
	else {
		$("#amigoContainer").css({
			"position": "absolute",		
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
	}
	//only need force for IE6
	
	$("#backgroundPopupAmigo").css({
		"height": windowHeight
	});
	
}

//centering popup
function centerPopupCorte(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#corteContainer").height();
	var popupWidth = $("#corteContainer").width();
	//centering
	if(popupHeight>windowHeight) {
		$("#corteContainer").css({
			"position": "absolute",		
			"top": 25,
			"left": windowWidth/2-popupWidth/2
		});
	}
	else {
		$("#corteContainer").css({
			"position": "absolute",		
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
	}
	//only need force for IE6
	
	$("#backgroundPopupCorte").css({
		"height": windowHeight
	});
	
}
