$(document).ready(function(){
	if ($.cookie('shownSurvey') !== 'true') {
		var oldPageCount = 0;
		var newPageCount = 0;
		var partyPage = 2;
		// check to see if pageCount cookie has already been set
		if ($.cookie('pageCount') && (!isNaN($.cookie('pageCount'))) ) { oldPageCount = parseInt($.cookie('pageCount')); }
		// if the user hasn't seen the magical number of pages, set a new page count value
		if (oldPageCount < partyPage) {
			newPageCount = oldPageCount + 1;
			$.cookie('pageCount', newPageCount, {expires: 365, path: '/'});
		}
		if (newPageCount == partyPage) {
			$.cookie('shownSurvey', 'true', {expires: 365, path: '/'}); // set a cookie so this browser doesn't see the survey question again
			showSurveyPop(); // show the survey question
		}
	}
});
function showSurveyPop() {
	$("#wrapper").before("<img src='/images/global/survey_popup.jpg' alt='Have time for a quick survey?' border='0' width='322' height='194' style='position:absolute;z-index:99999;border:0;margin:0;' id='surveyImage' usemap='#surveyMap' /><map id='surveyMap' name='surveyMap'><area alt='Close' shape='rect' coords='250,0,325,43' href='#' class='surveyClose' /><area alt='Take the Survey' shape='rect' coords='5,141,135,185' href='http://www.surveymonkey.com/s/DPJQXQW' target='_blank' class='surveyOpen' /><area alt='No thanks' shape='rect' coords='145,150,230,185' class='surveyClose' href='#' /></map>");
	pageTracker._trackPageview('/survey/');
	surveyWrapperDiv = document.getElementById("wrapper");
	wrapperLeft = getRealLeft2(surveyWrapperDiv);
	
	// reposition off-screen
	$("img#surveyImage").css("margin-left", wrapperLeft + 600 + "px");
	$("img#surveyImage").css("margin-top", -300 + "px");
	
	setTimeout("revealPrompt()", 2500);
	
	$(".surveyClose").click(function(){ $("#surveyImage").hide(); pageTracker._trackPageview('/survey/no/'); return false; });
	$(".surveyRules").click(function(){ pageTracker._trackPageview('/survey/rules/');  });
	$(".surveyOpen").click(function(){ $("#surveyImage").hide(); pageTracker._trackPageview('/survey/yes/'); });
}
function getRealLeft2(e) {
	var realLeft = 0;
	while (e.offsetParent) {
		realLeft += e.offsetLeft;
		e = e.offsetParent;
	}
	return realLeft;
}

function revealPrompt() {
	jQuery.easing.def = "easeOutBack";
	jQuery("img#surveyImage").animate({
		"margin-top": 45
	}, 750, function() { 
		// after animation
	});
}