var DropDownMenus = new Array();
var isIE = (navigator.appName.indexOf('Microsoft') != -1);

function DropDown(parentId)
{
    // Maak een globale referentie naar dit object
    this.gRef = 'DropDownMenu_' + parentId;
    eval(this.gRef + ' = this');
    
    // Pak de bijbehorende link en maak het menu
    this.parentObj = document.getElementById(parentId);
    this.dropdown = document.createElement('div');
    
    // Geef het menu de benodigde stijl eigenschappen
    this.dropdown.style.position = 'absolute';
    this.dropdown.style.top = (this.parentObj.offsetTop + this.parentObj.offsetHeight + (isIE ? -3 : 0)) + 'px';
    this.dropdown.style.left = this.parentObj.offsetLeft + 'px';
    this.dropdown.className = 'dropdownMenu';
    
    this.parentObj.mObj = this;
    this.dropdown.mObj = this;
    
    this.parentObj.appendChild(this.dropdown);
    
    // Voeg dit menuobject toe aan een lijst met menu-objecten
    DropDownMenus[parentId] = this;
    
    // Maak een array voor alle links in het menu
    this.dropdown.items = new Array();
    
    this.dropdown.style.display = 'none';
    
    this._setHandlers();
}

DropDown.prototype._Hover = function()
{
    if (this.mObj.timerOn) {
        this.mObj.timerOn = false
        clearTimeout(this.mObj.timer);
        this.mObj.timer = null;
    }
    for(var key in DropDownMenus) {
        if (DropDownMenus[key] != this.mObj) {
            DropDownMenus[key]._Hide();
        }
    }
    this.mObj.dropdown.style.display = '';
};

DropDown.prototype._Out = function()
{
    if (!this.mObj.timerOn) {
        this.mObj.timerOn = true;
        this.mObj.timer = setTimeout(this.mObj.gRef + '._Hide();', 1000);
    }
};

DropDown.prototype._Hide = function()
{
    this.dropdown.style.display = 'none';
};

DropDown.prototype._setHandlers = function()
{
    this.dropdown.onmousemove = this._Hover;
    this.dropdown.onmouseout = this._Out;
    this.parentObj.onmousemove = this._Hover;
    this.parentObj.onmouseout = this._Out;
};

DropDown.prototype.addItem = function(link_name, link_url, link_target)
{
    // Maak de objecten voor de link aan
    var curr_link = document.createElement('a');
    
    // Voeg de link aan de lijst met items van het menu toe
    this.dropdown.items.push(curr_link);
    
    // Geef de link zijn eigenschappen
    curr_link.href = link_url;
    curr_link.innerHTML = link_name;
    curr_link.target = typeof link_target != 'undefined' ? link_target : '_self';
    
    // Voeg de link toe aan het menu
    this.dropdown.appendChild(curr_link);
};