var rmenu;
var CurrentProduct = false;

Event.observe(window, 'load', function() {
	if (rmenu == 'contracted') {
		$$(".menu-categories dl  dd ul").each( function(el) {
			 el.hide();
		 });

		 $$(".menu-categories dl ul").each( function(el) {
			 el.hide();
		 });
		 
		 $$(".menu-categories dl dd").each( function(el) {
			 el.hide();
		 });
		 if (CurrentProduct) {
			expandMenu(CurrentProduct);
		}
	} else {
		if (CurrentProduct) {
			$(CurrentProduct).addClassName('currentProduct');
		}
	}
	
	
	$$(".menu-categories dl dd span").each( function(el) {
		Event.observe(el, 'click', function() {
			
			el.parentNode.immediateDescendants().each( function(childOfClicked) {
				if (childOfClicked.nodeName.toLowerCase() != 'span') childOfClicked.toggle();
			});
		
		}.bind(this));
	});
	
	$$(".menu-categories dl dt").each( function(el) {
		Event.observe(el, 'click', function() {
			var done = false;
			el.nextSiblings().each( function (n){
				if (n.nodeName.toLowerCase() == 'dt') {
					done = true; //stop hiding stuff if you hit the next dt node.
				}
				if (!done) {
					n.toggle();
				}
			}.bind(this));
		}.bind(this));
	});

});

function expandMenu(pid) {
	if (pid != 0) {
		$(pid).parentNode.show().parentNode.show();
		$(pid).addClassName('currentProduct');
		$(pid).parentNode.adjacent('.dd').each(function(el){el.show();});
		var done = false;
		$(pid).parentNode.parentNode.nextSiblings().each( function (n){
			if (n.nodeName.toLowerCase() == 'dt') {
				done = true; //stop hiding stuff if you hit the next dt node.
			}
			if (!done) {
				n.toggle();
			}
		}.bind(this));
		done = false;
		$(pid).parentNode.parentNode.previousSiblings().each( function (n){
			if (n.nodeName.toLowerCase() == 'dt') {
				done = true; //stop hiding stuff if you hit the next dt node.
			}
			if (!done) {
				n.toggle();
			}
		}.bind(this));
	}
}


