//*****************************************************************************************//
//*******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);

//*******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 pf() //pop-up printer friendly pages
{
	var url = window.location.href.split('#')[0];
	url += url.indexOf('?') != -1 ? '&' : '?';
	wPop( url + 'print=1', 'print', 515, 550, 'yes' );
}

function wPop(url, winName, wWidth, wHeight, scrll)
{
   var scrollB;
   if(!scrll)
   {
      scrollB = 'no';
      var pWidth = wWidth;
      var rSize = 'no'
   }
   else 
   {
      scrollB = scrll;
      wWidth = parseInt(wWidth) + 20;
      var rSize = 'yes'
   }
   var iMyWidth;
   var iMyHeight;
  iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
   //half the screen width minus half the new window width (plus 5 pixel borders).
   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
   //half the screen height minus half the new window height (plus title and status bars).
   var zWin = window.open(url, winName, "status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=" + rSize + ",left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
   zWin.focus();
}

function legal_window(url)
{
	var link = window.open(url,"legal",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,top=(20),left=(20),screenX=(20),screenY=(20),width=560,height=450');
	link.focus();
}

function flashSwap( flashDiv, flatDiv ) {
	
	detectFlash();
	if ( haveFlashVer ) { 
		document.getElementById( flatDiv ).style.display = 'none';
		document.getElementById( flatDiv ).style.height = '0px';
		document.getElementById( flashDiv ).style.display = 'block';
		document.getElementById( flashDiv ).style.height = 'auto';
	}
	else {
		document.getElementById( flashDiv ).style.display = 'none';
		document.getElementById( flashDiv ).style.height = '0px';
		document.getElementById( flatDiv ).style.display = 'block';
		document.getElementById( flatDiv ).style.height = 'auto';
	}
}

function showHide( id, bShow ) {
	document.getElementById( id ).style.display = (bShow) ? 'block' : 'none';
	document.getElementById( id ).style.height = (bShow) ? 'auto' : '0px';
}
