var HTTP_HOST = 'http://' + window.location.hostname + '/';

version = navigator.appVersion.toLowerCase();
ie = (version.indexOf('msie')>-1);
subsVisible = [];
timer = false;
timer2 = false;
milisec = 500;

function subShow(subId) {
    list = document.getElementById('navi-list');
    submenus = list.getElementsByTagName('ul');
    for(i in submenus) {
        if(submenus[i].id) {
            if(submenus[i].id == subId) {
                elm = document.getElementById(subId);
                if(timer) {
                    clearTimeout(timer);
                    clearTimeout(timer2);
                }
                if(elm && !subsVisible[subId]) {
                    elm.style.display = "block";
                    subsVisible[subId] = true;
                    selectsVisibility('hidden');
                }
            } else {
                subHide(submenus[i].id);
            }
        }
    }
}

function subWannaHide(subId) {
    elm = document.getElementById(subId);
    if(elm && subsVisible[subId]) {
        timer = setTimeout("subHide(\""+subId+"\")", milisec);
        timer2 = setTimeout("selectsVisibility('visible')", milisec);
    }
}

function subHide(subId) {
    elm = document.getElementById(subId);
    if(elm && subsVisible[subId]) {
        elm.style.display = "none";
        subsVisible[subId] = false;
    }
}

function menuClick(parentid) {
    listid = 'menu-parentid-'+parentid;
    buttonid = 'a-parentid-'+parentid;
    filterid = 'filter-parentid-'+parentid;
        
    list = document.getElementById(listid);
    button = document.getElementById(buttonid);
    filter = document.getElementById(filterid);

    if(button.className == 'tree closed') {
        button.className = 'tree open'
        if(list) {
            list.style.display = "block";
        }
        if(filter) {
            filter.style.display = "block";
        }
    } else {
        button.className = 'tree closed'
        if(list) {
            list.style.display = "none";
        }
        if(filter) {
            filter.style.display = "none";
        }
    }
}

// JavaScript Document

// DropDownMenu by Miha Hribar
// http://hribar.info

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function prepareMenu() {
    // first lets make sure the browser understands the DOM methods we will be using
  	if (!document.getElementsByTagName) return false;
  	if (!document.getElementById) return false;
  	
  	// lets make sure the element exists
  	if (!document.getElementById("menu_js")) return false;
  	var menu = document.getElementById("menu_js");
  	
  	// for each of the li on the root level check if the element has any children
  	// if so append a function that makes the element appear when hovered over
  	var root_li = menu.getElementsByTagName("li");
  	for (var i = 0; i < root_li.length; i++) {
  	    var li = root_li[i];
  	    // search for children
  	    var child_ul = li.getElementsByTagName("ul");
  	    if (child_ul.length >= 1) {
  	        // we have children - append hover function to the parent
  	        li.onmouseover = function () {
  	            if (!this.getElementsByTagName("ul")) return false;
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "block";
  	            return true;
  	        }
  	        li.onmouseout = function () {
  	            if (!this.getElementsByTagName("ul")) return false;
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "none";
  	            return true;
  	        }
  	    }
  	}
  	
  	return true;
}

addLoadEvent(prepareMenu);
