﻿/***************************/
//@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 Done popup with jQuery magic!
function loadPopupDone(){
	if(popupStatus==0){
		jQuery("#popupContactDone").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopupDone(){
	if(popupStatus==1){
		jQuery("#popupContactDone").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopupDone(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupContactDone").height();
	var popupWidth = jQuery("#popupContactDone").width();
	jQuery("#popupContactDone").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2+400,
		"left": windowWidth/2-popupWidth/2
	});
}

//loading Fail popup with jQuery magic!
function loadPopupFail(){
	if(popupStatus==0){
		jQuery("#popupContactFail").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopupFail(){
	if(popupStatus==1){
		jQuery("#popupContactFail").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopupFail(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupContactFail").height();
	var popupWidth = jQuery("#popupContactFail").width();
	jQuery("#popupContactFail").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2+350,
		"left": windowWidth/2-popupWidth/2
	});
}


//loading Welcome popup with jQuery magic!
function loadPopupWelcome(){
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0"  
		});
		jQuery("#backgroundPopup").fadeIn("slow");   		
		jQuery("#popupWelcome").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopupWelcome(){
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");   
		jQuery("#popupWelcome").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopupWelcome(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupWelcome").height();
	var popupWidth = jQuery("#popupWelcome").width();
	jQuery("#popupWelcome").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	 jQuery("#backgroundPopup").css({  
	 "height": windowHeight  ,
	 "weight": windowHeight  
	 }); 	
}

//CONTROLLING EVENTS IN jQuery
jQuery(document).ready(function(){
	jQuery("#buttonFail").click(function(){
		centerPopupFail();
		loadPopupFail();
	});

	jQuery("#popupContactCloseFail").click(function(){
		disablePopupFail();
	});
	
	jQuery("#buttonDone").click(function(){
		centerPopupDone();
		loadPopupDone();
	});

	jQuery("#popupContactCloseDone").click(function(){
		disablePopupDone();
	});

	jQuery("#buttonWelcome").click(function(){
		centerPopupWelcome();
		loadPopupWelcome();
	});

	jQuery("#popupWelcomeClose").click(function(){
		disablePopupWelcome();
	});

	jQuery("#backgroundPopup, #popupWelcome, #popupWelcomeArea").click(function(){
		disablePopupWelcome();
	});

	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopupDone();
			disablePopupFail();
			disablePopupWelcome();
		}
	});

});