var popupStatus = 0;

function loadPopup()
{
  if (popupStatus == 0)
  {
    $("#backgroundPopup").css({"opacity": "0.7"});
    $("#backgroundPopup").fadeIn("slow");
    $("#popupContent").fadeIn("slow");
    popupStatus = 1;
  }
}



function hidePopup()
{
  if (popupStatus == 1)
  {
    $("#backgroundPopup").fadeOut("slow");
    $("#popupContent").fadeOut("slow");
    popupStatus = 0;
  }
}


function centerPopup()
{
  if (window.innerWidth)
  {
    var windowWidth = window.innerWidth;
    var windowHeight = window.innerHeight;
  }
  else
  {
    var windowWidth = document.documentElement.clientWidth;;
    var windowHeight = document.documentElement.clientHeight;
  }


  var popupHeight = $("#popupContent").height();
  var popupWidth = $("#popupContent").width();
  $("#popupContent").css({"position":"fixed", "top":windowHeight/2-popupHeight/2,"left":windowWidth/2-popupWidth/2});
  $("#backgroundPopup").css({"height":windowHeight, "min-height":windowHeight});

}



$(document).ready(function(){
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		hidePopup();
	});

	//Click out event!
	$("#backgroundPopup").click(function(){
		hidePopup();
	});

	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			hidePopup();
		}
	});

        $("#cancelLink").click(function() { hidePopup(); });

});


function invitation()
{
  if (document.cookie.indexOf("visited") < 0)
  {
    var date = new Date();
    date.setTime(date.getTime()+(90*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    value = "visited=true" + expires;
    value = escape(value);
    document.cookie = value + "; path=/";
    centerPopup();
    loadPopup();
  }
}

setTimeout("invitation()", 35000);

