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

function activate_dropdown($current_object){
	// Ubirajem clearTimeout
	
	if (window.$hide_timeout){
		window.clearTimeout(window.$hide_timeout);
		window.$hide_timeout = 0;
	}

	$id = parseInt($current_object.id.replace("link-",""));
	if ($last_active == $id) {
		return;
	}
	
	if ($current_object != $prev_obj) {
		$zz = $prev_obj.id
	} else {
		$zz = '';
	}
	_hide_all_submenus($zz);
	$last_active = $id;
	$active_menus.push($id);
	$submenu = document.getElementById("sub-"+$id);
	if (!$submenu) return;
	
	$submenu.style.display = "block";
	$submenu.style.width = $current_object.clientWidth;
	$submenu.style.overflow = 'hidden';
	
	//alert($current_object.clientWidth);
	//alert($submenu.style.width);

	if ($current_object.className != 'active') {
		$current_object.style.background = '#980400 url(images/building/top_nav_l_corner_act.gif) top left no-repeat';
		$img = $current_object.getElementsByTagName('img');
		$img[2].src = $img[2].src.replace('.gif','_act.gif');
	}
}

function deactivate_dropdown($current_object){	
	if (!window.$hide_timeout){
		window.$hide_timeout = window.setTimeout("_hide_all_submenus('"+$current_object.id+"')", 500);
	}
	$prev_obj = $current_object;
}

function _hide_all_submenus($obj){
	if ($obj) {
		$current_object = document.getElementById($obj);
		if ($current_object.className != 'active') {
			$current_object.style.background = '#c9c9c9 url(images/building/top_nav_l_corner.gif) top left no-repeat';
			$img = $current_object.getElementsByTagName('img');
			if ($img[2]) {
				$img[2].src = $img[2].src.replace('_act.gif','.gif');
			}
		}
	}
	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;
}

