/**
 * This file includes the code to display the transparent messages to the user.
**/

// Current Page variables
var timer;
var currentMargin = 0;
var slideInProgress = false;

var messages = new Array();
var currentMessage = 0;

var timeToDisplaySingleMessage = 5000;
var timeToDisplayEachMessage = 2500;


//Display the next message in the array. If this is the last message, clear
//the interval that calls this function.
function changeMessage()
{
	// Display the current message (and properly align it)
	$('pageMessage').innerHTML = messages[currentMessage];
	verticalAlignMessage();
	
	// Increment the current message index
	currentMessage++
	
	if(messages.length == 1)
	{
		// We only have a single message to display
		// We'll display it for a few seconds, and then hide the message window
		setTimeout("startSlide();", timeToDisplaySingleMessage);
	}
	else if(currentMessage < messages.length)
	{
		// We have more messages to display, schedule the next message to be displayed after a short display
		setTimeout("changeMessage();", timeToDisplayEachMessage);
	}
	else
	{
		// We're done displaying all of the multiple messages we had
		// Schedule the message window to be hidden
		setTimeout("startSlide();", timeToDisplayEachMessage);
	}
}

//Calls the show/hide functions for the message div
function startSlide()
{
	//Disables the slide if there is one already in progress
	if(!slideInProgress)
	{
		slideInProgress = true;
		
		if(currentMargin == 0)
		{
			currentMargin = -118;
			timer = setInterval("showMessageDiv();", 1);
		}
		else
		{
			timer = setInterval("hideMessageDiv();", 1);
		}
	}
}

// Shows the sliding message div
function showMessageDiv()
{
	if(currentMargin < 0)
	{
		currentMargin = currentMargin + 12;
		$('siteMessagesBackground').style.marginTop = currentMargin + "px";
		$('siteMessagesContent').style.marginTop = currentMargin + "px";
	}
	else
	{
		window.clearInterval(timer);
		slideInProgress = false;
		
		currentMessage = 0;
		changeMessage();
	}
}

// Hides the sliding message div
function hideMessageDiv()
{
	if(currentMargin > -118)
	{
		currentMargin = currentMargin - 12;
		$('siteMessagesBackground').style.marginTop = currentMargin + "px";
		$('siteMessagesContent').style.marginTop = currentMargin + "px";
	}
	else
	{
		window.clearInterval(timer);
		slideInProgress = false;
		currentMargin = 0;
	}
}

// Vertically centers message text
function verticalAlignMessage()
{
	var height = $('pageMessage').offsetHeight;
	$('pageMessage').style.marginTop = -(height / 2) + "px";
}

//AddOnload(verticalAlignMessage);

