// Controls display of masthead message.
function initMastheadMessage() {
	var createCookieBoolsArray = [true, false];							// Boolean array that determine probability that 'displaySurvey' cookie 
																		// will be created if it doesn't exist (1/2 chance)
	var createCookieBool = createCookieBoolsArray[						// Boolean chosen at random. Used as flag.
			Math.floor(Math.random()*createCookieBoolsArray.length)];

	cookieJar = new CookieJar({expires:2629743, path: '/'});			// Create cookie jar (cookies expire after 1 month)
	helpALSurveyCookie = cookieJar.get('helpALSurvey');
	
	// If 'helpALSurvey' cookie does not exist then set to value of 'createCookieBool'
	if( helpALSurveyCookie == null )
	{
		cookieJar.put('helpALSurvey', {show:createCookieBool});			// Set value of cookie
		helpALSurveyCookie = cookieJar.get('helpALSurvey');				// Reassign new cookie val to variable
	}
	
	// If 'true' then show survey box
	if( helpALSurveyCookie.show == true )
	{
		Effect.Appear('mastheadMessageBox');
	}

	// Event observers
	Event.observe('mastheadCancel', 'click', mastheadCloseAndUpdate);		// Observe 'X' image - if clicked then close masthead and set cookie
	Event.observe('mastheadMessageLink', 'click', mastheadCloseAndUpdate);	// Observe survey link
}

// User clicked close button
function mastheadCloseAndUpdate(evt) {
	// If the element that triggered the event was not the survey link then do not
	// continue to page. (used for 'X' close button)
	if( Event.element(evt).id != 'mastheadMessageLink' )
	{
		Effect.SlideUp($('mastheadMessageBox'));				// Slide box out of sight
		Event.stop(evt);
	}
	else
	{
		$('mastheadMessageBox').hide();							// If survey link clicked then hide masthead
	}

	cookieJar.put('helpALSurvey', {show:false});				// Set cookie to false - do not show masthead again
}