// JavaScript Document

var a, t, i, x, id, sublevel, pattern, label, newlabel, pos;
var subnav;
subnav = document.getElementById('subnav');

try {
	if (subnav && subnav.hasChildNodes) {
		subnav.li = subnav.getElementsByTagName('LI');
		subnav.links = {};
		
		subnav.unpick = function() {
			if (this.Picked) {
				this.Picked.className = this.Picked.className.replace(/(\s*)sel/g,"");
			}
			this.Picked = null;
		}

		if (subnav.li && subnav.li.length) {

			for (i=0; i<subnav.li.length; i++) {
				if (subnav.li.item(i).className.match(/sel/)) {
					subnav.Picked = subnav.li.item(i);
				}
				
				subnav.links[i] = subnav.li.item(i).getElementsByTagName('A').item(0);
				if (subnav.links[i]) {
					a = subnav.links[i];
					a.id = a.getAttribute('item');

					if (a.id) {
						// init link with its category id
						pos = getOffset(a);
						a.pos = { left:pos[0], top:pos[1] };
						a.width = a.offsetWidth;
						a.height = a.offsetHeight;

						if (!a.box) if (a.box = document.getElementById('sub_'+a.id)) {

							with(a.box) {
								style.position = "absolute";
								style.zIndex = 99 + i;
								style.left = (a.pos.left - 3) + "px";
								style.top = (a.pos.top + a.offsetHeight) + "px"; //(a.pos.top + a.height + a.style.paddingBottom ) + "px";
							}

							a.showbox = function() {
								if (subnav.Box && this.box!=subnav.Box) {
									subnav.Box.className = subnav.Box.className.replace(/_v/g,'');
								}
								window.clearTimeout(this.box.closeTO);
								if (!this.box.className.match(/_v/)) this.box.className += '_v';
								subnav.Box = this.box;
							}

							a.hidebox = function() {
								var box_self = this.box;
								box_self.closeTO = window.setTimeout(function() { box_self.className = box_self.className.replace(/_v$/g,''); }, 150);
							}

							a.box.showbox = function() {
								window.clearTimeout(this.closeTO);
								if (!this.className.match(/_v/)) this.className += '_v';
							}

							a.box.hidebox = function() {
								var box_self = this;
								box_self.closeTO = window.setTimeout(function() { box_self.className = box_self.className.replace(/_v/g,''); }, 200);
							}

							a.onclick = function() {
								if (subnav.Picked && (this.parentNode != subnav.Picked)) {
									subnav.unpick();
								}
								if (!this.parentNode.className.match(/sel/)) this.parentNode.className += ' sel';
								subnav.Picked = this;
							}
							a.onmouseover = function() { this.showbox(); }
							a.onmouseout = function() { this.hidebox(); }
							a.box.onmouseover = function() { this.showbox(); }
							a.box.onmouseout = function() { this.hidebox(); }
						}

					}
				}
			}

		}

	}
}
catch(e) {
	alert('Error:\n' + e);
}