/**This file can display a dialog that advertises my iPhone site.*/
//1 means showing, 0 means hidden
var popupStatus = 0;

function loadPopup() {

	
	if(popupStatus == 0) {
		$("#background_popup").css({"opacity":0.7});
		$("#background_popup").fadeIn("slow");
		$("#popup").fadeIn("slow");
		popupStatus = 1;
	}
}

//hide the popup
function disablePopup() {
	if(popupStatus == 1) {
		$("#background_popup").fadeOut("slow");
		$("#popup").fadeOut("slow");
		popupStatus = 0;
	}
}

//center the popup
function centerPopup() {
	var documentHeight = document.documentElement.clientHeight;
	var documentWidth = document.documentElement.clientWidth;
	
	var popupWidth = $("#popup").width();
	var popupHeight = $("#popup").height();
	$("#popup").css({"position":"absolute",
					"top": documentHeight/2-popupHeight/2,
					"left": documentWidth/2-popupWidth/2
					});
	
	//only for buddy IE
	$("#background_popup").css({"height":documentHeight});
}

$(document).ready(function() {
	//show the popup for the iphone site
	//check to see if the user has already seen the dialog
	if($.cookie('hasSeenPopup') == null) {
		centerPopup();
		loadPopup();
		$.cookie('hasSeenPopup', 'yes', {expires:10});
		
	}
	
	//Press Escape event!  
	$(document).keypress(function(e){  
		if(e.keyCode==27 && popupStatus==1){  
			disablePopup();  
		} 
	});
	$("#background_popup").click(function() {
		if(popupStatus == 1) {
		disablePopup();
		}
	});
	$("#popup_close").click(function() {
		if(popupStatus == 1) {

			disablePopup();
		}

	});
	$("#close_link").click(function() {
		if(popupStatus == 1) {
			disablePopup();
		}
	});
	
});
