var navActive    = null;
var subnavActive = null;

function navInit () {
	
	var items = $$('li');

	for (var i = 0; i < items.length; i++) {

		info      = items[i].id.split("-");
  		infoClass = items[i].className.split("-");
  		
		if (info[0] == 'nav') {
			
			items[i].onmouseover = navOn;
			items[i].onmouseout = navOff;

			if (infoClass[1] == 'on')
				navActive = info[2];
				
		}
		
	}
	
}

function subnavInit () {
	
	var items = $$('div');

	for (var i = 0; i < items.length; i++) {

		info      = items[i].id.split("-");
        infoClass = items[i].className.split("-");

		if (info[0] == 'subnav') {
			
			items[i].onmouseover = subnavOn;
			items[i].onmouseout = subnavOff;
			
			if (infoClass[1] == 'on')
				subnavActive = info[1];
				
		}
		
	}
	
	new Ajax.Request('/ajax.php?module=menu&method=renderDropDownNavigation&id=&params=',
		{
    		method: 'get',
    		onSuccess: function(transport) {
      			var response = transport.responseText.evalJSON();
      			if (!response) { return; }
      			for (var i = 0; i < response.length; i++) {
      			    new Insertion.After($("nav-rgt-"+response[i].id), response[i].html);
				}
    		}
  		}
	);

	
}

function navOn () {
	
	info = this.id.split("-");
	
	$("nav-lft-"+info[2]).className = "lft-on";
	$("nav-rgt-"+info[2]).className = "rgt-on";
	
	if (subnavElement = $("subnav-layer-"+info[2])) {
		
   		offTop = getX(this) + 21;
   		offLft = getY($("nav-lft-"+info[2]));

		subnavElement.onmouseover = subnavLayerOn;
		subnavElement.onmouseout  = navOff;

   		subnavElement.style.top     = offTop+"px";
   		subnavElement.style.left    = offLft+"px";
    	subnavElement.style.display = "block";
	    	
    }

}

function navOff () {
	
	info = this.id.split("-");
	
	if (navActive != info[2]) {

		$("nav-lft-"+info[2]).className = "lft";
		$("nav-rgt-"+info[2]).className = "rgt";
		
	}

	if ($("subnav-layer-"+info[2]))
		$("subnav-layer-"+info[2]).style.display = "none";

}

function subnavLayerOn () {
	
	info = this.id.split("-");

	$("nav-lft-"+info[2]).className = "lft-on";
	$("nav-rgt-"+info[2]).className = "rgt-on";

    $("subnav-layer-"+info[2]).style.display = "block";
    
}

function subnavOn () {
	
	this.className = "item-on";
	
}

function subnavOff () {

	info = this.id.split("-");
	
	if (subnavActive != info[1])
		this.className = "item";

}

