
	/*
	JS
	--------------------------------------------------------------------------------------------
	@site				sho.com/site
	@project			sho (970)
	@package			common	
	@file				Navigation
	@modified			08.06.09
	@author				dpaul
	@desc			 	Helper for the global navigation on sho.com
	@note				Inspired by the original suckerfish dropdown article on alistapart,
	@note				and by Peter Slagter's Protofish implementation (http://protofish.procurios.nl)
	@depend				prototype
	
	/* =:GlobalNav
	--------------------------------------------------------------------------------------------*/
	namespace("sho.common");
	
	sho.common.Navigation = Class.create({
		
		id:'nav-sho',
		nav:null,
		items:null,
		klass:'hover',
		queue:[],
		timeout:0.4,
		
		/* =:Startup
		---------------------------------------------------------------------------------------*/
		initialize:function()
		{
		    if(!$(this.id)) return;
		    
			this.nav = $(this.id)
			this.items = this.nav.select('li');
			this.setHandlers();
		},
		
		setHandlers:function()
		{
			var th = this;
			this.items.each(function(i){
				i.observe('mouseover', (function(e){ th.over(i); }).bind(th));
				i.observe('mouseout', (function(e){ th.out(i); }).bind(th));
			});
		},
		
		/* =:Runtime
		---------------------------------------------------------------------------------------*/
		over:function(i)
		{
			i.addClassName(this.klass);
			
			while (this.queue.length) 
			{
				clearTimeout(this.queue[0][0]);
				this.release();
			}
		},
		
		out:function(i)
		{
			var rel = this.release.bind(this)
			this.queue.push([rel.delay(this.timeout),i]);
		},
		
		release:function()
		{
			if(this.queue.length)
			{
				var item = this.queue.shift()[1];
				item.removeClassName(this.klass);
			}
		}
		
		
	});
	
	/* Add to onload stack */
	document.observe('dom:loaded', function(){ new sho.common.Navigation(); });
	
	/* No surrender, No delete */
