﻿/***************************/
//@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 loadPopupAndroidLite(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.8"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupAndroidLite").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopupAndroidPro(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupAndroidPro").fadeIn("slow");
		popupStatus = 2;
	}
}
function loadPopupMobi(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupMobi").fadeIn("slow");
		popupStatus = 3;
	}
}



//disabling popup with jQuery magic!
function disablePopupAndroidLite(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupAndroidLite").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopupAndroidPro(){
	//disables popup only if it is enabled
	if(popupStatus==2){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupAndroidPro").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopupMobi(){
	//disables popup only if it is enabled
	if(popupStatus==3){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupMobi").fadeOut("slow");
		popupStatus = 0;
	}
}


//centering popup
function centerPopupAndroidLite(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupAndroidLite").height();
	var popupWidth = $("#popupAndroidLite").width();
	//centering
	$("#popupAndroidLite").css({
		"position": "absolute",
		"top": (windowHeight/2)-(popupHeight/2)-80,
		"left": (windowWidth/2)-(popupWidth/2)
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
function centerPopupAndroidPro(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupAndroidPro").height();
	var popupWidth = $("#popupAndroidPro").width();
	//centering
	$("#popupAndroidPro").css({
		"position": "absolute",
		"top": (windowHeight/2)-(popupHeight/2)-80,
		"left": (windowWidth/2)-(popupWidth/2)
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
function centerPopupMobi(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupMobi").height();
	var popupWidth = $("#popupMobi").width();
	//centering
	$("#popupMobi").css({
		"position": "absolute",
		"top": (windowHeight/2)-(popupHeight/2)-80,
		"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!
	$("#buttonAndroidLite").click(function(){
		//centering with css
		centerPopupAndroidLite();
		//load popup
		loadPopupAndroidLite();
	});
	$("#buttonAndroidPro").click(function(){
		//centering with css
		centerPopupAndroidPro();
		//load popup
		loadPopupAndroidPro();
	});
	$("#buttonMobi").click(function(){
		//centering with css
		centerPopupMobi();
		//load popup
		loadPopupMobi();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupAndroidLiteClose").click(function(){
		disablePopupAndroidLite();
	});
	$("#popupAndroidProClose").click(function(){
		disablePopupAndroidPro();
	});
	$("#popupMobiClose").click(function(){
		disablePopupMobi();
	});
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopupAndroidLite();
		disablePopupAndroidPro();
		disablePopupMobi();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopupAndroidLite();
			disablePopupAndroidPro();
			disablePopupMobi();
		}
	});

});
