﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

var popupStatus = 0;

function loadPopup(){
	if(popupStatus == 0){
		$("#flash_stars_effect").css({
			"visibility": "hidden"
		});

		$("#popupBackground").css({
			"opacity": "0.7"
		});
		$("#popupBackground").fadeIn("slow");
		$("#popupWindow").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus == 1){
		$("#popupBackground").fadeOut("slow");
		$("#popupWindow").fadeOut("slow");
		setTimeout("Visible_flash_stars_effect()", 1000);
	}
}

function Visible_flash_stars_effect(){
		$("#flash_stars_effect").css({
			"visibility": "visible"
		});
		popupStatus = 0;
}

function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupWindow").height();
	var popupWidth = $("#popupWindow").width();
	$("#popupWindow").css({
		"position": "absolute",
		"top": windowHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	$("#popupBackground").css({
		"height": windowHeight*1.4,
		"width": windowWidth-2
	});
}


$(document).ready(function(){
	$("#popupButton").click(function(){
		centerPopup();
		loadPopup();
	});
	$("#popupClose").click(function(){
		disablePopup();
	});
	$("#popupBackground").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode == 27 && popupStatus==1){
			disablePopup();
		}
	});
});
