/** * Method to attach an event handler to an element * @param object HTML element that the event should be attached to * @param string Name of the event, ie 'mouseover' * @param function Function that should be called when event occurs * @return element | boolean */ function registerHandler(element, evType, fn) { // check if this functionality is available anyway if (element.addEventListener) { // just use the 'addEventListener' methode element.addEventListener(evType, fn, true); return false; } else if (element.attachEvent) { // IE way of handling with events return element.attachEvent("on"+evType, fn); } } /** * Helper method to get the left & top position of the component * @param HTML element * @return Position object with properties 'left' and 'right' */ function getPosition(element) { // get the parent position if (!element.offsetParent) { return { left: element.offsetLeft, top: element.offsetTop } } else { var position = getPosition(element.offsetParent); position.left += element.offsetLeft; position.top += element.offsetTop; return position; } } /** * Helper method to set the position of an HTML element. * This method can be used to set that position of the element, based * on the lefttop coordinates of the document, and thus not based on the * offset-parent. This method only works for absolute positioned elements * @param HTML element * @param Left coordinate * @param Top coordinate */ function setPosition(element, left, top) { // does the element have an offset-element? if (element.offsetParent) { // find the position of the offset parent var offset = getPosition(element.offsetParent); left -= offset.left; top -= offset.top; } // Change the position element.style.left = left + 'px'; element.style.top = top + 'px'; } /** * Class represents a dropdown box * @param string Name of the dropdown */ function Dropdown(name) { // get the item and the dropdown this.menu = document.getElementById('menu_'+name); this.dropdown = document.getElementById('dropdown_'+name); // store original classname of menu this.originalClassname = this.menu.className; // timer for opening the dropdown, and a timer for closing the dropdown this.openTimer = false; this.closeTimer = false; // register the handlers this.initHandler(this.menu); this.initHandler(this.dropdown); } /** * Initialize the handler on a certain element * @var object HTML element */ Dropdown.prototype.initHandler = function(el) { // keep reference to this var self = this; // set up the handlers el.onmouseover = function() { self.mouseOverHandler(); } el.onmouseout = function() { self.mouseOutHandler(); } // register the same handlers for all child elements for (var i=0; i