//END toggle FUNCTION
var varProtocol = (("https:" == document.location.protocol) ? "https://" : "http://");
var Navs=new Array("contact");

var areaHolder

	for (var i=0;i<Navs.length;i++){
		if(!document.getElementById('subnav_'+Navs[i])){
			alert('subnav_'+Navs[i]+' does not exist');	
		}
	}

function setNav(area){
var e3 = document.getElementById('nav_'+area);
e3.className = 'navon';
areaHolder='nav_'+area;
//alert('nav_'+area);
}

function closeSubnavs(obj){
	for (var i=0;i<Navs.length;i++){
		if('subnav_'+Navs[i] != obj){
			var e2 = document.getElementById('subnav_'+Navs[i]);
			e2.style.display = 'none';
			
			//var e3 = document.getElementById('nav_'+Navs[i]);
			//e3.className = 'navoff';
		}
	}
}

function checkClasses(){
	var x=0;
	for (var i=0;i<Navs.length;i++){	
		var e3 = document.getElementById('nav_'+Navs[i]);
		//debug(e3.className);
		if(e3.className != 't12w nav navoff'){
			x++;
		}
	}
	/*if(x==0){
		document.getElementById(areaHolder).className='t12 nav navon';
		document.getElementById(areaHolder+'_img').src='newHeaderNavDropDown2.png';
	}*/
}

function toggle2(obj,x) {
	if (document.getElementById(obj)){
		if ( x==1 ) {
			closeSubnavs(obj);
			document.getElementById(obj).style.display = 'inline';
			document.getElementById(obj.replace(/subnav_/,'nav_')).className = 'A16b noUL';
			//document.getElementById(obj.replace(/subnav_/,'nav_')).style.cursor='pointer';
		//document.getElementById(obj.replace(/subnav_/,'nav_')+'_img').src=varProtocol+'newHeaderNavDropDown2.png';
		} else {
			document.getElementById(obj).style.display = 'none';
			document.getElementById(obj.replace(/subnav_/,'nav_')).className = 'A16w noUL';
		//document.getElementById(obj.replace(/subnav_/,'nav_')+'_img').src=varProtocol+'newHeaderNavDropDown.png';
		}
	}
}

function toggle3(obj,x) {
	if (document.getElementById(obj)){
		if ( x==1 ) {
			//closeSubnavs(obj);
			document.getElementById(obj).style.display = 'inline';
			document.getElementById(obj.replace(/subnav_/,'nav_')).className = 'navLink2 AG12';
			//document.getElementById(obj.replace(/subnav_/,'nav_')).style.cursor='pointer';
		} else {
			document.getElementById(obj).style.display = 'none';
			document.getElementById(obj.replace(/subnav_/,'nav_')).className = 'AG12';
		}
	}
}

function addEvent( obj, evt, fn )
{
    if ( typeof obj.addEventListener != undefined )
    {
        obj.addEventListener( evt, fn, false );
    }
    else if ( typeof obj.attachEvent != undefined )
    {
        obj.attachEvent( "on" + evt, fn );
    }
}

var Event = {
	add: function(obj,type,fn) {
		if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn](window.event); }
			obj.attachEvent('on'+type,obj[type+fn]);
		} else
		obj.addEventListener(type,fn,false);
	},
	remove: function(obj,type,fn) {
		if (obj.detachEvent) {
			obj.detachEvent('on'+type,obj[type+fn]);
			obj[type+fn] = null;
		} else
		obj.removeEventListener(type,fn,false);
	}
}


var HoverListener = {
	addElem: function( elem, callback, delay )
	{
		if ( delay === undefined )
			{
				delay = 1000;
			}
		var hoverTimer;
		Event.add( elem, 'mouseover', function()
			{
				hoverTimer = setTimeout( callback, delay );
			} 
		);
		Event.add( elem, 'mouseout', function()
			{
				clearTimeout( hoverTimer );
			} 
		);
	}
}

var HoverListener2 = {
	addElem: function( elem, callback, delay )
	{
		if ( delay === undefined )
			{
				delay = 1000;
			}
		var hoverTimer;
		
		Event.add( document.getElementById('subnav_'+elem), 'mouseover', function()
			{
				clearTimeout( hoverTimer );
			} 
		);
		
		Event.add( document.getElementById('subnav_'+elem), 'mouseout', function()
			{
				hoverTimer = setTimeout( callback, delay );
			} 
		);
		
		Event.add( document.getElementById('nav_'+elem), 'mouseover', function()
			{
				clearTimeout( hoverTimer );
			} 
		);
		
		Event.add( document.getElementById('nav_'+elem), 'mouseout', function()
			{
				hoverTimer = setTimeout( callback, delay );
			} 
		);
	}
}

Event.add( window, 'load', function()
{
		HoverListener.addElem( document.getElementById( 'nav_contact' ), function(){ toggle2('subnav_contact',1); }, 400 );	
		HoverListener2.addElem('contact', function(){ toggle2('subnav_contact',0);checkClasses(); }, 500 );	
		
		/*HoverListener.addElem( document.getElementById( 'nav_replacements' ), function(){ toggle2('subnav_replacements',1); }, 400 );	
		HoverListener2.addElem('replacements', function(){ toggle2('subnav_replacements',0);checkClasses(); }, 500 );	

		HoverListener.addElem( document.getElementById( 'nav_parts' ), function(){ toggle2('subnav_parts',1); }, 400 );	
		HoverListener2.addElem( 'parts' , function(){ toggle2('subnav_parts',0);checkClasses(); }, 500 );	

		HoverListener.addElem( document.getElementById( 'nav_brands' ), function(){ toggle2('subnav_brands',1); }, 400 );	
		HoverListener2.addElem( 'brands' , function(){ toggle2('subnav_brands',0);checkClasses(); }, 500 );	

		HoverListener.addElem( document.getElementById( 'nav_contaminants' ), function(){ toggle2('subnav_contaminants',1); }, 400 );	
		HoverListener2.addElem( 'contaminants' , function(){ toggle2('subnav_contaminants',0);checkClasses(); }, 500 );	

		HoverListener.addElem( document.getElementById( 'nav_application' ), function(){ toggle2('subnav_application',1); }, 400 );	
		HoverListener2.addElem( 'application' , function(){ toggle2('subnav_application',0);checkClasses(); }, 500 );	
				
		HoverListener.addElem( document.getElementById( 'nav_university' ), function(){ toggle2('subnav_university',1); }, 400 );			
		HoverListener2.addElem( 'university' , function(){ toggle2('subnav_university',0);checkClasses(); }, 500 );	
		
		HoverListener.addElem( document.getElementById( 'nav_cservice' ), function(){ toggle2('subnav_cservice',1); }, 100 );			
		HoverListener2.addElem( 'cservice' , function(){ toggle2('subnav_cservice',0);checkClasses(); }, 500 );	
		
		Event.add( document.getElementById('nav_systems'), 'click', function()
			{
				document.location.href='/';
			} 
		);
		Event.add( document.getElementById('nav_replacements'), 'click', function()
			{
				document.location.href='/office-furniture.asp';
			} 
		);
		Event.add( document.getElementById('nav_parts'), 'click', function()
			{
				document.location.href='http://www.waterfilters.net/Parts-Accessories/Parts-Accessories.htm';
			} 
		);
		Event.add( document.getElementById('nav_brands'), 'click', function()
			{
				document.location.href='http://www.waterfilters.net/Water-Filter-Brands_c_160.html';
			} 
		);
		Event.add( document.getElementById('nav_contaminants'), 'click', function()
			{
				document.location.href='http://www.waterfilters.net/Water-Filters-by-Contaminant_c_126.html';
			} 
		);
		Event.add( document.getElementById('nav_application'), 'click', function()
			{
				document.location.href='http://www.waterfilters.net/Water-Filters-by-Contaminant_c_126.html';
			} 
		);
		Event.add( document.getElementById('nav_university'), 'click', function()
			{
				document.location.href='http://www.waterfilters.net/Water-University_ep_36-1.html';
			} 
		);
		Event.add( document.getElementById('nav_cservice'), 'click', function()
			{
				document.location.href='http://www.waterfilters.net/Customer-Service_ep_31.html';
			} 
		);*/
		
} );

