/*=============================================================================

			 TITLE:		Simple Dropdown Menu Controller
 DESCRIPTION:		Creates a javascript object which maps to a simple, single-level
 								dropdown menu (typically implemented as an unordered list in HTML).
    MODIFIED:		2006.03.13
   AUTHOR(S): 	Graham Wheeler / NetMediaOne - www.netmediaone.com
		REQUIRES:		Prototype - conio.prototype.js ( www.conio.com )
								Yahoo! Core Namespace - YAHOO.core.js
								Yahoo! Event System - YAHOO.event.js

=============================================================================*/

//
//	GLOBAL VARIABLES
// 
var NMO_SIMPLE_MENU_COLLECTION = new Array(); 			// Holds references to each menu element
var NMO_SIMPLE_MENU_TIMER = "";											// Timer used by blurMenus()
var NMO_SIMPLE_MENU_HIDE_DELAY = 400;								// After menu loses focus, wait this number of milliseconds before firing clearNav()
var NMO_SIMPLE_MENU_FOCUS = "";											// Holds a reference to the focused navigation menu anchor
var NMO_SIMPLE_MENU_SHADOW_OPACITY = .25;						// 0 to 1 Where 0 = fully transparent(disabled) and 1 = solid
var NMO_SIMPLE_MENU_OFFSET = new Array( 0, 50);
var NMO_SIMPLE_MENU_SHADOWOFFSET = new Array( 5, 5 );

// Define class 
var NMOSimpleMenu = Class.create();

NMOSimpleMenu.prototype = {
	
	initialize: function( menuID, navID )
							{
								this.menu = $(menuID);
								this.nav = $(navID);
								//this.menuItems = document.getElementsBySelector( "#" + this.menu.id + " li" );
								this.menuLinks = document.getElementsBySelector( "#" + this.menu.id + " a" );
								this.menu.style.display = "none";
								
								// Bind mouse event handlers to menu structural components
								YAHOO.util.Event.addListener([this.nav, this.menu, this.menuLinks], "mouseover", this.focusNav, this, true);
								YAHOO.util.Event.addListener([this.nav, this.menu, this.menuLinks], "mouseout", this.blurNav, this, true);
							},
							
	focusNav: function(e, obj)
						{
							nmoClearMenus();	
							clearTimeout( NMO_SIMPLE_MENU_TIMER );
							NMO_SIMPLE_MENU_FOCUS = obj.nav.id;
							obj.render();				
						},
						
	blurNav: function(e, obj)
						{
							NMO_SIMPLE_MENU_FOCUS = "";
							clearTimeout( NMO_SIMPLE_MENU_TIMER );
							NMO_SIMPLE_MENU_TIMER = setTimeout( "nmoClearMenus()", NMO_SIMPLE_MENU_HIDE_DELAY );	
						},
									
	render: function()
					{
						this.menu.style.display = "block";

						if ( !hasClass( this.nav, "Hovered" ) )
						{
							addClass( this.nav, "Hovered" );
						}
						var curLeft = NMO_SIMPLE_MENU_OFFSET[0];
						var curTop = NMO_SIMPLE_MENU_OFFSET[1];
						var obj = this.nav;
						if ( obj.offsetParent )
						{
							while ( obj.offsetParent )
							{
								curLeft += obj.offsetLeft
								curTop += obj.offsetTop
								obj = obj.offsetParent;
							}
						}
						this.menu.style.left = curLeft + "px";
						this.menu.style.top = curTop + "px";

						if ( NMO_SIMPLE_MENU_SHADOW_OPACITY != 0 )
						{
							var shadow = $("menuDropShadow");
							shadow.style.width = parseInt( Element.getStyle( this.menu, "width") ) + 1 + "px";
							shadow.style.height = parseInt( this.menu.clientHeight ) + "px";
							shadow.style.left = ( curLeft + NMO_SIMPLE_MENU_SHADOWOFFSET[0] ) + "px";
							shadow.style.top = ( curTop + NMO_SIMPLE_MENU_SHADOWOFFSET[1] ) + "px";
							shadow.style.display = "block";
						}
						
						// Activate IFRAME shim to cover windowed widgets (SELECT, etc.)
						var shim = $("menuShim");
						shim.style.width = parseInt( Element.getStyle( this.menu, "width") ) + "px";
						shim.style.height = parseInt( this.menu.clientHeight ) + "px";
						shim.style.left = curLeft + "px";
						shim.style.top = curTop + "px";
						shim.style.display = "block";
					},
	
	hide: function()
				{
					this.menu.style.display = "none";
					if ( hasClass( this.nav, "Hovered" ) )
					{
						removeClass( this.nav, "Hovered" );
					}
				}
	
};

function nmoInitMenus()
{
//	NMO_SIMPLE_MENU_COLLECTION.push( new NMOSimpleMenu( "menuNeighborhoods", "navNeighborhoods" ) );
//	Element.setOpacity( "menuDropShadow", NMO_SIMPLE_MENU_SHADOW_OPACITY );
}


function nmoClearMenus()
{
	clearTimeout( NMO_SIMPLE_MENU_TIMER );
	$("menuDropShadow").style.display = "none";
	$("menuShim").style.display = "none";
	for ( i = 0; i < NMO_SIMPLE_MENU_COLLECTION.length; i++ )
	{
		menuItem = NMO_SIMPLE_MENU_COLLECTION[i];
		if ( NMO_SIMPLE_MENU_FOCUS == menuItem.nav.id )
		{
			menuItem.render();
		}
		else
		{
			menuItem.hide();
		}
	}
}

Event.observe( window, "load", nmoInitMenus, false );

