$(function(){
var popupStatus = 0,
pageToLoad = '',
expires = '',
COOKIE_NAME = 'ageCheck',
$go = $.cookie(COOKIE_NAME);


/*if (($go != 'ageCheck') && window.location != "http://www.intoxicology.co.uk/site/agecheck") {
	window.location = "http://www.intoxicology.co.uk/site/agecheck";
}*/


function isChecked(){
var n = $("input#remember:checked").length,
$go = $.cookie(COOKIE_NAME);
		if ($go == null) {
			if (n){
				$.cookie(COOKIE_NAME, 'ageCheck', { path: '/', expires: 100 });
			}else{
				$.cookie(COOKIE_NAME, 'ageCheck', { path: '/'});
			}
			
		}
}



function loadPopup(pageToLoad){  
	if(popupStatus==0){
		$("#backgroundPopup").css({  
		"opacity": "0.7"  
		});  
		$('object,embed').css('visibility','hidden');
		$("#popupContentInner").load('http://www.intoxicology.co.uk/site/statements/'+ pageToLoad +'')
		$("#backgroundPopup").fadeIn(150);  
		$("#popupContent").fadeIn(150);  
		popupStatus = 1;  
	}  
}
function disablePopup(){  
	
		$('object,embed').css('visibility','visible');
	if(popupStatus==1){  
		$("#backgroundPopup").fadeOut(150);  
		$("#popupContent").fadeOut(150);
		$("#popupContentInner").html('');  
		popupStatus = 0;  
	}  
}
function centerPopup(){
	var windowWidth = document.documentElement.clientWidth, 
	windowHeight = document.documentElement.clientHeight, 
	popupHeight = $("#popupContent").height(), 
	popupWidth = $("#popupContent").width();  
	$("#popupContent").css({"position": "absolute", "top": windowHeight/2-popupHeight/2, "left": windowWidth/2-popupWidth/2});  
	//only need force for IE6  
	$("#backgroundPopup").css({"height": windowHeight});  
}  





$("#legal-statement, #privacy-policy").click(function(e){

	var pageToLoad = $(this).attr('id');
	centerPopup();
	loadPopup(pageToLoad);
});

$("#popupContentClose").click(function(){
	disablePopup();
	
});
$("#backgroundPopup").click(function(){
	disablePopup();
});
$(document).keypress(function(e){
	if(e.keyCode==27 && popupStatus==1){
		disablePopup();
	}
});

$("#ageCheckSubmit").click(isChecked);
  
});