//*****************************************************************************************//
//*******PRELOAD AND ROLLOVER FUNCTIONS START********//

//This function preloads the global navigation elements
var navRoll = false; //Set this variable to false so no global rollovers will work until all preloading is done.
function plGnav()
{
	imgRoll();
	navRoll = true;
}

function uPreload(imgObjName,path,ext)
{
	eval( imgObjName + "a = new Image();" );
	eval( imgObjName + "a.src = '" + path + "/" + imgObjName + "a" + ext + "';");
}
 
//This function works in conjuction with the uPreload function to automatically preload images on a page.
//Images with the "roll" class in the HTML markup will be preloaded using "uPreload" and must be named accordingly.
//Ex. <img src="myimagei.gif" alt="my image alt" class="roll" />
function imgRoll()
{
	var linkArray = document.getElementsByTagName("img");
    for (var loop=0; loop<linkArray.length; loop++)
    {
    	imgClassArray = linkArray[loop].className.split(' ');
        for (var i=0; i<imgClassArray.length; i++)
        {
         	if (imgClassArray[i] == "roll")
         	{
    			var imgWithPath = linkArray[loop].src;
    			var imgPath = imgWithPath.substring( 0, imgWithPath.lastIndexOf( '/' ));
    			var imgName = imgWithPath.substring( imgWithPath.lastIndexOf( '/' ) + 1);
    			var imgObjName = imgName.substring( 0, imgName.lastIndexOf( '.' ) ) ;
    			var fileExt = imgWithPath.substring(imgWithPath.lastIndexOf('.'), imgWithPath.length); //file extension
    			if(imgObjName.substring(imgObjName.length -1)!= 'o')
    			{
    				uPreload(imgObjName.substring(imgObjName.length - 1,0),imgPath,fileExt);
    			}
    			linkArray[loop].parentNode.onmouseover=function(){roll(this);};
				linkArray[loop].parentNode.onmouseout=function(){roll(this);};
         	}
        }
    }
}
 
//This function is for navigation rollover images; uName is name of graphic, uState is on, off or over state
//This function only works for images that have been preloaded using the "uPreload" function.
//usage: <a href="myPage.aspx" onmouseover="nr('myimage','a')" onmouseout="nr('myimage','i')"><img src="myimagei.gif" alt="my image alt" id="myimage" class="pl" /></a>
function roll(o)
{
	if(navRoll)
	{
	var i,isnode,src,ftype,fsuffix,newsrc,nownode;
	for (i=0;i<o.childNodes.length;i++) // loop through all childNodes
	{
		nownode=o.childNodes[i];
		// if the node is an element and an IMG set the variable and exit the loop
		if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))
		{
			isnode=i;
			break;
		}
	}
	// check src and do the rollover
	src = o.childNodes[isnode].src; //full src with path
	fsrc = src.substring(src.lastIndexOf('.'), 0); //full src with path without file extension
	ftype = src.substring(src.lastIndexOf('.'), src.length); //file extension
	fsuffix = src.substring(src.lastIndexOf('.'), src.length - 5); //type of item ex.'i', 'a' or 'o'
	if(fsuffix == 'a')
	{
		newsrc = fsrc.substring(fsrc.length-1,0)+ 'i' + ftype;
	}
	else if(fsuffix == 'i')
	{
		newsrc = fsrc.substring(fsrc.length-1,0)+ 'a' + ftype;
	}
	else
	{
		newsrc = fsrc.substring(fsrc.length-1,0)+ 'o' + ftype;
	}
	o.childNodes[isnode].src=newsrc;
	}
}

AttachEvent(window, "load", plGnav);
AttachEvent(window, "load", sfHover);

//*******PRELOAD AND ROLLOVER FUNCTIONS END********//
//*****************************************************************************************//

function AttachEvent(elementObj, eventName, eventHandlerFunctionName)
{
  if (elementObj.addEventListener) 
  { // Non-IE browsers
    elementObj.addEventListener(eventName, eventHandlerFunctionName, false);		
  } 
  else if (elementObj.attachEvent) 
  { // IE 6+
    elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);
  } 
  else 
  { // Older browsers 
    var currentEventHandler = elementObj['on' + eventName];
    if (currentEventHandler == null) 
    {
      elementObj['on' + eventName] = eventHandlerFunctionName;
    } 
    else 
    {
      elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
    }
  }
}

function sfHover() 
{
	var browserName=navigator.appName;
	if (browserName=="Microsoft Internet Explorer" && document.getElementById("tnav"))
	{
		var sfEls = document.getElementById("tnav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

function divDisplay(divName, displayStyle)
{
	document.getElementById( divName ).style.display = displayStyle;
}
