var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

addLoadListener(function() { CreateMenu();});

var branch;
function addLoadListener(fn)
{
	if(typeof window.addEventListener != 'undefined')
	{
		window.addEventListener('load',fn,false);
	}
	else if (typeof document.addEventListener != 'undefined')
	{
		document.addEventListener('load',fnn, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', fn);
	}
	else
	{
		var oldfn = window.onload;
		if(typeof window.onload != 'function')
		{
			window.onload = fn;
		}
		else
		{
			window.onload = function()
			{
				oldfn();
				fn();
			};
		}
	}
}

function attachEventListener(target, eventType, functionRef, capture)
{
	if(typeof target.addEventListener != "undefined")
	{
		target.addEventListener(eventType, functionRef, capture);
	}
	else if (typeof target.attachEvent != "undefined")
	{
		target.attachEvent("on" + eventType, functionRef);
	}
	else
	{
		eventType = "on" + eventType;
		
		if(typeof target[eventype] == "function")
		{
			var oldListener = target[eventType];
			
			target[eventType] = function()
			{
				oldListener();
				
				return functionRef();
			};
		}
		else
		{
			target[eventType] = functionRef;
		}
	}
}

function CreateMenu()
{
	var strHref = readAddBar();
	if(strHref == 'productdisplay')
	{
		var dispL = 'MenuList';
		var dispVals = '';
		var Count = 1;
		var dynamicMU = '';
		var dynamicFMU = '';
		var currCat = '';
		currCat = getURLParam('Category').toUpperCase();
		//dynamicMU += '<ul>';
		//dynamicFMU += '<ul>';
		for(var i=1;i<=NumFirstLvlItems;i++)
		{
			Count = i;
			dispL = 'MenuList' + i;
			dispVals = window[dispL.split(',')];
			NumSubs1 = dispVals[1];
			if(currCat.indexOf(dispVals[2]) > -1)
			{
				if(dispVals[2].indexOf('SX99') < 0)
				{
					if(NumSubs1 > 0)
					{
						dynamicMU += '<p class="menu_head" id="CurrentHeaderCat"><a href="#" class="CurrCat">' + dispVals[0] + '</a></p>';
						dynamicMU = CreateListItems3(Count, dynamicMU, NumSubs1,dispL,currCat);
						//dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + getFirstChildCat(dispL) + '&PageProduct=1" class="CurrCat">' + dispVals[0] + '</a></li>';		
						
					}
					else
						dynamicMU += '<p class="menu_head"><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1" class="CurrCat">' + dispVals[0] + '</a></p>';
						//dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1" class="CurrCat">' + dispVals[0] + '</a></li>';
				}
			}
			else
			{
				/*if(dispVals[2].indexOf('SX99') < 0)
				{
					if(NumSubs1 > 0)
						dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + getFirstChildCat(dispL) + '&PageProduct=1">' + dispVals[0] + '</a></li>';		
					else
						dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1">' + dispVals[0] + '</a></li>';
				}*/
				if(dispVals[2].indexOf('SX99') < 0)
				{
					if(NumSubs1 > 0)
					{
						dynamicMU += '<p class="menu_head"><a href="#">' + dispVals[0] + '</a></p>';
						//dispL = dispL.slice(0,(StrEnd+1));
						dynamicMU = CreateListItems2(Count, dynamicMU, NumSubs1,dispL);
						//var StrEnd = dispL.lastIndexOf("_");
						//dispL = dispL.slice(0,StrEnd);
						//dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + getFirstChildCat(dispL) + '&PageProduct=1">' + dispVals[0] + '</a></li>';		
					}
					else
						dynamicMU += '<p class="menu_head"><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1">' + dispVals[0] + '</a></p>'
						//dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1">' + dispVals[0] + '</a></li>';
				}
			}
		}
		//dynamicMU += '</ul>';
		//dynamicFMU += '</ul></div>';
		//alert(dynamicMU);
		try
		{
			var insHTML = document.getElementById('pli');
			if(saf)
			{
				insHTML.innerHTML=dynamicMU;
			}
			else
			{
				insHTML.insertAdjacentHTML('beforeEnd',dynamicMU);
			}
			setCurrentCat();
			setCurrentCatTab(currCat);
		}
		catch(err){}
		//dropdownMenu('navigation');
		dropdownMenu2('pli');
		//var insFHTML = document.getElementById('footercats');
		//if(insFHTML)
		//{
		//	insFHTML.getElementById('yellowbox2').innerHTML = dynamicFMU;	
		//}
	}
	else
	{
		document.getElementById('LeftSideNav').style.display = 'none';
		CreateFMenu();
		setNewProductsLink();
	}
	return;
}
function CreateListItems3(itemNum, dynamicMU, NumSubs,dispL,currCat)
{
	var dispVals;
	dynamicMU += '<div class="menu_body">';
	dynamicMU += '<ul>';
	for(var i=1;i<=NumSubs;i++)
	{
		dispL += '_' + i;
		dispVals = window[dispL.split(',')];
		var StrEnd = dispL.lastIndexOf("_");
		if(currCat.indexOf(dispVals[2]) > -1)
		{
			if(dispVals[1]==0)
			{
				dynamicMU += '<li><a class="CurrCat" href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1"><span>' + toProperCase(dispVals[0]) + '</span></a></li>';
			}
			else
			{
				dynamicMU += '<li><a class="CurrCat" href="ProductDisplay.aspx?category=' + getFirstChildCat(dispL) + '&PageProduct=1"><span>' + toProperCase(dispVals[0]) + '</span></a></li>';
			}
		}
		else
		{
			if(dispVals[1]==0)
			{
				dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1"><span>' + toProperCase(dispVals[0]) + '</span></a></li>';
			}
			else
			{
				dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + getFirstChildCat(dispL) + '&PageProduct=1"><span>' + toProperCase(dispVals[0]) + '</span></a></li>';
			}
		}
		dispL = dispL.slice(0,StrEnd);
	}
	dynamicMU += '</ul></div>';
	return dynamicMU;
}
function CreateListItems2(itemNum, dynamicMU, NumSubs,dispL)
{
	//dispL += itemNum;
	//alert(dispL);
	var dispVals;
	dynamicMU += '<div class="menu_body">';
	dynamicMU += '<ul>';
	/*<li><a href="#"><span>Roller Wringer Buckets & Parts</span></a></li>
                        <li><a href="#"><span>Ergo Buckets and Press Wringers</span></a></li>
                        <li><a href="#"><span>Plastic Buckets</span></a></li>
	*/
	for(var i=1;i<=NumSubs;i++)
	{
		dispL += '_' + i;
		dispVals = window[dispL.split(',')];
		//alert(dispL + ' ' + toProperCase(dispVals[0]));
		var StrEnd = dispL.lastIndexOf("_");
		if(dispVals[1]==0)
		{
			dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1"><span>' + toProperCase(dispVals[0]) + '</span></a></li>';
			//dispL = dispL.slice(0,StrEnd);
		}
		else
		{
			dynamicMU += '<li><a href="ProductDisplay.aspx?category=' + getFirstChildCat(dispL) + '&PageProduct=1"><span>' + toProperCase(dispVals[0]) + '</span></a></li>';
		//	dynamicMU += '<ul>';
		//	dispL = dispL.slice(0,(StrEnd+1));
		//	dynamicMU = CreateListItems(i,dynamicMU,dispVals[1],dispL);
		//	var StrEnd = dispL.lastIndexOf("_");
		//	dispL = dispL.slice(0,StrEnd);
		//	dynamicMU += '</ul></li>';
		}
		dispL = dispL.slice(0,StrEnd);
	}
	dynamicMU += '</ul></div>';
	return dynamicMU;
}
function CreateFMenu()
{
	var insFHTML = document.getElementById('footercats');
	var insLHTML = document.getElementById('makehome');
	if(insFHTML || insLHTML)
	{
		var dispL = 'MenuList';
		var dispVals = '';
		var Count = 1;
		//var dynamicMU = '';
		var dynamicFMU = '';
		dynamicFMU += '<ul>';
		for(var i=1;i<=NumFirstLvlItems;i++)
		{
			Count = i;
			dispL = 'MenuList' + i;
			dispVals = window[dispL.split(',')];
			NumSubs1 = dispVals[1];
			//dynamicFMU += '<li><a href="ProductBrowse.aspx?category=' + dispVals[2] + '">' + dispVals[0] + '</a></li>';
			if(dispVals[2].indexOf('SX99') < 0)
			{
				if(NumSubs1 > 0)
					dynamicFMU += '<li><a href="ProductDisplay.aspx?category=' + getFirstChildCat(dispL) + '&PageProduct=1">' + dispVals[0] + '</a></li>';		
				else
					dynamicFMU += '<li><a href="ProductDisplay.aspx?category=' + dispVals[2] + '&PageProduct=1">' + dispVals[0] + '</a></li>';
			}
		}
		dynamicFMU += '</ul>';
		if(insFHTML)
			document.getElementById('yellowbox2').innerHTML = dynamicFMU;
		if(insLHTML)
		{
			var nDiv1 = document.createElement('div');
			nDiv1.id = 'footercats';
			var nDiv2 = document.createElement('div');
			nDiv2.id = 'yellowbox1';
			var nDiv3 = document.createElement('div');
			nDiv3.id = 'yellowbox2';
			var nDiv4 = document.createElement('div');
			nDiv4.id = 'yellowbox3';
			nDiv3.innerHTML = dynamicFMU;
			nDiv1.appendChild(nDiv2);
			nDiv1.appendChild(nDiv3);
			nDiv1.appendChild(nDiv4);
			insLHTML.parentNode.appendChild(nDiv1);
		}
	}
	return;
}
function getFirstChildCat(dispL)
{
	return (window[(dispL+'_1').split(',')][2])
}
function setCurrentCat()
{
	try
	{
		//document.getElementById(getURLParam('Category').toUpperCase()).className = 'stab';
		//alert('here');
		$(document.getElementById("CurrentHeaderCat")).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
		//$(p).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
	}
	catch(err)
	{
/*		
		txt="There was an error on this page.\n\n";
		txt+="Error description: " + err.description + "\n\n";
		txt+="Click OK to continue.\n\n";
		alert(txt);
*/
	}
}
function setCurrentCatTab(currCat)
{
	try
	{
		if(document.getElementById(currCat))
		{
			document.getElementById(currCat).style.background = '#FFFFFF url(../../images/TemplateImages/tabbg_grey.gif) repeat-x 0px 0px';
		}
	}
	catch(err){}
}
function replaceWhiteSpace(str)
{
	return(str.replace(/ /g, "&nbsp;"));
}
function openProductDisplay()
{
	dispL = 'MenuList1';
	dispVals = window[dispL.split(',')];
	if(dispVals[1] > 0)
		window.location.href = "ProductDisplay.aspx?category="+ getFirstChildCat(dispL) + '&PageProduct=1';
	else
		window.location.href = "ProductDisplay.aspx?category="+ dispVals[2] + '&PageProduct=1';
}
function CreateListItems(itemNum, dynamicMU, NumSubs,dispL)
{
	dispL += itemNum;
	var dispVals;
	for(var i=1;i<=NumSubs;i++)
	{
		dispL += '_' + i;
		dispVals = window[dispL.split(',')];
		dynamicMU += '<li><a href="ProductBrowse.aspx?category=' + dispVals[2] + '">' + toProperCase(dispVals[0]) + '</a>';
		var StrEnd = dispL.lastIndexOf("_");
		if(dispVals[1]==0)
		{
			dynamicMU += '</li>';
			dispL = dispL.slice(0,StrEnd);
		}
		else
		{
			dynamicMU += '<ul>';
			dispL = dispL.slice(0,(StrEnd+1));
			dynamicMU = CreateListItems(i,dynamicMU,dispVals[1],dispL);
			var StrEnd = dispL.lastIndexOf("_");
			dispL = dispL.slice(0,StrEnd);
			dynamicMU += '</ul></li>';
		}
	}
	return dynamicMU;
}
function toProperCase(s)
{
  return s.toLowerCase().replace(/^(.)|\s(.)/g, 
          function($1) { return $1.toUpperCase(); });
}
function dropdownMenu2(navid)
{
	var isie = (typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE');
	if (typeof document.getElementById == 'undefined' || (navigator.vendor == 'Apple Computer, Inc.' && typeof window.XMLHttpRequest == 'undefined') || (isie && typeof document.uniqueID == 'undefined'))
	{
		return;	
	}
	
	//var rollover = new Image;
	//rollover.src = 'images/right_black.gif';
	
	var tree = document.getElementById('pli');
	if(saf)
	{
		var tree = document.getElementById('pli');
	}
	if(tree)
	{
		branch = tree;
		var items = document.getElementsByTagName('p');
		for (var i=0; i <items.length; i++)
		{
			//dropdownTrigger2(tree, items[i],navid,isie);
			dropdownTrigger3(items[i]);
		}
	}
}
function dropdownMenu(navid)
{
	var isie = (typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE');
	if (typeof document.getElementById == 'undefined' || (navigator.vendor == 'Apple Computer, Inc.' && typeof window.XMLHttpRequest == 'undefined') || (isie && typeof document.uniqueID == 'undefined'))
	{
		return;	
	}
	
	var rollover = new Image;
	//rollover.src = 'images/right_black.gif';
	
	var tree = document.getElementById('navigation');
	if(saf)
	{
		var tree = document.getElementById('CatMenu');
	}
	if(tree)
	{
		branch = tree;
		var items = document.getElementsByTagName('li');
		for (var i=0; i <items.length; i++)
		{
			dropdownTrigger(tree, items[i],navid,isie);	
		}
	}
}
function dropdownTrigger3(p)
{
	attachEventListener(p,'click',function(e)
	{
		//$(this).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
		$(p).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
	},false);
}
function dropdownTrigger2(tree, p, navid, isie)
{
	attachEventListener(p,'mouseover',function(e)
	{
		//$(this).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
		$(p).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
	},false);
}
function dropdownTrigger(tree, li, navid, isie)
{
	var opentime, closetime;
	var a = li.getElementsByTagName('a').length >0 ? li.getElementsByTagName('a')[0] : null;
	var menu = li.getElementsByTagName('ul').length > 0 ? li.getElementsByTagName('ul')[0] : null;
	var horiz = tree.className.indexOf('horizontal') != -1;
	var issub = li.parentNode.id == navid;
	if(menu)
	{
		li.className += (li.className == '' ? '' : ' ') + 'hasmenu';
	}
	attachEventListener(li,'mouseover',function(e)
	{
		if (unwantedTextEvent()){return;}
		clearTimeout(closetime);
		if (branch == li){ branch = null; }
		if(a){
		a.className += (a.className == '' ? '' : ' ') + 'rollover';
			if(menu)
			{
				opentime = window.setTimeout(function()
				{
					if(branch)
					{
						clearMenus(branch);
						branch = null;
					}
					menu.style.left = horiz ? (isie ? li.offsetLeft + 'px' : 'auto') : '0';
					menu.style.top = horiz && issub ? (isie ? a.offsetHeight + 'px' : 'auto') : (isie ? li.offsetTop + 'px' : '0');
					if(saf)
					{
						menu.style.left = horiz ? 'auto' : '0';
						menu.style.top = horiz ? 'auto' : '0';
					}
				},50);
			}
		}
	},false);
	attachEventListener(li, 'mouseout', function(e)
	{
		if (unwantedTextEvent()){return;}
		var related = typeof e.relatedTarget != 'undefined' ? e.relatedTarget : e.toElement;
		if(!li.contains(related))
		{
			clearTimeout(opentime);
			branch = li;
			if(a){
			a.className = a.className.replace(/ ?rollover/g, '');
				if(menu)
				{
					closetime = window.setTimeout(function()
					{
						if(saf)
						{
							menu.style.display='none';
						}
						else
						{
							menu.style.left='-200em';
						}
					},300);
				}
			}
		}
	}, false);
	
	if(!isie)
	{
		li.contains = function(node)
		{
			if (node == null){ return false; }
			if (node == this){ return true; }
			else { return this.contains(node.parentNode); }
		};
	}
}

function clearMenus(root)
{
	var menus = root.getElementsByTagName('ul');
	for (var i = 0; i < menus.length; i++)
	{
		menus[i].style.left =  '-200em';
	}
}

function unwantedTextEvent()
{
	return (navigator.vendor == 'Apple Computer, Inc.' && (event.target == event.relatedTarget.parentNode || (event.eventPhase == 3 && event.target.parentNode == event.relatedTarget)));
};

function readAddBar()
{
	var myVar = self.location.toString();
	var pgname = myVar.substr(myVar.lastIndexOf('/')+1,(myVar.lastIndexOf('.')-myVar.lastIndexOf('/')-1));
	return(pgname.toLowerCase());
}
function setNewProductsLink()
{
	var newProdsLink = document.getElementById('HomePageNewProds');
	if(newProdsLink)
	{
		if( typeof( window[ 'Menu2_2' ] ) != "undefined" )
		{
			if(Menu2_2[0].indexOf('New Products') > -1)
				newProdsLink.style.visibility = 'visible';
		}
	}
}


