﻿function MenuItem(element,parentItem,dropDownId){function getStyleObject(element){return(element.style||element)}function getNextSiblingElement(element){for(var nextSibling=null;(nextSibling=element.nextSibling)&&!(nextSibling.tagName);element=nextSibling);return nextSibling}function getOffsetLeft(element){var offsetLeft=element.offsetLeft;var offsetParent=element.offsetParent;if(offsetParent){offsetLeft+=getOffsetLeft(offsetParent)}return offsetLeft}function getOffsetTop(element){var offsetTop=element.offsetTop;var offsetParent=element.offsetParent;if(offsetParent){offsetTop+=getOffsetTop(offsetParent)}return offsetTop}var _this_=this;var dropDownElement=dropDownId?document.getElementById(dropDownId):getNextSiblingElement(element);dropDownElement.parentNode.removeChild(dropDownElement);document.body.appendChild(dropDownElement);var dropDownStyle=getStyleObject(dropDownElement);var parentElement=element.parentNode;var children=[];var currentItem=null;var timerId=0;this.addChild=function(childItem){children.push(childItem)};this.getTimerId=function(){return parentItem?parentItem.getTimerId():timerId};this.setTimerId=function(value){if(parentItem){parentItem.setTimerId(value)}else{timerId=value}};this.clearTimer=function(){if(parentItem){parentItem.clearTimer();return}if(timerId){clearTimeout(timerId);timerId=0}};this.getCurrentItem=function(){return currentItem};this.setCurrentItem=function(value){currentItem=value;if(parentItem){parentItem.setCurrentItem(this)}};this.showElement=function(){dropDownStyle.left="0px";dropDownStyle.top="0px";dropDownStyle.position="absolute";dropDownStyle.display="block";var offset_width=dropDownElement.offsetWidth;if(parentItem){dropDownStyle.left=(getOffsetLeft(parentElement)-dropDownElement.offsetWidth+5)+"px";dropDownStyle.top=(element.offsetTop-1)+"px"}else{dropDownStyle.left=(getOffsetLeft(parentElement)+parentElement.offsetWidth-dropDownElement.offsetWidth-2)+"px";dropDownStyle.top=(getOffsetTop(parentElement)+parentElement.offsetHeight+5)+"px"}dropDownStyle.width=(offset_width-2)+"px";var className=element.className;var matched=className.match(/(.*?)_active$/);element.className=matched?matched[0]:className+"_active";if(parentItem){parentItem.setCurrentItem(this)}};this.hideElement=function(){for(var i=0;i<children.length;i++){children[i].hideElement()}dropDownStyle.display="none";var className=element.className;var matched=className.match(/(.*?)_active$/);element.className=matched?matched[1]:className;if(parentItem){var _currentItem=parentItem.getCurrentItem();if(_currentItem==this){parentItem.setCurrentItem(null)}}};this.hideParent=function(){if(parentItem){parentItem.hideElement();parentItem.hideParent()}};this.onMouseOutTimer=function(){_this_.setTimerId(0);_this_.hideElement();_this_.hideParent()};element.onmouseover=function(){_this_.clearTimer();if(parentItem){var _currentItem=parentItem.getCurrentItem();if(_currentItem){if(_currentItem==_this_){return}_currentItem.hideElement()}}if(dropDownStyle.display!="block"){_this_.showElement()}};parentElement.onmouseover=function(){_this_.clearTimer()};parentElement.onmouseout=function(){if(_this_.getTimerId()){return}_this_.setTimerId(setTimeout(_this_.onMouseOutTimer,500))};dropDownElement.onmouseover=function(){_this_.clearTimer()};dropDownElement.onmouseout=function(){if(_this_.getTimerId()){return}_this_.setTimerId(setTimeout(_this_.onMouseOutTimer,500))};if(parentItem){parentItem.addChild(this)}element.onmouseover()}function __base_js_onload__(){function __call_inherit__(){if(__base_js_onload__.__inherit__){try{__base_js_onload__.__inherit__()}catch(e){alert("Error: "+e.message)}}}function __init_list__(__element_name__,__child_name__,__class_name__){var tags=document.getElementsByTagName(__element_name__);for(var i=0;i<tags.length;i++){for(var j=0;j<tags[i].childNodes.length;j++){var childNode=tags[i].childNodes[j];if(childNode.tagName){if(childNode.tagName.toLowerCase()==__child_name__){childNode.className=__class_name__;break}}}}}__call_inherit__();__init_list__("ul","li","first-child")}__base_js_onload__.__inherit__=window.onload;window.onload=__base_js_onload__;
