﻿//  BEGIN -->

var popupStatus = 0;
var currentDiv = "#popup";

function loadPopup(mydiv){
	$(mydiv).load("popup.html"); 
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.35"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery(mydiv).fadeIn("slow");
		jQuery("#close").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery(currentDiv).fadeOut("slow");
		jQuery("#close").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(myDiv){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery(myDiv).height();
	var popupWidth = jQuery(myDiv).width();
	jQuery(myDiv).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
}

function popper() {
	loadPopup(currentDiv);
}

$(document).ready(function(){
						   
jQuery("#close").click(function(){
	disablePopup();
});


jQuery("#backgroundPopup").click(function(){
	disablePopup();
});

jQuery(document).keypress(function(e){
	if(e.keyCode==27 && popupStatus==1){
	disablePopup();
	}
});

});

///////////////////////
//    SET COOKIES   //
/////////////////////

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}

function loadpopunder(){
		   setTimeout("popper();",1000);
		   foundCookie = 1;
}

loadornot();


// END -->
