// AFSC Survey Message script (jQuery)
// This script, which places a Firefox-style "alert bar" at the top
// of the page, can be retooled for different messages and uses, 
// by changing the content and cookie behaviors.
// Modified for FGC - changed cookie name and link text

$(document).ready(function() {
 
    //alert('Survey alert loaded!'); //DEBUGGING

	// Check for the cookie, which is set when they click either link.
	// if it's not there, show the alert bar and set the cookie.
	if ($.cookie('QY_survey_msg_cookie') != 'set') {
	
		// Create "alert bar" and prepend in BODY tag:
		$('<div id="topalert"><p><b>We need your opinion:</b> Help us improve this website. <a href="http://www.fgcquaker.org/qy/quaker-youth-web-survey" target="_blank" id="survey-link">First question &raquo;</a> <a href="#" id="close-link">Not now</a></p><hr /></div>').css({ background: '#F4D97A' }).prependTo('body');
		  
		// Assign click functions:
		
		$("div#topalert a#survey-link").click(function () {
			// If the visitor clicks the link to take the survey, 
			// set the cookie so the message doesn't appear again.
			// (actually expires in a year, but that's well longer 
		    // than we'd tend to keep a message like this active.) 
			$.cookie('QY_survey_msg_cookie', 'set', { expires: 365, path: '/' });
			// return true because we still want to follow the link to the survey:
			return true; 
		});
		
		$("div#topalert a#close-link").click(function () {
			$("div#topalert").slideUp();
			// If the visitor clicks the link to close the message, 
			// set the cookie so the message doesn't appear again for 1 day.
			$.cookie('QY_survey_msg_cookie', 'set', { expires: 1, path: '/' });
			// Prevent default action of link:
			return false;
		});
		
	} // end if (cookie check)
		   
});
