//======================================================================================================//
//  Filename	: oncMenu.js										//
//  Release 	: 2002-12-09										//
//													//
//  This file is for building the navigation menu. 							//
//  For modifying the menuitems use the oncMenuItems.js and the oncMenuItemsIE50.js			//	
//======================================================================================================//
//  This script was created by Dave Bleeker.								//
//  Copyright 2003 SO-Creatief.										//
//======================================================================================================//

//======================================================================================//
// 				SET MENU DEFAULTS					//
//======================================================================================//

menuDefaultWidth		= 160;
menuDefaultBorderWidth		= 25;
menuDefaultPaddingWidth		= -25;
menuDefaultBorderTop		= 1;
menuDefaultPaddingTop		= 1;
menuItemDefaultHeight		= 30;
menuItemDefaultText		= "Onbekend";
menuItemDefaultHref		= "javascript:void(0)";
menuSeparatorDefaultHeight	= 6;
menuDefaultImagePath		= "";
menuDefaultEmptyText		= "Leeg";
menuDefaultBackground		= "#ffffff";

//======================================================================================//
// 				UGLY BROWSER TEST					//
//======================================================================================//

var op 		= /opera 5|opera\/5/i.test(navigator.userAgent);
var ie 		= !op && /msie/i.test(navigator.userAgent);	
var ie50 	= /MSIE ((5\.[01234])|([2345]))/.test( navigator.userAgent );	
var ie55 	= ie  && /MSIE ((5\.[56789])|([6789]))/.test( navigator.userAgent );
var mz 		= !op && /mozilla\/5/i.test(navigator.userAgent);									// preventing opera to be identified as mz
var ieBox 	= ie && /win/.test(navigator.platform) && (document.compatMode == null || document.compatMode != "BackCompat");	// IE proprietary box model

if (ie && document.getElementById == null) 
{																// ie4
  document.getElementById = function(sId) 
  {
    return document.all[sId];
  };
}

//======================================================================================//
// 				INCLUDE FUNTION						//
//======================================================================================//

function include(filename)
{
  document.write('<script type="text/javascript" src="js/' +filename+ '"></script>');
}

//======================================================================================//
// 				DEFINE MENU HANDLER EVENTS				//
//======================================================================================//

var menuHandler = 
{
  idCounter		: 0,
  idPrefix		: "DS-menu-object-",
  getId			: function () { return this.idPrefix + this.idCounter++; },
  overMenuItem		: function (oItem) 
  {
    var jsItem = this.all[oItem.id];
    var menuLength = this.idCounter - 1;
    var btnId = "DS-menu-object-" +menuLength;    
    var btn   = document.getElementById(btnId);
    window.status = jsItem.text;

    if (oItem == btn)
    {
      // Do nothing :)
    }    
    else
    {
      oItem.style.background 	= "white";
      oItem.style.color 	= jsItem.toolTip;
    }

    if (jsItem.subMenu) 
    {
      jsItem.parentMenu.hideAllSubs();
      jsItem.subMenu.show();
    }
    else jsItem.parentMenu.hideAllSubs();
  },
  blurMenu		: function (oMenuItem) 
  {
    window.setTimeout("menuHandler.all[\"" + oMenuItem.id + "\"].subMenu.hide();", 200);
  },
  all			: {}
};

//======================================================================================//
// 				MENU CONSTRUCTOR					//
//======================================================================================//

function menu()
{
  this._menuItems = [];
  this._subMenus  = [];
  this.id			= menuHandler.getId();
  this.top			= 0;
  this.left			= 0;
  this.shown			= false;
  menuHandler.all[this.id] 	= this;
}

//======================================================================================//
// 				MENU PROPERTIES						//
//======================================================================================//

menu.prototype.width		= menuDefaultWidth;
menu.prototype.borderWidth	= menuDefaultBorderWidth;
menu.prototype.paddingWidth	= menuDefaultPaddingWidth;
menu.prototype.borderTop	= menuDefaultBorderTop;
menu.prototype.paddingTop	= menuDefaultPaddingTop;
menu.prototype.emptyText	= menuDefaultEmptyText;
menu.prototype.background	= menuDefaultBackground;

//======================================================================================//
// 				MENU ADD FUNCTION					//
//======================================================================================//

menu.prototype.add = function(menuItem)
{
  this._menuItems[this._menuItems.length] = menuItem;

  if (menuItem.subMenu) this._subMenus[this._subMenus.length] = menuItem.subMenu;

   menuItem.parentMenu = this;
   // alert(this._menuItems);
};

//======================================================================================//
// 				MENU SHOW FUNCTION					//
//======================================================================================//

menu.prototype.show = function () 
{
  var divElement = document.getElementById(this.id);

  divElement.style.left = op ? this.left : this.left + "px";
  divElement.style.top = op ? this.top : this.top + "px";

  var divBottom = divElement.style.pixelTop + divElement.offsetHeight;
  if (divBottom > document.body.offsetHeight)
  {
    newTop = document.body.offsetHeight - divElement.offsetHeight;
    divElement.style.top = newTop;
  }

  divElement.style.visibility = "visible";
  this.shown = true;
  if (this.parentMenu)
  this.parentMenu.show();
}

//======================================================================================//
// 				MENU HIDE FUNCTION					//
//======================================================================================//

menu.prototype.hide = function () 
{
  this.hideAllSubs();
  var divElement = document.getElementById(this.id);
  divElement.style.visibility = "hidden";
  this.shown = false;
}

//======================================//
// 	MENU HIDE ALL FUNCTION		//
//======================================//

menu.prototype.hideAllSubs = function () 
{
  for (var i = 0; i < this._subMenus.length; i++) 
  {
    if (this._subMenus[i].shown)
    this._subMenus[i].hide();
  }
}

//======================================================================================//
// 				MENU TOSTRING FUNCTION					//
//======================================================================================//

menu.prototype.toString = function () 
{
  var top = this.top + this.borderTop + this.paddingTop;
  var str = "<div id='" + this.id + "' class='DS-menu' style='" + "background:" +this.background+ "; width:" + (!ieBox  ?  this.width - this.borderWidth - this.paddingWidth  :  this.width) + "px;" +  "left:" + this.left + "px;" +	"top:" + this.top + "px;" + "'>";

  if (this._menuItems.length == 0) 
  {
    str += "<span class='DS-menu-empty'>" + this.emptyText + "</span>";
  }
  else 
  {	
    // loop through all menuItems
    for (var i = 0; i < this._menuItems.length; i++) 
    {
      var mi = this._menuItems[i]
      str += mi;
      if (mi.subMenu) mi.subMenu.top = top - mi.subMenu.borderTop - mi.subMenu.paddingTop +10;
      top += mi.height;
    }
  }
  str += "</div>";

  for (var i = 0; i < this._subMenus.length; i++) 
  {
    this._subMenus[i].left = this.left + this.width - this._subMenus[i].borderWidth/2;
    str += this._subMenus[i];
  }
  return str;
};

//======================================================================================//
// 				MENU ITEMS FUNCTION					//
//======================================================================================//

function menuItem(sText, sHref, sToolTip, oSubMenu) 
{
  this.text = sText || menuItemDefaultText;
  this.href = (sHref == null || sHref == "") ? menuItemDefaultHref : sHref;
  this.subMenu = oSubMenu;
  if (oSubMenu) oSubMenu.parentMenuItem = this;
  this.toolTip = sToolTip;
  this.id = menuHandler.getId();
  menuHandler.all[this.id] = this;
};

menuItem.prototype.height = menuItemDefaultHeight;

//======================================================================================//
// 				MENUITEM TOSTRING FUNCTION				//
//======================================================================================//

menuItem.prototype.toString = function () 
{
  //return "<a" +	" id='" + this.id + "'" + " href='" + this.href + "'" +	(this.toolTip ? " style='background:" + this.toolTip + ";'" : "") +
  return "<a" +	" id='" + this.id + "'" + " href='javascript:window.location.replace(\"" +this.href+ "\")' " +	(this.toolTip ? " style='background:" + this.toolTip + ";'" : "") +

	 " onclick='javascript:window.setTimeout(\"getIframe()\",200)' onmouseover='menuHandler.overMenuItem(this);return true'"+ " onmouseout=\"this.style.color='white';this.style.background='" +this.toolTip+ "';window.status=document.title;return true\">" +this.text+ "</a>";
};

onmouseout="window.status='hallo';return true;"

//======================================================================================//
// 				MENU SEPARATOR AND ITS PROPERTIES			//
//======================================================================================//

function menuSeparator() 
{
  this.id = menuHandler.getId();
  menuHandler.all[this.id] = this;
};

menuSeparator.prototype.height = menuSeparatorDefaultHeight;

menuSeparator.prototype.toString = function () 
{
  return "<div></div>"
};

//======================================================================================//
// 				THE ROOTMENU CONSTRUCTOR				//
//======================================================================================//

function menuBar() 
{
  this._parentConstructor = menu;
  this._parentConstructor();
}

menuBar.prototype = new menu;

//======================================================================================//
// 				THE ROOTMENU TOSTRING - DOES IT EVER ENDS ? :)		//
//======================================================================================//

menuBar.prototype.toString = function () 
{
  var str = "<div id='" + this.id + "' class='DS-menu-bar'>";
	
  // loop through all menuButtons
  for (var i = 0; i < this._menuItems.length; i++)
  str += this._menuItems[i];
	
  str += "</div>";
  for (var i = 0; i < this._subMenus.length; i++)
  str += this._subMenus[i];
	
  return str;
};

//======================================================================================//
// 				THE ROOTMENUBUTTON CONSTRUCTOR				//
//======================================================================================//

function menuButton(sText, sHref, sToolTip, oSubMenu) 
{
  this._parentConstructor = menuItem;
  this._parentConstructor(sText, sHref, sToolTip, oSubMenu);
}

//======================================================================================//
// 				THE ROOTMENUBUTTON ITEMS				//
//======================================================================================//

menuButton.prototype = new menuItem;

//======================================================================================//
// 				AND JUST ONE MORE TIME... TOSTRING			//
//======================================================================================//

menuButton.prototype.toString = function () 
{
  return	"<a" +	" onmouseover='menuHandler.overMenuItem(this)'" + " id='" + this.id + "'" + " href='" + this.href + "'" +
  (op ? (" onoperafocus='menuHandler.overMenuItem(this)'" +
  (this.subMenu ? " onoperablur='menuHandler.blurMenu(this)'" : "")) : (" onfocus='menuHandler.overMenuItem(this)'" +
  (this.subMenu ? " onblur='menuHandler.blurMenu(this)'" : "")
  )) +"><img src='img/nav/" +this.text+ "' border=0></a>";
}

if (ie50)
{
  include("oncMenuItemsIE50.js"); 
}
else
{
  include("oncMenuItems.js");
}
