﻿/**
 *   Filename     : ddMenu.js
 *   Date Written : March 10, 2008 
 *   Written By   : Nelson D. Bendigosa
 *   Description  : Object class for dropdown menu.
 *
 *   Parameters :
 *      bColor - the background color of the menu. 
 *      itemclass - the class style for the menu item.   
 *      zindex - the z-order of the parent DIV.
 *      opacity - the transparency amount of the menu. 
 *              
**/

if(typeof obrainiacs == "undefined") var obrainiacs = {};
obrainiacs.ddMenu = function(itemclass, bColor, zindex, opacity) {     
    this.divParentEl;                                   //the parent DIV element of the menu.
    this.attributes = [];                               //contains the attributes to set.
    this.setAttribute("bColor", bColor || "#000000");   //the background color of the menu. Default is Black.
    this.setAttribute("itemclass", itemclass || "");    //the class name for the menu item.
    this.setAttribute("zindex", zindex || 30);          //the z-order of the parent DIV. Default is 30.
    this.setAttribute("opacity", opacity || 80);        //the transparency value of the menu. Default is 80.
}

obrainiacs.ddMenu.prototype = {
    /* ---------------------------------------------------------------------------
     *   Method name : setAttribute()
     *   Purpose : Use to set the attributes of an object.
     *   Parameters : 
     *       name - is the name of the attribute to set.
     *       value - the value of the attribute.
     * --------------------------------------------------------------------------- 
    */
    setAttribute: function(name, value) {
        this.attributes[name] = value;
    },
    
    /* ---------------------------------------------------------------------------
     *   Method name : getAttribute()
     *   Purpose : Use to get the attributes of an object.
     *   Parameters : 
     *       name - is the name of the attribute to get its value.     
     * --------------------------------------------------------------------------- 
    */
    getAttribute: function(name) {
        return this.attributes[name] || "";
    },      
    
    /* ---------------------------------------------------------------------------
     *   Method name : createMenu()
     *   Purpose : Use to create the menu item inside element specified in (el).
     *   Parameters : 
     *       el- the div element on which to create the menu item.
     *       itemlist - 2-dimensional array which contains the Menu item and
     *                  the URL.
     * --------------------------------------------------------------------------- 
    */
    createMenu: function(el, itemlist) {
        var divMenuItem = "";               
        this.divParentEl = el;
        var divParent = document.getElementById(el);
        
        if(itemlist) {            
            for(var i = 0; i < itemlist.length; i++) {
                divMenuItem += '<div><a href="' + itemlist[i][1] + '" class="' + this.getAttribute("itemclass") + '">' + 
                               itemlist[i][0] + '</a></div>\n';
            }            
            divParent.innerHTML = divMenuItem;            
        }        
    },
    
    /* ---------------------------------------------------------------------------
     *   Method name : showMenu()
     *   Purpose : Use to display the menu for the current object.
     *   Parameters : 
     *       none    
     * --------------------------------------------------------------------------- 
    */
    showMenu: function() {             
        var divParent = document.getElementById(this.divParentEl);
        var opacity = this.getAttribute("opacity");
        var t;
        
        if(divParent) {           
           divParent.style.opacity = (opacity / 100);
           divParent.style.MozOpacity = (opacity / 100);
           divParent.style.filter = 'alpha(opacity=' + opacity + ')';
           divParent.style.backgroundColor = this.getAttribute("bColor");
           divParent.style.visibility = 'visible';
           divParent.style.zIndex = this.getAttribute("zindex");                       
        }        
    },
    
    /* ---------------------------------------------------------------------------
     *   Method name : closeMenu()
     *   Purpose : Use to close the currently open menu.
     *   Parameters : 
     *       none
     * --------------------------------------------------------------------------- 
    */
    closeMenu: function() {              
        var divParent = document.getElementById(this.divParentEl);
        if(divParent) divParent.style.visibility = 'hidden';       
    }
}

/* alias, so that we can use ddMenu in creating object of this type. */
var ddMenu = obrainiacs.ddMenu;

