// JavaScript Document

// *** Variables ***
var mDebug;
var mHeader, mFooterOrange, mFooterBlue, mFooterRed;

// Initialisation - get a ref to the CSS rules we need to modify
function init()
{	
	// Get a ref to the DIV to use for debug messages
	mDebug = document.getElementById("Debug");
	trace("DEBUG MESSAGES:");
	
	// Get the header (logocontainer) CSS stlye
	var mySheet = document.styleSheets[0];	
	if (mySheet) 
	{   
		// Get array of stylesheets (.rules is IE only)		
		var myRules = mySheet.cssRules ? mySheet.cssRules: mySheet.rules;
		
		for (i = 1; i < myRules.length; i++) 
		{
			//trace("Checking rule: " + myRules[i].selectorText.toLowerCase());
			
			if (myRules[i].selectorText.toLowerCase() == ".logocontainer") 						// Header
			{
				mHeader = myRules[i];
				trace("Found Header");
			}
			else if (myRules[i].selectorText.toLowerCase() == ".footercontainer_orange") 		// Footers
			{
				mFooterOrange = myRules[i];
				trace("Found Footer Orange");
			}
			else if (myRules[i].selectorText.toLowerCase() == ".footercontainer_blue") 
			{
				mFooterBlue = myRules[i];
				trace("Found Footer Blue");
			}
			else if (myRules[i].selectorText.toLowerCase() == ".footercontainer_red") 
			{
				mFooterRed = myRules[i];
				trace("Found Footer Red");
			}
		}
	}
}

// Debug function to trace out messages
function trace(tMessage)
{
	if (console != null)
	{
		console.log(tMessage);						// If there's a debug window available, use it!
	}
	else
	{
		mDebug.innerHTML += tMessage + "<br>";		// Otherwise use the debug DIV
	}
}

// Change Header Images
function changeImage(newName) 
{
	if (mHeader) 
	{                
		mHeader.style.backgroundImage = "url('" + newName + "')";
		
		// Change Footer from here -> hack
		switch(newName)
		{
			case("images/CSL_Logo_Pink.jpg"):
				changeFooter("images/CSL_Footer_Red.jpg");
				break;
			case("images/CSL_Logo_Red.jpg"):
				changeFooter("images/CSL_Footer_Red.jpg");
				break;
			case("images/CSL_Logo_Orange.jpg"):
				changeFooter("images/CSL_Footer_Orange.jpg");
				break;
			case("images/CSL_Logo_Blue.jpg"):
				changeFooter("images/CSL_Footer_Blue.jpg");
				break;
			default:
				break;
		}
	}		
}

// Change Footer Images
function changeFooter(newName)
{			
	trace("Changing Footer for: " + newName);
	if (mFooterOrange) 
	{
		mFooterOrange.style.backgroundImage = "url('" + newName + "')";
	}
	
	if (mFooterBlue) 
	{                
		mFooterBlue.style.backgroundImage = "url('" + newName + "')";
	}	
	
	if (mFooterRed) 
	{                
		mFooterRed.style.backgroundImage = "url('" + newName + "')";
	}	
}
