//If there is text in this variable it will be displayed between the header and the main area on every page
var sitewideMessageHeader = "SHOW CANCELLED:";
var sitewideMessageBody = "Tonight's presentation of King Lear has been cancelled due to the weather (7/29/2011).";
var fallbackMessage = "Welcome to Flock Theatre's new website. Check back often to see the latest improvements.";
//If there is no expiration date, set this equal to null
var sitewideMessageStart = new Date(2009,07,01,00,00,00,00);
var sitewideMessageEnd = new Date(2011,06,29,22,00,00,00);

function populateSitewideMessage()
{
	var messageBox = document.getElementById('breakingNews');
	var temporalNewsSection = document.getElementById('temporalNewsSection');
	//If there is a message provided and today is not beyond the expiration date or there is no expiration date
	//Show the message in the message bar
	if(sitewideMessageBody && (!sitewideMessageEnd || new Date() < sitewideMessageEnd)
		&& (!sitewideMessageStart || new Date() > sitewideMessageStart))
	{
		messageBox.innerHTML = "<span id='pulsingHeaderText'>" + sitewideMessageHeader + "</span> " + sitewideMessageBody;
		messageBox.style.display = 'block';
		/*temporalNewsSection.innerHTML = "<span style=\"font-size:125%;color:#f00;\"><strong>" + sitewideMessageHeader + "</strong></span><br />" + sitewideMessageBody;
		temporalNewsSection.style.display = 'block';*/
		startPulsingText('pulsingHeaderText','99','FF');
	}
	else
	{
		//This is in place for the message about the new flock website.  Remove it eventually.
		if(fallbackMessage.length > 0)
		{
			messageBox.innerHTML = fallbackMessage;
			messageBox.style.display = 'block';
		}
		else
		{
			messageBox.style.display = 'none';
		}
		
	}
	temporalNewsSection.style.display = 'none';
}

function populateNews() {
	var newsHtml = "";
	if(currentNews)
	{
		for(var i=0; i < currentNews.length; i++)
		{
			newsHtml += currentNews[i].getHTML();
		}
	}
	
	if(newsHtml.length == 0)
	{
		newsHtml = "There is no current news.";
	}
	
	$("#newsfeed").append(newsHtml);
}

$(document).ready(function() {
	//Set the copyright year
	$("#copyrightYear").text(new Date().getFullYear());
	
	//set the active menu tabs, current Tab must be set on each page
	if(currentTab)
	{
		$("#"+currentTab).addClass("current");
		$("#"+currentTab + " div.select_sub").addClass("show");
	}
	
	//set up the dialog which will be shown when the good search is clicked
	$("#goodSearchDialog").dialog({
		modal: true,
		autoOpen: false,
		height: 250,
		width: 300,
		buttons: {
			Ok: function() {
				window.location.href = "http://www.goodsearch.com";
				$(this).dialog('close');
			}
		}
	});
	
	$("#genericDialog").dialog({
		modal: true,
		autoOpen: false,
		height: 400,
		width: 400,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});

	//set the click function for the goodsearch bar
	$("#goodSearchLink").click(function(event) {
		event.preventDefault();
		$("#goodSearchDialog").dialog('open');
	});
	
	drawMenu();
	
	populateNews();
	
	populateSitewideMessage();
   });

function drawMenu()
{
	$("#navbar").load("menu.html");
}

function openSelfTest()
	{
		window.open ("selftest.html","selftest","menubar=0,resizable=0,scrollbars=1,width=500,height=700,top=30,left=30");
	}
	
	function submitOnEnter(event)
	{
		  if (event.keyCode == 13)  
          {  
              getDirections(); 
          }  
	}
	
function openDialog(title, file) {
	$("#genericDialog").load(dialogPath + file);
	$("#genericDialog").dialog('option', 'title', title).dialog('open');
}

function getDirections()
	{
		var fromAddr = document.getElementById("fromAddr").value;
		var toAddr = document.getElementById("toAddr").value;
		var mapPanel = document.getElementById("googleMap");
		var map = new GMap2(mapPanel);
		var directionsPanel = document.getElementById("googleDirections");
		var directions = new GDirections(map, directionsPanel);
		directions.load("from: " + fromAddr + " to: " + toAddr);
	}
	
	function dec2hex(dec) {return dec.toString(16);}
			function hex2dec(hex) {return parseInt(hex,16);} 
			
			/*Color changing code complements of www.xe.com - The XE.com Universal Currency Converter*/
			//Only operates on the first two digits of the color for red
			var firstHexColor = '99';
			var secondHexColor = 'FF';
			var color7 = hex2dec(firstHexColor);
			var hexco7 = '';
			var interval7 = 3.0;
			function redColorPulse(elementId) {
				  if ((color7 + (interval7)) > hex2dec(secondHexColor)) { interval7 *= -1; }
				  if ((color7 + (interval7)) < hex2dec(firstHexColor)) { interval7 *= -1; }
				  color7+= interval7;
				  hexco7 = dec2hex(color7);
				  //hexco7 = "#" + ("000000").substring(0,6 - hexco7.length) + hexco7;
				  hexco7 = "#" + hexco7 + "0000";
				  document.getElementById(elementId).style.color = hexco7;
			}
			
			//Starts the element id color CSS attribute pulsing between the main and fade colors 
			//Colors should be passed in as 6-digit hex without the number sign
			
			function startPulsingText(elementId, lowColor, highColor) {
				firstHexColor = lowColor;
				secondHexColor = highColor;
				setInterval("redColorPulse('"+elementId+"')",2);
			}

