/**
 * LiveMenu, version 1.0
 *
 * Copyright (c) 2009 Sergey Golubev
 *
 * LiveMenu is freely distributable under the terms of the MIT License.
 * For details, see http://livemenu.sourceforge.net
 */
var liveMenu={};liveMenu.defaultConfig={mainMenuClassName:"lm-menu",submenuClassName:"lm-submenu",containerClassName:"lm-container",horizontalClassName:"lm-horizontal",verticalClassName:"lm-vertical",right:"lm-right",left:"lm-left",up:"lm-up",down:"lm-down",showDelay:80,hideDelay:400,showEventType:"mouseenter",effect:"plain",duration:500,maxHidingSubmenus:3,transition:"sinoidal"};liveMenu.isReady=false;liveMenu.subsCount=0;liveMenu.isKonqueror=navigator.userAgent.indexOf("Konqueror")!=-1;liveMenu.initOnLoad=function(b,a){if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){liveMenu.isReady=true;new liveMenu.Menu(b,a)},false)}else{if(document.attachEvent){document.attachEvent("onreadystatechange",function(){if(document.readyState==="complete"){liveMenu.isReady=true;new liveMenu.Menu(b,a)}})}}liveMenu.event.add(window,"load",function(){if(!liveMenu.isReady){new liveMenu.Menu(b,a)}})};liveMenu.Menu=function(e,a){var d=liveMenu.Utils;this.config=d.merge(liveMenu.defaultConfig,a);if(this.config.showEventType=="click"){this.config.showDelay=0}this.id=e;this.domNode=document.getElementById(e);this.submenus={};this.visibleSubs=[];this.stopHidingOn=null;var b=this.getInitSubNodes();this.setSubIDs(b);var c=this.convertMenuTree(b);this.initializeSubs(c)};liveMenu.Menu.prototype={getInitSubNodes:function(){var f=liveMenu.Utils,c=this.config,b=this.domNode.getElementsByTagName("ul"),e=[];for(var d=0,a=b.length;d<a;d++){if(f.hasClass(b[d],c.submenuClassName)){e.push(b[d])}}return e},setSubIDs:function(c){for(var b=0,a=c.length;b<a;b++){var d=c[b];d.id="submenu"+(++liveMenu.subsCount);d.parentNode.id="submenu"+liveMenu.subsCount+"_opener"}},convertMenuTree:function(b){var g,c,a,e,k,n=[],m,h,f;for(m=0,f=b.length;m<f;m++){g=b[m];a=g.cloneNode(true);e=a.childNodes;for(h=0;h<e.length;h++){if(e[h].tagName=="LI"){if(k=e[h].getElementsByTagName("ul")[0]){k.parentNode.removeChild(k)}}}c=document.createElement("div");c.className=this.config.containerClassName;c.appendChild(a);a.style.display="block";if(liveMenu.isKonqueror){var d=liveMenu.Utils;if((this.config.effect=="fade"||this.config.effect=="smooth")&&d.hasClass(a,this.config.horizontalClassName)){c.appendChild(document.createTextNode("\u00a0"))}}document.body.appendChild(c);n.push(a)}this.removeInitSubNodes();return n},initializeSubs:function(d){for(var b=0,a=d.length;b<a;b++){var c=d[b];this.submenus[c.id]=new liveMenu.Submenu(c,this)}},removeInitSubNodes:function(){var b=this.domNode.childNodes;for(var a=0;a<b.length;a++){if(b[a].tagName=="LI"){var c=b[a].getElementsByTagName("ul")[0];if(c){c.parentNode.removeChild(c)}}}},removeFromVisibleSubs:function(b){var d=this.visibleSubs,c=[];for(var a=0;a<d.length;a++){if(d[a]!=b){c.push(d[a])}}this.visibleSubs=c},parseHidingSubs:function(){var a=this.config.maxHidingSubmenus,c=[],e=this.visibleSubs;for(var d=0;d<e.length;d++){if(e[d].isHiding){c.push(e[d])}}var b=c.length-a;if(b>0){for(d=0;d<b;d++){c[d].hideWithoutEffect()}}}};liveMenu.Submenu=function(b,a){this.id=b.id;this.menu=a;this.domNode=b;this.container=b.parentNode;this.opener=document.getElementById(this.id+"_opener");this.parentSub=this.menu.submenus[this.opener.parentNode.id];this.position=this.getPosition();this.hideTimer=null;this.showTimer=null;this.isShowing=false;this.isHiding=false;this.isGoingToHide=false;this.addEventListeners()};liveMenu.Submenu.prototype={addEventListeners:function(){var d=liveMenu.event,g=this.menu.config.showEventType;var f=this;d.add(this.opener,g,function(h){f.show(h)},true);d.add(this.opener,g,function(h){f.cancelHide(h)},true);d.add(this.opener,"mouseleave",function(h){f.hide(h)});d.add(this.domNode,"mouseleave",function(h){f.hide(h)});var b=this.domNode.childNodes;for(var a=0;a<b.length;a++){if(b[a].tagName=="LI"){d.add(b[a],"mouseenter",function(h){f.cancelHide(h)})}}if(g=="click"){var c=this.opener.getElementsByTagName("A");for(a=0;a<c.length;a++){d.add(c[a],"click",function(h){h.preventDefault()})}}},show:function(d){var c=this.parentSub,a=this.menu;if(c&&(c.isShowing||c.isHiding)){a.subToShowNext=this;return}var f=this,b=a.config.showDelay;this.showTimer=setTimeout(function(){f.doShow(false)},b)},cancelHide:function(c){if(!this.isVisible()){return}var a=this.menu;if(this.isGoingToHide){clearTimeout(this.hideTimer);this.hideTimer=null;this.isGoingToHide=false}else{if(this.isHiding){this.isHiding=false;this.doShow(true)}else{if(a.stopHidingOn!=this){var b=a.visibleSubs[a.visibleSubs.length-1];if(b!=this){a.stopHidingOn=this}}}}c.stopImmediatePropagation()},hide:function(c){if(this.isHiding||this.isGoingToHide){return}if(!this.isVisible()){this.menu.subToShowNext=null;clearTimeout(this.showTimer);return}var a=this.menu;a.stopHidingOn=null;var b=a.visibleSubs[a.visibleSubs.length-1];if(b!=this){return}this.isGoingToHide=true;var d=this;this.hideTimer=setTimeout(function(){d.doHide()},a.config.hideDelay);c.stopPropagation()},doShow:function(b){this.parseVisibleNotAncestors();var a=this.menu;if(a.config.beforeShow){a.config.beforeShow.call(this)}if(b){a.removeFromVisibleSubs(this)}a.visibleSubs.push(this);this.isShowing=true;liveMenu.Effect.In(this,a.config.effect,function(){this.isShowing=false;var c=this.menu;if(c.config.afterShow){c.config.afterShow.call(this)}if(c.subToShowNext){c.subToShowNext.doShow();c.subToShowNext=null}})},doHide:function(){if(this.hideTimer){clearTimeout(this.hideTimer);this.hideTimer=null}var a=this.menu;this.isShowing=false;this.isGoingToHide=false;this.isHiding=true;a.parseHidingSubs();if(a.config.beforeHide){a.config.beforeHide.call(this)}liveMenu.Effect.Out(this,function(){this.isHiding=false;var b=this.menu;if(this.parentSub){var c=b.visibleSubs[b.visibleSubs.length-1];if(c==this&&b.stopHidingOn!=this.parentSub&&!this.getVisibleNotAncestors().length){var d=true}}b.removeFromVisibleSubs(this);if(b.config.afterHide){b.config.afterHide.call(this)}if(d){this.parentSub.doHide()}})},hideWithoutEffect:function(){if(this.hideTimer){clearTimeout(this.hideTimer);this.hideTimer=null}liveMenu.Effect.destroy(this);this.container.style.display="none";this.isShowing=false;this.isHiding=false;this.isGoingToHide=false;var a=this.menu;a.subToShowNext=null;if(a.config.beforeHide){a.config.beforeHide.call(this)}a.removeFromVisibleSubs(this);if(a.config.afterHide){a.config.afterHide.call(this)}},parseVisibleNotAncestors:function(){var f=this.getVisibleNotAncestors();if(!f.length){return}if(f.length===1){if(!f[0].isHiding){f[0].doHide()}return}var e=this.parentSub||this.menu,c,b,a;for(var d=0;d<f.length;d++){c=f[d];b=c.parentSub||this.menu;if(b!=e){c.hideWithoutEffect()}else{if(!c.isHiding){a=c}}}if(a){a.doHide()}},getPosition:function(){var b=liveMenu.Utils,a=this.menu.config;sub=this.domNode;if(b.hasClass(sub,a.right)){return"right"}if(b.hasClass(sub,a.down)){return"down"}if(b.hasClass(sub,a.up)){return"up"}if(b.hasClass(sub,a.left)){return"left"}return null},getAncestors:function(){var b=[];var a=this.parentSub;while(a!=null){b.push(a);a=a.parentSub}return b},getVisibleNotAncestors:function(){var e=liveMenu.Utils;var d=[];var c=this.getAncestors();var b=this.menu.visibleSubs;c.push(this);for(var a=0;a<b.length;a++){if(e.indexOf(b[a],c)==-1){d.push(b[a])}}return d},isVisible:function(){return this.container.style.display=="block"}};liveMenu.Effect={effects:[],zIndex:100,Transitions:{linear:function(a){return a},sinoidal:function(a){return(-Math.cos(a*Math.PI)/2)+0.5}},loop:function(a,f,g){var d=a;if(f){d.direction=f;d.callback=g;if(d.intervalId){clearInterval(d.intervalId);d.intervalId=null}var b=(new Date()).getTime();d.startOn=d.finishOn?(2*b-d.finishOn):b;d.finishOn=d.startOn+d.duration;d.render(null);d.intervalId=setInterval(function(){liveMenu.Effect.loop(d)},d.interval)}else{var b=(new Date()).getTime();if(b>=d.finishOn){clearInterval(d.intervalId);d.intervalId=null;d.finishOn=d.startOn=null;d.render(1);d.callback.call(d.submenu)}else{var c=(b-d.startOn)/(d.finishOn-d.startOn);d.render(this.Transitions[d.transition](c))}}},In:function(b,a,c){if(this.effects[b.id]==null){this.effects[b.id]=new this[a](b)}b.container.style.zIndex=this.zIndex++;if(a=="plain"){this.effects[b.id].render("in");c.call(b)}else{this.loop(this.effects[b.id],"in",c)}},Out:function(a,b){if(this.effects[a.id].type=="plain"){this.effects[a.id].render("out");b.call(a)}else{this.loop(this.effects[a.id],"out",b)}},destroy:function(b){var a=this.effects[b.id];if(a&&a.intervalId){clearInterval(a.intervalId)}this.effects[b.id]=null},setContainerPos:function(a){var c=a.container.style;var b=this.getTargetCoords(a);c.left=b.left+"px";c.top=b.top+"px"},getTargetCoords:function(a){var c=liveMenu.Utils,b=a.opener;switch(a.position){case"right":return{left:c.getOffsetPos(b,"Left")+b.offsetWidth,top:c.getOffsetPos(b,"Top")};case"down":return{left:c.getOffsetPos(b,"Left"),top:c.getOffsetPos(b,"Top")+b.offsetHeight};case"left":return{left:c.getOffsetPos(b,"Left")-a.domNode.offsetWidth,top:c.getOffsetPos(b,"Top")};case"up":return{left:c.getOffsetPos(b,"Left"),top:c.getOffsetPos(b,"Top")-a.domNode.offsetHeight}}},setSubInitPos:function(b){var a=b.domNode;switch(b.position){case"right":a.style.left=-a.offsetWidth+"px";return;case"down":a.style.top=-a.offsetHeight+"px";return;case"left":a.style.left=a.offsetWidth+"px";return;case"up":a.style.top=a.offsetHeight+"px";return}}};liveMenu.Effect.plain=function(a){this.type="plain";this.container=a.container;liveMenu.Effect.setContainerPos(a)};liveMenu.Effect.plain.prototype={render:function(a){this.container.style.display=a=="in"?"disply":"none"}};liveMenu.Effect.fade=function(b){var a=b.menu.config;this.submenu=b;this.duration=a.duration;this.transition=a.transition;this.interval=100;liveMenu.Effect.setContainerPos(b);var c=b.container.style;c.opacity="0.0";c.zoom=1};liveMenu.Effect.fade.prototype={render:function(b){var c=this.submenu.container.style;if(b==null){if(!this.submenu.isVisible()){c.display="block";c.filter="alpha(opacity: 0)"}}else{var a=this.direction=="in"?b:1-b;a=a.toFixed(1);c.opacity=a;c.filter="alpha(opacity="+a*100+")";if(b===1&&this.direction=="out"){c.display="none"}}}};liveMenu.Effect.smooth=function(a){liveMenu.Effect.slide.call(this,a);var b=a.container.style;b.opacity="0.0";b.zoom=1;b.display="block";b.filter="alpha(opacity: 0)"};liveMenu.Effect.smooth.prototype={render:function(a){liveMenu.Effect.slide.prototype.render.call(this,a);if(a==null){this.prevProgress=0}else{if(a>=this.prevProgress+0.1||a==1){this.prevProgress=a;liveMenu.Effect.fade.prototype.render.call(this,a)}}}};liveMenu.Effect.slide=function(b){var a=b.menu.config;this.submenu=b;this.duration=a.duration;this.transition=a.transition;this.interval=20;liveMenu.Effect.setContainerPos(b);liveMenu.Effect.setSubInitPos(b);if(b.position=="left"||b.position=="right"){this.dimension="Width";this.axis="left";this.initCoord=parseInt(b.domNode.style.left)}else{this.dimension="Height";this.axis="top";this.initCoord=parseInt(b.domNode.style.top)}};liveMenu.Effect.slide.prototype={render:function(b){if(b==null){var d=this.submenu.container.style;if(!this.submenu.isVisible()){d.display="block"}}else{var f=b,c=this.submenu.domNode,a=c["offset"+this.dimension],e=this.direction=="out"?Math.floor(a*f):a-Math.floor(a*f);c.style[this.axis]=this.initCoord<0?(this.initCoord+e)+"px":(this.initCoord-e)+"px";if(f===1&&this.direction=="out"){this.submenu.container.style.display="none"}}}};liveMenu.event={elements:[],handlers:{},add:function(f,e,d,g){var h=liveMenu.Utils,a=h.indexOf(f,this.elements);if(a===-1){this.elements.push(f);a=this.elements.length-1;this.handlers[a]={}}if(!this.handlers[a][e]){this.handlers[a][e]=[];var c=e=="mouseenter"?"mouseover":e=="mouseleave"?"mouseout":e;var b=function(i){var j=new liveMenu.Event(i||window.event,e);liveMenu.event.handle.call(arguments.callee.elem,j)};b.elem=f;if(f.addEventListener){f.addEventListener(c,b,false)}else{if(f.attachEvent){f.attachEvent("on"+c,b)}else{f["on"+c]=b}}}f=null;if(g){this.handlers[a][e].unshift(d)}else{this.handlers[a][e].push(d)}},handle:function(h){var j=liveMenu.Utils,g=liveMenu.event,a=j.indexOf(this,g.elements),b=g.handlers[a][h.type];for(var c in b){var f=b[c];if(h.type=="mouseenter"||h.type=="mouseleave"){var d=h.relatedTarget;while(d&&d!=this){d=d.parentNode}if(d==this){return}}f.call(this,h);if(h.isImmediatePropagationStopped){return}}}};liveMenu.Event=function(b,a){this.originalEvent=b;this.type=a;if(b.relatedTarget){this.relatedTarget=b.relatedTarget}else{if(b.fromElement){this.relatedTarget=b.fromElement==b.srcElement?b.toElement:b.fromElement}}};liveMenu.Event.prototype={stopPropagation:function(){var a=this.originalEvent;a.stopPropagation?a.stopPropagation():a.cancelBubble=true},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=true;this.stopPropagation()},preventDefault:function(){var a=this.originalEvent;a.preventDefault?a.preventDefault():a.returnValue=false}};liveMenu.Utils={merge:function(b,a){if(!a){return b}for(var c in b){if(!a.hasOwnProperty(c)){a[c]=b[c]}}return a},hasClass:function(b,a){var c=new RegExp("(^|\\s)"+a+"(\\s|$)");if(b&&b.className&&c.test(b.className)){return true}return false},getOffsetPos:function(b,c){var a=0;while(b!=null){a+=b["offset"+c];b=b.offsetParent}return a},indexOf:function(b,a){if(Array.prototype.indexOf){return a.indexOf(b)}for(var c=0;c<a.length;c++){if(a[c]===b){return c}}return -1}};

  liveMenu.initOnLoad('navigation', { effect: 'smooth',
                beforeShow: function () { 
                    this.opener.className = 'lm-selected-item';
                },
                beforeHide: function () {
                    this.opener.className = '';
                }
            });

