/*Runs when the page has loaded*/
jQuery(document).ready(function(){	
	/*Runs the function to show the popup*/
	showPopupConfirmation();
});

/*Shows the demo confirmation popup if the session variable "demoConfirmed" is empty*/
function showPopupConfirmation() {
	/*Used to position the popup in the middle of the screen*/
	$("#popupConfirmationContainer").css("top",$(window).height()/2-$("#popupConfirmationContainer").height()/2).css("left",$(window).width()/2-$("#popupConfirmationContainer").width()/2);
	
	/*Set the default opacity to 0 for IE (filter) and other browsers (opacity)*/
	$("#popupConfirmationOverlay").css("filter","alpha(opacity = 0)").css("opacity","0")

	/*Set the height and width of the overlay to the size of the document (screen). Width is set in the CSS file to 100%*/
	$("#popupConfirmationOverlay").css("height",$(document).height());
	/*Show the overlay and fade it in to half opacity*/
	$("#popupConfirmationOverlay").show().fadeTo("slow", 0.5);
	/*Fade in the popup*/
	$("#popupConfirmationContainer").fadeIn("slow");
	
	/*Fade in the popup - this method removes the filter attribute which causes text to look jagged. Setting the background colour in CSS is another workaround that was used instead*/
	/*$("#popupConfirmationContainer").fadeIn("slow",function(){
		if ($.browser.msie) {
			$("#popupConfirmationContainer").get(0).style.removeAttribute("filter");
		}
	});*/
}

/*Function that closes popup when the no button is pressed*/
function closePopupConfirmation() {
	var response;
	
	response = confirm("You are now being taken to the demonstration website. Please note we do not sell these products.");
	
	if (response)
	{
		/*Use ajax to call demoConfirmation.asp which sets the session variable "demoConfirmed" to true*/
		$.get("demoConfirmation.asp");
		/*Fade out the popup*/
		$("#popupConfirmationContainer").fadeOut("slow");
		/*Fade out the overlay*/
		$("#popupConfirmationOverlay").fadeOut("slow");
	}
}

/*Function which suggests other sites when the yes button is pressed*/
function showSiteSuggestions() {
	/*Slide in the list of recommended sites*/
	$("#popupSiteSuggestions").slideDown("slow");
	/*Used to position the popup in the middle of the screen now that it is larger (the height of the suggestions list (100) is added to the height of the popup container)*/
	$("#popupConfirmationContainer").animate({"top": $(window).height()/2-($("#popupConfirmationContainer").height()+100)/2+"px"}, "slow");
	/* Disable the buttons*/
	$("#popupBuyButton").hide();
	$("#popupDemoButton").hide();
}
