﻿/***************************/
//@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 loadred(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupr").css({
			"opacity": "0.8"
		});
		$("#backgroundPopupr").fadeIn("slow");
		$("#red").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadgreen(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupg").css({
			"opacity": "0.8"
		});
		$("#backgroundPopupg").fadeIn("slow");
		$("#green").fadeIn("slow");
		popupStatus = 1;
	}
}


function loadblue(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupb").css({
			"opacity": "0.8"
		});
		$("#backgroundPopupb").fadeIn("slow");
		$("#blue").fadeIn("slow");
		popupStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disablered(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupr").fadeOut("slow");
		$("#red").fadeOut("slow");
		popupStatus = 0;
	}
}

function disablegreen(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupg").fadeOut("slow");
		$("#green").fadeOut("slow");
		popupStatus = 0;
	}
}

function disableblue(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupb").fadeOut("slow");
		$("#blue").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerred(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#red").height();
	var popupWidth = $("#red").width();
	//centering
	$("#red").css({
		//"Display":"Block"				   
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupr").css({
		"height": windowHeight
	});
	
}

function centergreen(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#green").height();
	var popupWidth = $("#green").width();
	//centering
	$("#green").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupg").css({
		"height": windowHeight
	});
	
}

function centerblue(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#blue").height();
	var popupWidth = $("#blue").width();
	//centering
	$("#blue").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupb").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#btnred").click(function(){
		//centering with css
		centerred();
		//load popup
		loadred();
	});
	
	$("#btngreen").click(function(){
		//centering with css
		centergreen();
		//load popup
		loadgreen();
	});
	
	$("#btnblue").click(function(){
		//centering with css
		centerblue();
		//load popup
		loadblue();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#redClose").click(function(){
		disablered();
	});
	
	$("#greenClose").click(function(){
		disablegreen();
	});
	
	$("#blueClose").click(function(){
		disableblue();
	});
	//Click out event!
	$("#backgroundPopupr").click(function(){
		disablered();
	});
	$("#backgroundPopupg").click(function(){
		disablegreen();
	});
	$("#backgroundPopupb").click(function(){
		disableblue();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablered();
			//disablegreen();
			//disableblue();
		}
	});

});

