/**************************************************************************************
******							CREATE DROPSHADOW JAVASCRIPT					 ******
**************************************************************************************/
  function shadowInit() {
		/** This creates the getElementsByClassName function if the browser is IE **/
		if (document.getElementsByClassName == undefined) 
		{
			document.getElementsByClassName = function(className)
			{
				var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
				var allElements = document.getElementsByTagName("*");
				var results = [];
		
				var element;
				for (var i = 0; (element = allElements[i]) != null; i++) {
					var elementClass = element.className;
					if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
						results.push(element);
				}
		
				return results;
			}
		}

		// Get all the element of the class white_box
		var boxes = document.getElementsByClassName('white_box');
		// For all the elements found add the shadow and remove the border style
		for(var i= 0; i < boxes.length; i++)
		{
			addShadow(boxes[i]);
			boxes[i].style.border = "none";
		}
	
		// Add drop shadow to the given divObj
		function addShadow(divObj)
		{
			var temp = [];
			var i = 0;
			/* Add all the child to a temporary storage array 
			The reason you cant just say divObj.childNodes is b/c that is a pointer and what ever you do next will change 
			what it is pointing to and you will lose the original children */
			while(divObj.childNodes.length > 0)
			{
				temp[i] = divObj.childNodes[0];
				divObj.removeChild(divObj.childNodes[0]);
				i++;
			}
			
			// add a new div object to the divObj and set var next to point to the new div then set its className
			divObj.appendChild(document.createElement("div"));
			var next = divObj.firstChild;
			next.className = "bottom_shadow";
			
			// add a new div object to the divObj and set var next to point to the new div then set its className
			next.appendChild(document.createElement("div"));
			next = next.firstChild;
			next.className = "left_side";
			
			// add a new div object to the divObj and set var next to point to the new div then set its className
			next.appendChild(document.createElement("div"));
			next = next.firstChild;
			next.className = "right_side";

			// add a new div object to the divObj and set var next to point to the new div then set its className
			next.appendChild(document.createElement("div"));
			next = next.firstChild;
			next.className = "left_corner";
			
			// add a new div object to the divObj and set var next to point to the new div then set its className
			next.appendChild(document.createElement("div"));
			next = next.firstChild;
			next.className = "right_corner";
			
			// add all the original children back to the intermost new div
			for(var i = 0; i < temp.length; i++)
			{
				next.appendChild(temp[i]);
			}
		}
	}
/****************************	END DROPSHADOW SCRIPT	*******************************/
	
	
	
	
/**************************************************************************************
******							INITIALIZE HOVER JAVASCRIPT						 ******
**************************************************************************************/
 function hoverInit() {
		var gnm = document.getElementById('greennav_menu');
		// center the whole green nav and set the class for the last item
		var last = gnm.lastChild;
		if (last.nodeName!='LI')
		{
			last = last.previousSibling;
		}
		var pad = Math.round((gnm.offsetWidth - (last.offsetLeft+last.offsetWidth)) /2);
		gnm.style.paddingLeft =pad+'px';
		last.className +=' last';

		// add the hover class to LIs when you mouse over them
		var ULs = document.getElementsByTagName("ul");
		for (var i=0;i <ULs.length ;i++ ) {
			if (ULs[i].className.indexOf('menu_top')>=0) {
				for (var j=0; j < ULs[i].childNodes.length; j++) {
					var node = ULs[i].childNodes[j];
					if (node.nodeName == "LI") {
						// the 'prev' class gets rid of the divider line in the LI to the left of the highlighted one
						if (node.className.indexOf('active') >=0 ) {
							if (node.previousSibling) {
								if (node.previousSibling.nodeName=='LI') node.previousSibling.className +=' prev';
								else if (node.previousSibling.previousSibling && node.previousSibling.previousSibling.nodeName=='LI') 
									node.previousSibling.previousSibling.className +=' prev'; 
							}
						} 
						//mouseover
						node.onmouseover= function() { 
							this.className += ' hover';
							if (this.previousSibling) {
								if (this.previousSibling.nodeName=='LI') this.previousSibling.className +=' prev';
								else if (this.previousSibling.previousSibling && this.previousSibling.previousSibling.nodeName=='LI') 
									this.previousSibling.previousSibling.className +=' prev'; 
							}
						}
						//mouseout
						node.onmouseout= function ()  {
							this.className = '';
							//this.className = this.className.replace(' hover',''); 
							if (this.previousSibling) {
								if (this.previousSibling.nodeName=='LI') this.previousSibling.className =this.previousSibling.className.replace(' prev','');
								else if (this.previousSibling.previousSibling && this.previousSibling.previousSibling.nodeName=='LI')
									this.previousSibling.previousSibling.className = this.previousSibling.previousSibling.className.replace(' prev','');
							}
							
							/* 1/7/11 Fix of the alignment of the last drop down, makes sure the last li has the 'last' class -Adrian */
							var last = this.parentNode.lastChild;
							while(last.nodeType != 1)
							{
								last = last.previousSibling;
							}
							last.className = "last";	
							//**********************************************						
								 
						}
						//onclick *********************************Fix drop down not resetting*****************************
						node.onclick= function ()  { 
							this.className = '';
							//this.className = this.className.replace(' hover',''); 
							if (this.previousSibling) {
								if (this.previousSibling.nodeName=='LI') this.previousSibling.className =this.previousSibling.className.replace(' prev','');
								else if (this.previousSibling.previousSibling && this.previousSibling.previousSibling.nodeName=='LI')
									this.previousSibling.previousSibling.className = this.previousSibling.previousSibling.className.replace(' prev',''); 
							}
						}
						//*************************************************************************************************/
					}
				} // end of for loop for child nodes
			}			
		}
		var divs = document.getElementsByTagName("div");
		for (i=0; i < divs.length; i++) {
			if (divs[i].className.indexOf('dynhover')>=0) {
				divs[i].onmouseover= function() {
					this.className += ' hover';
				}
				//mouseout
				divs[i].onmouseout= function ()  { 
					this.className = this.className.replace(' hover',''); 
				}
			}
		}
	}
/****************************	END HOVER SCRIPT	*********************************/







/**************************************************************************************
******							CLEAR SEARCH JAVASCRIPT							 ******
**************************************************************************************/
	function clearSearch() {
		document.getElementById('search_input').value = '';
	}
/***************************** 	END SEARCH SCRIPT	**********************************/








/**************************************************************************************
******						GOOGLE ANALYTICS JAVASCRIPT							 ******
**************************************************************************************/
	function googleAnalytic() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	  }
/***************************** 	END GOOGLE SCRIPT	**********************************/




// Function that runs when page is loading, Calls all the functions needed to Initialize a page
(function() {
	// Initialize the Search Box
	document.getElementById('search_input').value="SEARCH";
	
	// Call the Hover Script
	hoverInit();
	
	// Call Dropshadow Script
	shadowInit();
	
	// Initialize and call Google Script
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-9447881-1']);
	_gaq.push(['_trackPageview']);
	googleAnalytic();
})();
