if(typeof aw == "undefined") var aw = new Object();
aw.SuckerFishNav = function(){};

aw.SuckerFishNav.prototype = {
	initialize:function(){
		this.navElement = "header-nav";
		this.timeout = null;
		this.checkForElement();
		this.cachedClearApply = this.bindMethod( this.clearHoverEvents );
		
		if( window.addEventListener ){
			window.addEventListener( "unload", this.cachedClearApply, false );
		} else if( window.attachEvent ){
			window.attachEvent( "onunload", this.cachedClearApply );
		}
	},
	addHoverFunctionality:function(){
		var items = document.getElementById(this.navElement).getElementsByTagName("LI");
		for( var i = 0; i < items.length; i++ ){
			if( items[i].addEventListener ){
				items[i].addEventListener( "mouseover", this.addHoverClass, false );
				items[i].addEventListener( "mouseout", this.remHoverClass, false );
			} else if( items[i].attachEvent ) {
				items[i].mouseoveradd = this.bindMethod( this.addHoverClass, items[i] );
				items[i].mouseoutrem = this.bindMethod( this.remHoverClass, items[i] );
				items[i].attachEvent( "onmouseover", items[i].mouseoveradd );
				items[i].attachEvent( "onmouseout", items[i].mouseoutrem );
			}
		}
	},
	addHoverClass:function(){
		setAttributeClass( this, "hn-hover", true );
	},
	remHoverClass:function(){
		removeFromClassAttribute( this, "hn-hover" );
	},
	checkForElement:function(){
		if( !document.getElementById(this.navElement) ){
			this.timeout = setTimeout( this.bindMethod(this.checkForElement), 300 );
		} else {
			clearTimeout( this.timeout );
			this.addHoverFunctionality();
		}
	},
	clearHoverEvents:function(){
		var items = document.getElementById(this.navElement).getElementsByTagName("LI");
		for( var i = 0; i < items.length; i++ ){
			if( items[i].removeEventListener ){
				items[i].removeEventListener( "mouseover", this.addHoverClass, false );
				items[i].removeEventListener( "mouseout", this.remHoverClass, false );
			} else if( items[i].detachEvent ) {
				items[i].detachEvent( "onmouseover", items[i].mouseoveradd );
				items[i].detachEvent( "onmouseout", items[i].mouseoutrem );
				items[i].mouseoveradd = null;
				items[i].mouseoutrem = null;
			}
		}
		
		if( window.removeEventListener ){
			window.removeEventListener( "unload", this.cachedClearApply, false );
		} else if( window.detachEvent ){
			window.detachEvent( "onunload", this.cachedClearApply );
		}
	}, 
	bindMethod:function( method, object ){
		var __method = method;
		var __object = (object) ? object : this;
		return function(){return __method.apply(__object);};
	}
};

var suckerfishover = new aw.SuckerFishNav();
suckerfishover.initialize();
