var mainNavDivObj;
var globalNavDivObj;
	addEventHandler(window, 'load', loadCommon, false)
		
	function getMainNavDivObj()
	{
		return document.getElementById('mainNav');
	}

	function getGlobalNavDivObj() {
	    return document.getElementById('globalNavigation');
	}
	function loadCommon()
	{
	    mainNavDivObj = getMainNavDivObj();
	    globalNavDivObj = getGlobalNavDivObj();
	    if (mainNavDivObj && globalNavDivObj)
	        iniNav();
	}
	
	function iniNav()
	{
	    var navImageObjects = mainNavDivObj.getElementsByTagName('img');
	    attachNavMouseEvents(navImageObjects);
	    navImageObjects = globalNavDivObj.getElementsByTagName('img');
	    attachNavMouseEvents(navImageObjects);
	}

    //For each image in the array, set the over/rest image and add the event handlers.
	function attachNavMouseEvents(imageArray) 
	{
	    for (var i = 0; i < imageArray.length; i++) 
	    {
	        buttonObj = imageArray[i];
	        buttonObj.restImage = buttonObj.src;
	        buttonObj.overImage = buttonObj.src.replace('R', 'O');
	        addEventHandler(buttonObj, 'mouseover', overButton, false);
	        addEventHandler(buttonObj, 'mouseout', outButton, false);
	        //When loading the images and events, we need set the "at" state for the section we are in.
	        swapImage(buttonObj);

	    }
	}
	
	function overButton(e) 
	{
	    this.src = this.overImage	
    }
	
	function outButton() {
	    swapImage(this);
	}

	function swapImage(refObj) {
	    if (firstCategory(window.location.href) == firstCategory(refObj.parentNode.href))
	        refObj.src = refObj.overImage;
	    else
	        refObj.src = refObj.restImage;

	}

	function firstCategory(url) {
		return url.split('/')[3];
	}

	function replaceAll(text, strA, strB) {
	    while (text.indexOf(strA) != -1) {
	        text = text.replace(strA, strB);
	    }
	    return text;
	}
	//Props
	//http://weblogs.asp.net/asmith/archive/2003/10/06/30744.aspx
	//CJB comments: Adding the handler like this accomplishes 4 goals
	//1.  You can add multiple handlers in multiple scripts and not step on each other
	//2. The handler has access to the caller via 'this'
	//3. Use built in event handling. That is, we are not creating a seperate array of functions to call (The object itself tracks the events, not some external EventHandlerDelegateFactory)
	//4. Ensure we have access to the event argument as calling
	function addEventHandler(obj, eventName, fn, useCapture)
	{
		var callbackName = eventName + 'Handler';
		//Add as many handlers as we want
		while (obj[callbackName] != undefined )
		{
			var d = new Date()
			callbackName = eventName + 'Handler' + d.getMilliseconds();
		}
		
		//Here is the 'trick' Attach the handler to the object itself. Have the anon event listener call the handler on the object. That way 'this' works in IE as well as FF
		obj[callbackName] = fn;
		if ( obj.addEventListener ) 
		{
		    obj.addEventListener(eventName, function(e) { obj[callbackName](e); }, useCapture);
		} 
		else if ( obj.attachEvent ) 
		{ 
			obj.attachEvent("on" + eventName, function(e){obj[callbackName](e);});
		}
	}

	//For Search
	function clearTB(refObj) {
	    if (refObj.value = '&nbsp;Enter Keyword')
	        refObj.value = '';
	}


	function CallSearch(refObj) {

	    var objSearchText = refObj;
	    var searchText;

	    if ((objSearchText != null)) {
	        searchText = objSearchText.value;
	        searchText = searchText.replace(/</gi, "< ");
	        searchText = searchText.replace(/>/gi, " >");
	        objSearchText.value = searchText;
	    }

	    document.cookie = "postbackcookie=";

	    return true;
	}
	//End Search
	
	
	//props
	//http://www.chapter31.com/2006/12/07/including-js-files-from-within-js-files/
	function include(file)  
	{  
		var script  = document.createElement('script');  
		script.src  = file;  
		script.type = 'text/javascript';  
		script.defer = true;  

		document.getElementsByTagName('head').item(0).appendChild(script);
    }

//Media Tracking Functions for Flowplayer and Omniture
function omniMediaTrackingStart(mediaName,mediaLength,mediaPlayerName) {      
m.Media.open(mediaName,mediaLength,mediaPlayerName);
m.Media.play(mediaName,0);
}

function omniMediaTrackingStop(mediaName,mediaPosition) {
m.Media.stop(mediaName,mediaPosition);
m.t();
}

function omniMediaTrackingResume(mediaName,mediaPosition) {
m.Media.play(mediaName,mediaPosition);
m.t();
}

function omniMediaTrackingDone(mediaName) {
m.Media.close(mediaName);
m.t();
}
