/* tabbedMenu for PACT project
    By Frank Pennycook frank@pennycook.net
    October 2007
*/

var tabbedMenu={

	Heading:[], Menu:[], Tab:[], currentIndex:null,


	showMenu:function(newIndex){
		this.hideAllMenus()
		if (newIndex == this.currentIndex){
			this.Menu[newIndex].className="current"   
		} else if (null != this.Tab[newIndex]) {
			this.Menu[newIndex].className="preview"   
			this.Tab[newIndex].className="preview"
		}
	},

	hideAllMenus:function(){
		// do not use less than sign because Typo3 does not like it
		for (var i=0; i!=this.Menu.length; i++){
			this.Menu[i].className="inactive"
			this.Tab[i].className="inactive"   
		}
		// keep the current tab current even if its menu is inactive
		this.Tab[this.currentIndex].className="current"
	},

	init:function(tabbedMenuId, currentIndex){

          var menuArea=document.getElementById(tabbedMenuId)
          this.currentIndex = currentIndex
          if (null != menuArea){		

		// read info about all the tabs into global arrays
		this.Tab=menuArea.getElementsByTagName("li")
		// do not use less than sign because Typo3 does not like it
		for (var i=0; i!=this.Tab.length; i++){


			if (this.Tab[i].getAttribute("id")){

				// the tab headings are divs with id attribute
				this.Heading[this.Heading.length]=this.Tab[i].getAttribute("id")
				menuName="menu_"+this.Heading[i]
				this.Menu[this.Menu.length]=document.getElementById(menuName)
			}
			
			// each tab knows its own index
			this.Tab[i].index=i
			

			// set mouseover behaviour to show relevant menu
			this.Tab[i].onmouseover=function(){
				// 'this' now refers to the Tab element
				tabbedMenu.showMenu(this.index)
			}

			/*set mouseout behaviour to still show relevant menu
			this.Tab[i].onmouseout=function(){
				tabbedMenu.showMenu(this.index)
			}*/

		} // end for loop over tab index i		

		// revert to default only when mouse leaves menu area completely
		document.getElementById("left_column").onmouseout=function(){
			tabbedMenu.showMenu(tabbedMenu.currentIndex)
		}

		// show menu for the initial tab
		this.showMenu(currentIndex)

          } // end if tabbed menu exists
	} // end function init

}
