﻿var dolphintabs = {
    subcontainers: [], last_accessed_tab: null,

    revealsubmenu: function(curtabref) {
        this.hideallsubs()
        //if there was last visited tab then hide it 
        if (this.last_accessed_tab != null)
            this.last_accessed_tab.className = ""
        //If there's a sub menu defined for this tab item, show it
        //curtabref is from the agrument
        if (curtabref.getAttribute("rel")) 
            document.getElementById(curtabref.getAttribute("rel")).style.display = "block"
        curtabref.className = "current"
        this.last_accessed_tab = curtabref
    },
    
    //This hides all submenu presently visible
    hideallsubs: function() {
        for (var i = 0; i < this.subcontainers.length; i++)
            document.getElementById(this.subcontainers[i]).style.display = "none"
    },


    init: function(menuId, selectedIndex) {
		var tabItems = document.getElementById(menuId).getElementsByTagName("a")
        for (var i = 0; i < tabItems.length; i++) {
            if (tabItems[i].getAttribute("rel"))
            //store rel in subcontainer
            //store id of submenu div of tab menu item
                this.subcontainers[this.subcontainers.length] = tabItems[i].getAttribute("rel")
            //selectecd Index is passed as argument
            if (i == selectedIndex) { //if this tab item should be selected by default
                tabItems[i].className = "current"
                this.revealsubmenu(tabItems[i])
            }
            tabItems[i].onmouseover = function() {
                dolphintabs.revealsubmenu(this)
            }
        } //END FOR LOOP
    }

}