/*

	Javascript class to setup various utility methods
	
	Event observer watches for full page and DOM load
	Once DOM is available, write header and footer objects
	to their DIVs
	
	Trace function plugs into firebug in firefox...for development only
	
	setupDropDown code addes highlights to menu items with submenus
	code deploys listeners on navigation LIs and toggles the classname'over'
	
	required code at the bottom of file instantiates the utility class
	
	This setup keeps js code OUT of markup.
	
*/


var Utility = Class.create({
	initialize: function(){
		this.trace("Javascript loaded.");
		
		Event.observe(window, 'load', this.loaded.bind(this));
		
	},
	loaded: function(){
		this.trace('DOM loaded and available.');
		//$('body').hide();
		// Hides body until header and footer are included and dropdown initialized
		
		/*
				Javascript includes are located in the includes.js file
				they are Javascript objects with a content property containing
				an HTML string.
		*/
		
			// insert footer markup into document
			$('footer').innerHTML = footer.content;
		
			// insert header markup into document
			$('header').innerHTML = header.content;
		
		/*		End include section		*/
		
		// setup dropdown menu behavior
		this.setupDropDown();
		
		// Shows the new body
		$('body').removeClassName('hidebody');
	},
	
	// This function is used for development only
	trace: function($message){
		if (!Prototype.Browser.IE) {
			// Comment out this line for production
			//if (("console" in window) || ("firebug" in console)) console.log($message);
		}
	},
	setupDropDown: function(){
		
		$$('#navigation ul>li').each(function(node, i){
		 		if(node.down().next() != null) {
					node.down().addClassName('hasSubmenu');
				}
		 });
		
		
		$$("#navigation ul>li>a").each(function(node, i){
			node.onmouseover = node.onmouseout = function(){
				node.toggleClassName('anchor_hover');
			}
		});
		
		$$("#navigation li").each(function(node, i){
			//node.cleanWhitespace();
			// if there’s a ul
			var ul = node.down().next();//$A(node.getElementsByTagName("ul")).first();
			if(ul != null){
					// toggle it’s visibility on these events
					node.onmouseover = node.onmouseout = function(){
						ul.toggleClassName('over');
					}
			}
			
			
		});
		
	}
});


util = new Utility()