/*
// Drop down controls
*/

var navControl = {
	init: function() {
	
		// This is to keep the main section headers highlighted as you hover over the sub items below
		$$('.listitem').each(function(el) {
				Event.observe(el, 'mouseover', navControl.makeActive.bindAsEventListener(el), true);
				Event.observe(el, 'mouseout', navControl.makeNormal.bindAsEventListener(el), true);
			});	
		// This is for all of the topnav drop down effects
		if ($('account') != undefined) {
			new Event.observe('account', 'mouseover', navControl.showAccount);
			new Event.observe('account', 'mouseout', navControl.hideAccount);
		}
		new Event.observe('location', 'mouseover', navControl.showLocation);
		new Event.observe('location', 'mouseout', navControl.hideLocation);
		
		if ($('saveshare') != undefined) {
		    new Event.observe('saveshare', 'mouseover', navControl.showSaveshare);
		    new Event.observe('saveshare', 'mouseout', navControl.hideSaveshare);
		}
		
		var personalization = $('personalization');
		var fname = $('fname');
		var nm = Cookie.get("fname");
		if( nm != null ) {
			fname.appendChild( document.createTextNode( nm ) );
			personalization.style.display = "inline";
		}
		
		var logoff = $('logoff');
		if( logoff ) {
			logoff.onclick = navControl.logoff.bindAsEventListener( this );
		}
		
		var print = $('printpage');
		if( print ) {
			print.onclick = navControl.print.bindAsEventListener( this );
		}
	}, 
	makeActive: function() {
		var anchorTag = this.down('a');
		anchorTag.addClassName('activetoggle');
	}, 
	makeNormal: function() {
		var anchorTag = this.down('a');
		anchorTag.removeClassName('activetoggle');
	},
	showCart: function() {
		$('cartmenu').setStyle({display: 'block'});	
	}, 
	hideCart: function() {
		$('cartmenu').setStyle({display: 'none'});
	}, 
	showAccount: function() {
		$('accountmenu').setStyle({display: 'block'});
	}, 
	hideAccount: function() {
		$('accountmenu').setStyle({display: 'none'});
	}, 
	showLocation: function() {
		$('locationmenu').setStyle({display: 'block'});
	}, 
	hideLocation: function() {
		$('locationmenu').setStyle({display: 'none'});
	},
	showSaveshare: function() {
		$('sscontent').setStyle({display: 'block'});
	}, 
	hideSaveshare: function() {
		$('sscontent').setStyle({display: 'none'});
	},
	localize: function( input ) {
		return function(e) {
			Cookie.set("localZip", $F(input));
			navControl.hideLocation();
		}
	},
	logoff: function(e) {
		Cookie.erase("fname");
	},
	print: function(e) {
		Event.stop(e);
		window.print();
	}
}
	
Event.observe(window, 'load', navControl.init);

