document.observe("dom:loaded", function() {

function drillDown(listItem) {
	listItem = $(listItem);
	listItem.stopObserving("click");
	listItem.addClassName("show-sub");
	listItem.removeClassName("hide-sub");
	if (listItem.down("ul ul")) {
		listItem.siblings().each(function(sibling) {
			sibling.removeClassName("show-sub");
			sibling.addClassName("hide");
			sibling.addClassName("hide-sub");
		});
	}
	listItem.observe("click", function(event) {
		event.stop();
		drillUp(listItem);
	});
}
function drillUp(listItem) {
	listItem = $(listItem);
	listItem.stopObserving("click");
	listItem.removeClassName("show-sub");
	listItem.addClassName("hide-sub");
	listItem.siblings().each(function(sibling) {
		sibling.removeClassName("hide");
	});
	listItem.observe("click", function(event) {
		event.stop();
		drillDown(listItem);
	});
}


$$("#product_nav li").each(function(li) {
	if (li.down("ul")) {
		li.addClassName("hide-sub");
		li.observe("click", function(event) {
			event.stop();
			drillDown(li);
		});
	} else {
		li.addClassName("no-sub");
	}
});
$$("#product_nav li a").each(function(link) {
	link.observe("click", function(event) {
		Event.extend(event);
		event.stopPropagation();
	});
})


var currentItem = /cat=(\d+)/i.exec(window.location.search || "");
if (!currentItem) currentItem = "cat_";
currentItem = "cat_" + currentItem[currentItem.index] || "cat_";
currentItem = document.getElementById(currentItem);

if (currentItem) {
	while (currentItem != document.getElementById("product_nav")) {
		if (currentItem.tagName.toLowerCase() == "li")
			drillDown(currentItem)
		currentItem = currentItem.parentNode;
	}
}

});