// *****************************************************
// Random Header Images
// Mears 08.06
//******************************************************

function setHeaderImage() {
		
	// Create a random number between 0 and the total number of images	
	var baseNum = headerImage.length;
	var randomNum = (Math.floor(Math.random()*baseNum));
				
	//Swap default image with random image
	var finalHeader = document.getElementById("body-header-img");
	finalHeader.setAttribute("src", headerImage[randomNum]);
	
}


// *****************************************************
// Highlight Current Tab
// Mears 08.06
//******************************************************

function setCurrentTab() {

	//get the name of the current page
	var bodyId = document.getElementsByTagName("body")[0].getAttribute("id");

	var getNav = document.getElementById("tabnav");
	var navLinks = getNav.getElementsByTagName("a");
	
	for ( var i=0; i< navLinks.length; i++) {
		var linkTitle = navLinks[i].getAttribute("title");
		
		if ( linkTitle.indexOf(bodyId) != -1 ) {
			
			navItem = navLinks[i].parentNode;			
			navItem.className="current";			
		
		}
		
	}
	
}


//*******************************
//Hover Tabs for IE
// Mears 08.18
//*******************************

hoverTab = function() {
//alert("test");
if (document.all&&document.getElementById) {
navRoot = document.getElementById("tabnav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}


// DF1.1 :: domFunction 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
//******************************************************

function domFunction(f, a)
{
	var n = 0;
	var t = setInterval(function()
	{
		var c = true;
		n++;
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
		{
			c = false;

			if(typeof a == 'object')
			{
				for(var i in a)
				{
					/*  */
					if(	(a[i] == 'id' && document.getElementById(i) == null)
						||
							(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
						|| 
							(a[i] == 'class' && !checkElementByTagClass(i.split('.')[0], i.split('.')[1]))
						) 
					{ 
						c = true; 
						break; 
					}
				}
			}
			/* if(!c) { alert('function = ' + f); } */
			if(!c) {f(); clearInterval(t); }
		}
		if(n >= 100)
		{
			clearInterval(t);
		}
	}, 250);
};


//Initializations
var initHeaderImage = new domFunction(function() {
		setHeaderImage();
	}, { 'body-header' : 'id' } );
	
var initCurrentTab = new domFunction(function() {
		setCurrentTab();
		hoverTab();
	}, { 'tabnav' : 'id' } );