function init_nav($table){
	$links = $table.getElementsByTagName("A");
	$counter = $links.length;
	for ($x=0; $x < $counter; $x++) {
		$td = $links[$x].parentNode;
		$td.onmouseover =  activate_dropdown;
		$td.onmouseout 	=  deactivate_dropdown;
	}
}

var $active_menus = new Array();
var $hide_timeout = 0;
var $last_active =  0;

function activate_dropdown(){

	// Poluchajem tekushij TD objekt
	var $current_object = this;
	while($current_object.tagName && $current_object.tagName != "TD"){
		$current_object = $current_object.parentNode;
	}
	// Ubirajem clearTimeout
	if (window.$hide_timeout){
		window.clearTimeout(window.$hide_timeout);
		window.$hide_timeout = 0;
	}
	// Poluchejem ID tekushego elementa
	$id = parseInt($current_object.getAttribute("id").replace("link-",""));
	if ($last_active == $id) {
		return;
	}

	_hide_all_submenus();
	$last_active = $id;
	$active_menus.push($id);
	$container = document.getElementById("link-"+$id);
	$submenu = document.getElementById("sub-"+$id);
	if (!$submenu) return;
	if ($container.firstChild != $submenu){
		$container.insertBefore($submenu, $container.firstChild);
	}
	$submenu.style.display = "block";
}

function deactivate_dropdown(){
	if (!window.$hide_timeout){
		window.$hide_timeout = window.setTimeout("_hide_all_submenus()", 500);
	}
}
function _hide_all_submenus(){
	while($sub = $active_menus.pop()){
		if (document.getElementById("sub-"+$sub)){
			document.getElementById("sub-"+$sub).style.display = "none";
		}
	}
	$last_active = 0;
	window.clearTimeout(window.$hide_timeout);
	window.$hide_timeout = 0;
}
