/* * Dropdownmenu for Web in a Box * Copyright IT Construction Company * @author Michiel * @version 1.0 * @requires prototype.js, effects.js */ var DropDown = Class.create(); DropDown.prototype = { /* initiale object */ initialize: function() { this.hideDelay = 1000; this.menuName = "subMenu"; this.expandedMenu = null; this.expandedParentObj = null; this.delayTimer = null; this.menuArr = new Array(); this.initialized = false; }, /* add all menu items to menu array */ initMenuItems: function() { var elem = document.getElementsByTagName('div'); for (var i = 0; i < elem.length; i++) if(elem[i].id.substr(0, this.menuName.length) == this.menuName) this.menuArr.push(elem[i].id.substr(this.menuName.length, elem[i].id.length)); this.initialized = true; }, /* check if menuid is an submenu */ isMenu: function(_menuID) { if(this.menuArr.length > 0) for (var i = 0; i < this.menuArr.length; i++) if(this.menuArr[i] == _menuID) return true; return false; }, /* positions the menu object */ positionMenu: function(_menuID, _parentObj) { var posArr = new Position.cumulativeOffset(_parentObj); $('subMenu' + _menuID).style.position = "absolute"; $('subMenu' + _menuID).style.left = posArr[0] + 1; $('subMenu' + _menuID).style.top = posArr[1] + _parentObj.clientHeight - 5; }, /* function called on mouseover */ over: function(_menuID, _parentObj) { if(!this.initialized) this.initMenuItems(); if(this.isMenu(_menuID)) { if(_menuID != this.expandedMenu) { if(this.expandedMenu) { $('subMenu' + this.expandedMenu).style.display = 'none'; this.expandedParentObj.id = 'menuItemSub'; } // $('topSellSpacer').style.width = 50;//_parentObj.clientWidth; // alert($('topSellSpacer').style.width); this.positionMenu(_menuID, _parentObj); //new Effect.SlideDown($('subMenu' + _menuID), {duration: 0.2}); $('subMenu' + _menuID).style.display = ''; _parentObj.id = 'menuItemSub-active'; this.expandedParentObj = _parentObj; this.expandedMenu = _menuID; } window.clearTimeout(this.delayTimer); } else { this.hide(); _parentObj.id = 'menuItem-active'; } }, /* hide expanded menu */ hide: function() { if(this.expandedMenu) { //new Effect.SlideUp($('subMenu' + this.expandedMenu), {duration: 0.2}); $('subMenu' + this.expandedMenu).style.display = "none"; this.expandedMenu = null; this.expandedParentObj.id = 'menuItemSub'; this.expandedParentObj = null; } }, /* called on mouseout */ out: function(_menuID, _parentObj) { if(this.isMenu(_menuID)) this.delayTimer = setTimeout('dropDown.hide(\''+ _menuID +'\')', this.hideDelay) else _parentObj.id = 'menuItem' } } var dropDown = new DropDown();