var popupStatus = 0;

function launchPopup() {
	jQuery(".contentBoxClose").click(function(){
		disablePopup();
	});
	
	/*
	jQuery("#contentBoxBackground").click(function(){
		disablePopup();
	});
	*/
	
	jQuery(document).keypress(function(e){
		if (e.keyCode==27 && popupStatus == 1){
			disablePopup();
		}
	});
	
	centerPopup();
	
	if (popupStatus == 0){
		toggleFlash();
		jQuery("#contentBoxBackground").css({
			"opacity": "0.7"
		});
		
		jQuery("#contentBoxBackground").fadeIn("slow");
		jQuery("#contentBox").fadeIn("slow");
		
		cookieWriter();
		
		popupStatus = 1;
	}
}

function disablePopup() {
	if (popupStatus == 1) {
		jQuery("#contentBoxBackground").fadeOut("slow");
		jQuery("#contentBox").fadeOut("slow");
		toggleFlash();
		popupStatus = 0;
	}
}

function toggleFlash() {
	if (popupStatus == 0) {
		jQuery("object,embed,iframe").css({
			'visibility' : 'hidden'
		});
	} else {
		jQuery("object,embed,iframe").css({
			'visibility' : 'visible'
		});
	}
}

function cookieWriter() {
	var currentTime = new Date();
	var puTime = currentTime.getTime();
	jQuery.cookie('puTime',puTime, {path: '/', expires: 365});
}

function centerPopup() {
	var windowWidth = jQuery(window).width();
	var windowHeight = jQuery(window).height();
	var popupHeight = jQuery("#contentBox").height();
	var popupWidth = jQuery("#contentBox").width();

	jQuery("#contentBox").css({
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	//IE6 FORCING
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6) {
		jQuery("#contentBoxBackground").css({
			"height": jQuery(document).height(),
			"width": windowWidth
		});
		scroll(0,0);
	}
}