// various options for the left navigation menu
var VA = {
	closeSpeed : 200,
	fadeSpeed : 1000,
	subdir : [
		"custom-mfg-fabricating",
		"electrical-power-generation",
		"electronic-components",
		"hardware",
		"instruments-controls",
		"machinery-tools-supplies",
		"materials-handling",
		"metals-products",
		"plant-facility-equipment",
		"plastics-foam-rubber",
		"process-equipment",
		"misc"
	],
	closeOpts : {
		height:'hide',
		margin:'0px',
		padding:'0px'
	},
	// highlight menu item corresponding to current section of site
	highlightSubDirectory : function() {
		for (var i = 0; i < this.subdir.length; i++) {
			if (location.href.indexOf(this.subdir[i]) != -1) {
				$("#" + this.subdir[i]).addClass('defaultOpen');
				var c = $("#" + this.subdir[i]).next(".panelContent");
				c.addClass('defaultOpen2');
				c.children("ul").show();
				break;
			}
		}
	}
};
/*
TODO:
When I get the time, I need to move all of this CSS stuff to classes in a css file.
*/
$(document).ready(function(e){
	// disable script on homepage
	if (location.href.match(/(htm\/|industrysearchnetwork.com)(\/?index.htm)?$/))
		return;
	
	VA.highlightSubDirectory();
	
	// show the sub menu on a mouse click event
	$(".panelTab > a").click(function(evt){	
		evt.preventDefault();
		
		var c = $(this).parent().next(".panelContent").children("ul");
		
		// only take action on unopen menu items
		if (c.css('display') == 'none') {
			// clear styles from menu items, and hide
			$(".panelContent").css('background', '#fc3'); // the slide is too jarring if we keep it white!
			$(".panelTab").removeClass('defaultOpen');
			$(".panelContent").children('ul').animate(VA.closeOpts, VA.closeSpeed);
		
			// get new styles ready for clicked menu item
			$(this).parent().addClass('defaultOpen');
			c.parent().addClass('defaultOpen2');
			
			// a couple of IE specific adjustments
			$(".defaultOpen2").css('padding', '0px');
			if (c.parent().hasClass('defaultOpen2'))
				c.parent().css('padding', '8px 0px 2px 0px');
		
			// we made bgcolor yellow earlier, change it back to white
			c.parent().css('background','#fff');
			c.fadeIn(VA.fadeSpeed);
		} else {
			location = this.href;
		}
	});
});
