﻿var popupStatus = 0;

function loadPopup(id_name){
	if(popupStatus==0){
		$(".popup_bg").css({
			"opacity": "0.5"
		});
		$(".popup_bg").fadeIn("slow");
		$(id_name).fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(id_name){
	if(popupStatus==1){
		$(".popup_bg").fadeOut("slow");
		$(id_name).fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(id_name){
	var windowHeight = document.documentElement.clientHeight;
	var windowWidth = document.body.clientWidth;
	var popupHeight = $(id_name).height();
	var popupWidth = $(id_name).width();
	$(id_name).css({
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	$(".popup_bg").css({
		"height": windowHeight,
		"width": windowWidth
	});
}

function startPopup(id_name){
	temp = id_name;
	centerPopup(id_name);
	loadPopup(id_name);
	$(".popup_close").click(function(){
		disablePopup(temp);
	});
	$(".popup_bg").click(function(){
		disablePopup(temp);
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup(temp);
		}
	});	
}

$(document).ready(function(){
	date = new Date();
    m = date.getMonth()+1;
	y = date.getFullYear();
	if(m == 2 && y == 2011 && document.cookie.indexOf("GENERACJA.pl_2011-02") == -1){
		startPopup("#welcome");
		document.cookie = "GENERACJA.pl_2011-02=Welcome; expires=Mon, 28 Feb 2011 23:59:59 GMT";
	}
});
