// JavaScript Document
//alert(window.history);
// Fixes IE Flicker
    // Thanks to www.mister-pixer.com 
    try 
    {
        document.execCommand("BackgroundImageCache", false, true);
    } catch(err) {}

var infiniteLoopCounter = 0;
// This function only works with image tags
// state consists of a three state enumeration ("on", "off", "hover")
// image names cannot have a (.) in it.  This function splits the name on that to preserver the file extension
// I'll work on making that patch to make it even more flexible
function SwapImage(elementID, state)
{
	// grab the image tag you want to swap states
	
	var instance = document.getElementById(elementID);
	var fileExtension = "";
	var fileName = "";
	var newFullFileName = "";
	//alert("Hello There");
	// grab the image string pathName
	var imagePath = instance.src;
	
	// split it on the (.)
	// split the string and dump the contents into an array
	var arrayOfSplit = new Array();
	var folderSplit = new Array();
	folderSplit = imagePath.split("/");
	// recreate the folder structure
	var tempArray = new Array();
	tempArray = imagePath.split("/", folderSplit.length-1);
	var newPath = tempArray.join("/");
	var fullFileName = folderSplit[folderSplit.length-1];
	arrayOfSplit = fullFileName.split(".");
	if(arrayOfSplit[arrayOfSplit.length-1].length == 3)
	{
		// this is the file extention propogate it back up 
		fileExtension = arrayOfSplit[arrayOfSplit.length-1];
		fileName = arrayOfSplit[arrayOfSplit.length-2];
	//	alert("FileName: " + fileName);
		if(fileName.indexOf("_on") != -1 && state != "on")
		{
			newFullFileName = fileName.slice(0, fileName.length-3) + "_" + state + "." + fileExtension;
		}
		else if (fileName.indexOf("_off") != -1 && state != "off")
		{
			newFullFileName = fileName.slice(0, fileName.length-4) + "_" + state + "." + fileExtension;
		}
		else if(fileName.indexOf("_hover") != -1 && state != "hover")
		{
			newFullFileName = fileName.slice(0, fileName.length-6) + "_" + state + "." + fileExtension;
		}
	//	alert("New Full FileName: " + newFullFileName);
		imagePath = newPath + "/" + newFullFileName;
		// the rest of the string
		
		
		//alert(state);
	}
	
	instance.src = imagePath;
	//alert(arrayOfSplit[arrayOfSplit.length-1].length);
}

function RecursiveStringSplit(seperator, baseString)
{
	// normally would be a good idea to make sure that baseString is a base string but it's not being used for anything major
	if(infiniteLoopCounter == 0)
	{
	
		// split the string and dump the contents into an array
		var arrayOfSplit = new Array();
		arrayOfSplit = baseString.split(seperator, 1);
		if(arrayOfSplit[arrayOfSplit.length-1].length == 3)
		{
			// this is the file extention propogate it back up 
		}
		infiniteLoopCounter++;
	}
}

/* Navigation Javascript */

// This function handles hover states for the nav.
function NavSwapState(linkID,containerID, state, style)
{
	
	if(state == "hover")
	{
		document.getElementById(containerID).className = style + "Container_" + state;
		//alert("Link ClassName: " + document.getElementById(linkID).className);
		//document.getElementById(linkID).className = style + "Link_" + state;
		//alert("Link ClassName: " + document.getElementById(linkID).className);
	}
	else if(state == "off")
	{
		document.getElementById(containerID).className = style + "Container";
		//document.getElementById(linkID).className = style + "Link";
	}
	else
	{
		// no state matched up 
		// get off your butt and write your own
		alert("State did not match, currently only supports hover and off");
	}
		
}

/* LOGIN SCRIPTS */
function logout(value)
{
	if(document.logout_form)
	{
		document.logout_form.logoutFlag.value = value;
		document.logout_form.submit();	
	}
}