// JavaScript Document


function waldenDropdown ( menuId)
	{
	this.hover = function ( closure )
		{
		// if the function is called with a parameter then we return a closure for use in event handlers
		if( closure )
			{
			return (function() {thisObj.hover();});		
			}
			
		this.menuList.style.display = "block";
		}
		
	this.mouseout = function ( closure )
		{
		// if the function is called with a parameter then we return a closure for use in event handlers
		if( closure )
			{
			return (function() {thisObj.mouseout();});		
			}
		
		this.menuList.style.display = "none";
		}
	
	// grab the div tag that contains the menu and store it as a property of this object
	this.menuDiv = document.getElementById( menuId );
	
	// find the UL that contains the actual drop-down and assign it to a property of this object
	this.menuList = this.menuDiv.childNodes[2];
	if( this.menuList.nodeType != 1 )
		{
		this.menuList = this.menuDiv.childNodes[3];
		}
	
	// hide the dropdown menus
	this.mouseout();
	
	// declare a static, local instance of THIS for later use
	var thisObj = this;
	}


function getElementsByClassName(classname, node) 
	{
	if( !node ) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for( var i=0,j=els.length; i<j; i++ )
		{
		if( re.test(els[i].className )) 
			{
			a.push(els[i]);
			}
		}
	return a;
	}

function init ()
	{
	menus = getElementsByClassName( "walden_dropdown" );
	for( x = 0, ArrayLength = menus.length; x < ArrayLength; x++ )
		{
		menus[x].waldenDropdownMenu = new waldenDropdown( menus[x].id );
		menus[x].onmouseover = menus[x].waldenDropdownMenu.hover( true );
		menus[x].onmouseout = menus[x].waldenDropdownMenu.mouseout( true );
		}
	}


window.onload = init;
