//
// Based on the code written by Miha Hribar (http://hribar.info) with
// minor modifications by Jernej Kos.
//

/**
 * Initializes the menu elements.
 */
function initializeMenus()
{
  if (!document.getElementsByTagName)
    return false;

  if (!document.getElementById)
    return false;

  var menu = document.getElementById("menu");
  if (!menu)
    return false;

  // Get first level LI elements
  var rootLi = menu.getElementsByTagName("li");
  for (var i = 0; i < rootLi.length; i++) {
    var li = rootLi[i];

    var childUl = li.getElementsByTagName("ul");
    if (childUl.length >= 1) {

      // Method for menu display
      li.onmouseover = function () {
        if (this.timer != undefined) {
          clearTimeout(this.timer);
          this.timer = undefined;
        }

        var ul = this.getElementsByTagName("ul");
        if (!ul)
          return false;

        ul[0].style.display = "block";
	this.className = 'tabNavigacijaActive';

	var a = this.getElementsByTagName("a");
	if (a) {
	  var fakeLink = ul[0].getElementsByTagName("a");
	  fakeLink[0].style.width = (a[0].offsetWidth + 7) + 'px';
	}

        return true;
      }

      // Method for menu hiding
      li.onmouseout = function () {
        var ul = this.getElementsByTagName("ul");
        if (!ul)
          return false;
        var thisVar = this;

        if (this.timer == undefined) {
        this.timer = setTimeout( function() {


        ul[0].style.display = "none";
        thisVar.className = 'tabNavigacija';

        return true;
        }, 200);
        }
      }
    }
  }

  return true;
}

