// Script to show and hide the menu-items

//Needed to show and hover the active menus
function fktReactivateMenu(){
	fktHideSub();
	fktMenuUnHover();
	
	main_id = getCookie('active_main_menu_id');
	sub_id = getCookie('active_sub_menu_id');
	
	if(document.getElementById("menu_main_item"+main_id) != null)
		document.getElementById("menu_main_item"+main_id).style.backgroundPosition = "0px -34px";
		
	if(document.getElementById("menu_sub"+main_id) != null)
		document.getElementById("menu_sub"+main_id).style.visibility = "visible";
	if(document.getElementById("menu_sub_item"+main_id+''+sub_id) != null)
		document.getElementById("menu_sub_item"+main_id+''+sub_id).style.color = "#529a9f";
}


function fktChangeActiveMain(id){
	setCookie('active_main_menu_id',id,1);
	setCookie('active_sub_menu_id',0,1);
}
function fktChangeActiveSub(id_main,id_sub){
	setCookie('active_main_menu_id',id_main,1);
	setCookie('active_sub_menu_id',id_sub,1);
}


//clicked_item contains reference to the clicked bouton or item
//menu_id contains a string with the menu to show
function fktMenuShow(clicked_item,menu_id) {
	fktHideSub();
	fktMenuHover(clicked_item);
	if(document.getElementById(menu_id) != null)
		document.getElementById(menu_id).style.visibility = "visible";
}


//Function to hide all the menu_sub's
function fktHideSub() {
  	//Hide all menu_sub's
  	//Works only for upto 9 menu_sub's
	for (var i=1;i<10;i++){
		if(document.getElementById("menu_sub"+i) != null)
			document.getElementById("menu_sub"+i).style.visibility = "hidden";
	}
}

function fktMenuHover(citem) {
	//First: unhover all elements
	fktMenuUnHover();
	
	//Second: hover the clicked bouton
	//citem.className = "menu_main_item_active";
	citem.style.backgroundPosition = "0px -34px";
}

function fktMenuUnHover(){
	menu_main_items = document.getElementById("menu_main_container").getElementsByTagName("a");
	for (var i=0;i<menu_main_items.length;i++)
		menu_main_items[i].style.backgroundPosition = "0px 0px";
}


function getCookie(c_name){
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}
function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

