﻿

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

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#legal").fadeIn("slow");
		popupStatus = 1;
	}
}

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


function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus2==0){
		$("#creditos").fadeIn("slow");
		popupStatus2 = 1;
	}
}

function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus2==1){
		$("#creditos").fadeOut("slow");
		popupStatus2 = 0;
	}
}



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


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


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button1").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		$('#contenedor').fadeOut(1000);
				
	});
	
	$("#button2").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup2();
		$('#contenedor').fadeOut(1000);
				
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
		$('#trans').fadeIn(1000);
		$('#contenedor').fadeIn(1000);
});
	
	$("#popupContactClose2").click(function(){
		disablePopup2();
		$('#trans').fadeIn(1000);
		$('#contenedor').fadeIn(1000);
});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
		$('#trans').fadeIn(1000);
		$('#contenedor').fadeIn(1000);
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopup2();
			$('#trans').fadeIn(1000);
			$('#contenedor').fadeIn(1000);
		}
	});

});
