/**
 * LiveMenu, version 1.1
 *
 * Copyright (c) 2009-2010 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:500,showOn:"mouseenter",effect:"plain",mode:"simultaneous",duration:400,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.showOn=="click"){this.config.showDelay=0}if(this.config.effect=="plain"||this.config.maxHidingSubmenus==0){this.config.mode="consecutive"}this.id=e;this.domNode=document.getElementById(e);this.orientation=this.getOrientation();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(a){var b=liveMenu.Utils;this.visibleSubs.splice(b.indexOf(a,this.visibleSubs),1)},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()}}},getGroupToShow:function(c){var b=c.getAncestors();var d=[c];for(var a in b){if(b[a].isHiding){d.unshift(b[a])}}return d},getGroupToHide:function(c){var b=c.getAncestors();var d=[c];for(var a=0;b[a]&&b[a]!=this.stopHidingOn;a++){d.unshift(b[a])}return d},getOrientation:function(d){var c=liveMenu.Utils,a=this.config,b=d||this.domNode;if(c.hasClass(b,a.horizontalClassName)){return"horizontal"}if(c.hasClass(b,a.verticalClassName)){return"vertical"}return null}};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.orientation=a.getOrientation(b);this.hideTimer=null;this.showTimer=null;this.isShowing=false;this.isHiding=false;this.isSetToHide=false;this.addEventListeners()};liveMenu.Submenu.prototype={addEventListeners:function(){var f=liveMenu.event,a=this.menu.config.showOn;var g=this;f.add(this.opener,a,function(h){g.show(h)},true);f.add(this.opener,a,function(h){g.cancelHide(h)},true);f.add(this.opener,"mouseleave",function(h){g.hide(h)});f.add(this.domNode,"mouseleave",function(h){g.hide(h)});var c=this.domNode.childNodes;for(var b=0;b<c.length;b++){if(c[b].tagName=="LI"){f.add(c[b],"mouseenter",function(h){g.cancelHide(h)})}}if(a=="click"){var d=this.opener.getElementsByTagName("A");for(b=0;b<d.length;b++){f.add(d[b],"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(g){if(!this.isVisible()){return}var f=this.getAncestors();for(var c=0;c<f.length;c++){var d=f[c];clearTimeout(d.hideTimer);d.hideTimer=null;d.isSetToHide=false}var a=this.menu;if(this.isSetToHide){clearTimeout(this.hideTimer);this.hideTimer=null;this.isSetToHide=false;a.stopHidingOn=this}else{if(this.isHiding){a.stopHidingOn=this.parentSub;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}}}}g.stopImmediatePropagation()},hide:function(c){if(this.isHiding||this.isSetToHide){return}if(!this.isVisible()){this.menu.subToShowNext=null;clearTimeout(this.showTimer);return}var a=this.menu;a.stopHidingOn=null;if(a.config.mode=="consecutive"){var b=a.visibleSubs[a.visibleSubs.length-1];if(b!=this){return}}this.isSetToHide=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(b){a.removeFromVisibleSubs(this)}a.visibleSubs.push(this);var d=a.config.mode=="simultaneous"?a.getGroupToShow(this):[this];for(var c in d){d[c].isShowing=true;d[c].isHiding=false;if(a.config.beforeShow){a.config.beforeShow.call(d[c])}}liveMenu.Effect.In(d,a.config.effect,function(){var h,g=false,e;if(!this.subIDs){h=this.submenu;h.isShowing=false;g=true;e=h.menu;if(e.config.afterShow){e.config.afterShow.call(h)}}else{e=this.effects[this.subIDs[0]].submenu.menu;for(var f in this.effects){h=this.effects[f].submenu;h.isShowing=false;if(e.config.afterShow){e.config.afterShow.call(h)}}}if(e.subToShowNext&&(g||e.subToShowNext.parentSub.id in this.effects)){e.subToShowNext.doShow();e.subToShowNext=null}})},doHide:function(){var a=this.menu,d,c;if(a.config.mode=="simultaneous"){d=a.getGroupToHide(this);c=false}else{d=[this];c=a.config.maxHidingSubmenus==0?true:false}for(var b in d){clearTimeout(d[b].hideTimer);d[b].hideTimer=null;d[b].isHiding=true;d[b].isSetToHide=false;d[b].isShowing=false;if(a.config.beforeHide){a.config.beforeHide.call(d[b])}}if(a.config.mode!="simultaneous"&&!c){a.parseHidingSubs()}liveMenu.Effect.Out(d,function(){var e,h,g;if(this.subIDs){e=this.effects[this.subIDs[0]].submenu.menu;for(g in this.effects){h=this.effects[g].submenu;h.isHiding=false;e.removeFromVisibleSubs(h);if(e.config.afterHide){e.config.afterHide.call(h)}}return}h=this.submenu;h.isHiding=false;e=h.menu;if(h.parentSub){var f=e.visibleSubs[e.visibleSubs.length-1];if(f==h&&e.stopHidingOn!=h.parentSub&&!h.getVisibleNotAncestors().length){var i=true}}e.removeFromVisibleSubs(h);if(e.config.afterHide){e.config.afterHide.call(h)}if(i){h.parentSub.doHide()}},c)},hideWithoutEffect:function(){if(this.hideTimer){clearTimeout(this.hideTimer);this.hideTimer=null}liveMenu.Effect.destroy(this);this.container.style.visibility="hidden";this.isShowing=false;this.isHiding=false;this.isSetToHide=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 d=this.getVisibleNotAncestors();if(!d.length){return}var c=this.menu;if(c.config.mode=="simultaneous"){var a=liveMenu.Utils,e=c.visibleSubs[c.visibleSubs.length-1];if(!e.isHiding&&a.indexOf(e,d)!=-1){e.doHide()}for(var f=0;f<d.length;f++){if(!d[f].isHiding){d[f].doHide()}}return}if(d.length===1){if(!d[0].isHiding){d[0].doHide()}return}var h=this.parentSub||c,b,j,g;for(var f=0;f<d.length;f++){b=d[f];j=b.parentSub||c;if(j!=h){b.hideWithoutEffect()}else{if(!b.isHiding){g=b}}}if(g){g.doHide()}},getPosition:function(){var c=liveMenu.Utils,a=this.menu.config,b=this.domNode;if(c.hasClass(b,a.right)){return"right"}if(c.hasClass(b,a.down)){return"down"}if(c.hasClass(b,a.up)){return"up"}if(c.hasClass(b,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.visibility=="visible"}};liveMenu.Effect={effects:{},groups:[],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)}else{var c=(b-d.startOn)/(d.finishOn-d.startOn);d.render(this.Transitions[d.transition](c))}}},getGroupIndex:function(a){for(var b in this.groups){if(this.groups[b].id==a){return b}}return null},getSubIDs:function(b){var a=[];for(var c=0;c<b.length;c++){a.push(b[c].id)}return a},getGrpID:function(a){return a.join(" ")+" "},In:function(l,g,k){var c=l[0].menu,e;this.zIndex++;for(e in l){l[e].container.style.zIndex=this.zIndex}if(c.config.mode=="simultaneous"){var b=liveMenu.Utils,j,h=this.getSubIDs(l),d=this.getGrpID(h);for(e in this.groups){j=this.groups[e];if(d.indexOf(j.id)==-1&&b.indexOf(h[h.length-1],j.subIDs)!=-1){j.divide(h[h.length-1]);break}}var f=true;for(e in this.groups){j=this.groups[e];if(d.indexOf(j.id)!=-1){this.loop(j,"in",k);f=false}}if(f){this.groups.push(new this.group(d,h,l,g));this.loop(this.groups[this.groups.length-1],"in",k)}}else{var a=l[0];if(this.effects[a.id]==null){this.effects[a.id]=new this[g](a)}if(g=="plain"){this.effects[a.id].render("in");k.call(this.effects[a.id])}else{this.loop(this.effects[a.id],"in",k)}}},Out:function(q,d,b){var p=q[0].menu;if(p.config.mode=="consecutive"){var n=q[0];if(b){this.destroy(n);this.effects[n.id]=new this.plain(n)}var t=this.effects[n.id];if(t.type=="plain"){t.render("out");d.call(t);if(b){this.destroy(n)}}else{this.loop(this.effects[n.id],"out",d)}return}var c=liveMenu.Utils,j,g=q,o=this.getSubIDs(g),v=this.getGrpID(o),u=[];for(var h=0,r=this.groups.length;h<r;h++){j=this.groups[h];if(v!=j.id){if(j.direction=="in"&&j.id.indexOf(v)!=-1){var f=o[0],k=c.indexOf(f,j.subIDs)-1;j.divide(j.subIDs[k])}else{intersect=this.getGroupsIntersection(o,j.subIDs);if(intersect.length){var a=j.subIDs,x=o;if(c.indexOf(a[a.length-1],x)!=-1&&c.indexOf(a[0],x)==-1){j.divide(a[c.indexOf(x[0],a)-1]);j=this.groups[this.groups.length-1]}this.loop(j,"out",d);u=u.concat(intersect)}}}}for(var s in u){var w=c.indexOf(u[s],o);if(w!=-1){g.splice(w,1);o=this.getSubIDs(g)}}if(!g.length){return}v=this.getGrpID(o);if(!(h=this.getGroupIndex(v))){this.groups.push(new this.group(v,o,g));h=this.groups.length-1}this.loop(this.groups[h],"out",d)},getGroupsIntersection:function(b,c){var e=liveMenu.Utils,d=e.indexOf(b[0],c),a=[];if(d!=-1){a=c.slice(d,d+b.length)}else{d=e.indexOf(c[0],b);if(d!=-1){a=b.slice(d,d+c.length)}}return a},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.submenu=a;this.container=a.container;liveMenu.Effect.setContainerPos(a)};liveMenu.Effect.plain.prototype={render:function(a){this.container.style.visibility=a=="in"?"visible":"hidden"}};liveMenu.Effect.group=function(b,d,e,h){var g=e[0].menu.config;this.subIDs=d;this.id=b;this.duration=g.duration;this.transition=g.transition;this.interval=20;if(typeof(h)=="object"){this.effects=h}else{var j=h,c=liveMenu.Effect.effects;this.effects={};for(var f=0;f<e.length;f++){var a=e[f];if(!(a.id in c)){c[a.id]=new liveMenu.Effect[j](a)}this.effects[a.id]=c[a.id]}}};liveMenu.Effect.group.prototype={render:function(b){var a,c=this.effects;if(b==null){for(a in c){c[a].direction=this.direction}}for(a in c){if(c[a]){c[a].render(b)}}if(b==1){var d=liveMenu.Effect.getGroupIndex(this.id);liveMenu.Effect.groups.splice(d,1)}},divide:function(a){var j=[],i=[],n={},m={},b=j,d=n;for(var g in this.effects){b.push(this.effects[g].submenu);d[g]=this.effects[g];if(g==a){b=i;d=m}}var c=liveMenu.Effect.getGroupIndex(this.id),h=liveMenu.Effect.getSubIDs(j),f=liveMenu.Effect.getSubIDs(i),l=liveMenu.Effect.getGrpID(h),o=liveMenu.Effect.getGrpID(f);if(this.direction=="in"){this.subIDs=h;this.id=l;this.effects=n}else{this.subIDs=f;this.id=o;this.effects=m}var k=liveMenu.Effect;k.groups.push(this);k.groups.splice(c,1);k.groups.push(this.direction=="in"?new k.group(o,f,i,m):new k.group(l,h,j,n));k.groups[k.groups.length-1].finishOn=this.finishOn}};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.visibility="visible";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){if(this.direction=="out"){c.visibility="hidden"}else{c.filter=""}}}}};liveMenu.Effect.smooth=function(a){liveMenu.Effect.slide.call(this,a);var b=a.container.style;b.opacity="0.0";b.zoom=1;b.visibility="visible";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.condData={initCoord:parseInt(b.domNode.style.left),x1:b.position=="left"?-b.container.offsetWidth:b.opener.offsetWidth,x2:"up",x3:"offsetTop",x4:"offsetHeight",x5:"down",x6:"Top",x7:"Left",x8:"top",x9:"left",x10:"horizontal",x11:"offsetWidth"}}else{this.condData={initCoord:parseInt(b.domNode.style.top),x1:b.position=="up"?-b.container.offsetHeight:b.opener.offsetHeight,x2:"left",x3:"offsetLeft",x4:"offsetWidth",x5:"right",x6:"Left",x7:"Top",x8:"left",x9:"top",x10:"vertical",x11:"offsetHeight"}}};liveMenu.Effect.slide.prototype={render:function(b){if(b==null){var o=this.submenu.container.style;if(!this.submenu.isVisible()){o.visibility="visible"}}else{var i=liveMenu.Utils,m=this.condData,a=this.submenu,k=a.domNode,q=a.opener,e=a.container,s=a.parentSub,l=this.direction=="in"?Math.floor(k[m.x11]*b):k[m.x11]-Math.floor(k[m.x11]*b);if(s){var r=s.domNode,n=true;if(s.position==m.x2){n=r[m.x3]<=r[m.x4]-q[m.x3]-q[m.x4]}else{if(s.position==m.x5){n=r[m.x3]*-1<=q[m.x3]}}if(n){var f=i.getOffsetPos(q,m.x6);e.style[m.x8]=f+"px"}else{var h=s.parentSub;if(h&&h.orientation==m.x10){var g=h.domNode,j=i.getOffsetPos(g,m.x6);e.style[m.x8]=s.position==m.x2?(j-g[m.x4])+"px":(j+g[m.x4])+"px"}}e.style[m.x9]=(i.getOffsetPos(q,m.x7)+m.x1)+"px"}k.style[m.x9]=m.initCoord<0?(m.initCoord+l)+"px":(m.initCoord-l)+"px";if(b===1&&this.direction=="out"){e.style.visibility="hidden"}}}};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}};

