/**
 * doijs package
 * 
 * @author donna iwan setiawan
 * @version 1.1 release 6
 * copyright - (c) 2007 - 2010 donna iwan setiawan
 * license - GPL version 3 or any later version <http://www.gnu.org/licenses/gpl-3.0.txt>
 */
doi.widget.menu=function(d){var e=[],c=[],b="doi-widget-menu",a=arguments[1]||{};a.attribute=a.attribute||{};a.attribute.layout=a.attribute.layout||"hv";this.render=function(){if(!d){e=doi.dom.$("tag:div;title=doi-widget-menu:true")}else{if(d.length){e=d}else{e=[d]}}if(!e||(e&&e.length==0)){return}for(var f=0;f<e.length;f++){var g=new doi.widget.menuBar(e[f],a);g.render();c.push(g)}};this.menus=function(){return c}};doi.widget.register(doi.widget.menu);doi.widget.menuBar=function(){var d=arguments[0],e=arguments[1]||{},a,f=false,k=[],h=this,j=doi.widget.instance.save(this,d.id),c=0,g=e.className||"doi-widget-menu",i=[],b=doi.widget.zIndex();function l(){if(f){return}if(!d||!(d&&doi.dom.isElement(d))){return}var q=d.getAttribute("title");var o={};o.className=(d.className)||g;g=o.className;o.attribute=doi.dom.parseAttribute(q);e=doi.dom.merge(e,o);a=e.attribute||{};if(doi.dom.isUndefined(a.nodeVisibility)){a.nodeVisibility=true}if(doi.dom.isUndefined(a.effect)){a.effect=false}if(e.attribute.title){d.setAttribute("title",e.attribute.title)}else{d.setAttribute("title","")}b=(a.zIndex)||b;for(var p=0;p<d.childNodes.length;p++){if(d.childNodes[p].nodeName=="UL"){for(var n=0;n<d.childNodes[p].childNodes.length;n++){if(d.childNodes[p].childNodes[n].nodeName=="LI"){var m=new doi.widget.menuItem(d.childNodes[p].childNodes[n]);h.addItem(m);m.parent(h)}}}}doi.event.add(document,"click",function(){h.hide()});f=true}this.attribute=function(){return e.attribute};this.layout=function(){return e.attribute.layout.charAt(0)};this.level=function(){if(doi.dom.isUndefined(arguments[0])){c=doi.dom.parseInt(arguments[0])}return c};this.element=function(){return d};this.registerFrame=function(o,m){var p=m.level()-1;if(i[p]&&i[p].object==m){return}for(var n=i.length-1;n>=p;n--){i[n].object.hide();i.pop()}i.push({object:m,element:o})};this.hide=function(){for(var m=i.length-1;m>=0;m--){i[m].object.hide();i.pop()}};this.render=function(){var s=c+1;h.element().innerHTML="";var r=h.element();if(/^h/i.test(e.attribute.layout)){var o=document.createElement("table");o.setAttribute("border",0);o.setAttribute("cellPadding",0);o.setAttribute("cellSpacing",0);var m=document.createElement("tbody");var p=document.createElement("tr");r.appendChild(o);o.appendChild(m);m.appendChild(p)}for(var n=0;n<h.items().length;n++){if(/^h/i.test(e.attribute.layout)){var q=document.createElement("td");p.appendChild(q)}else{var q=r}h.items()[n].effect(a.effect);h.items()[n].nodeVisibility(a.nodeVisibility);h.items()[n].className(g+"-item");h.items()[n].frameClassName(g+"-frame");h.items()[n].layout(e.attribute.layout.charAt(0));h.items()[n].level(s);h.items()[n].menuBar(h);h.items()[n].zIndex(b);h.items()[n].render(q)}r.id=j;doi.dom.className(r,g);d=r};this.hasItem=function(){return(k.length>0)};this.items=function(){return k};this.addItem=function(m){k.push(m)};l()};doi.widget.menuItem=function(){var o,p=this,j=arguments[0],e=false,l="",i="",n,c=[],d=doi.widget.instance.save(this),b,m=0,r=null,a="doi-widget-menu-item",f="doi-widget-menu-frame",t=0,g="h",h=true,k=false,s;function q(){if(e){return}if(!j||!(j&&doi.dom.isElement(j))){return}if(j.nodeName=="LI"){for(var w=0;w<j.childNodes.length;w++){if(j.childNodes[w].nodeName=="A"){n=j.childNodes[w].cloneNode(false);for(var v=0;v<j.childNodes[w].childNodes.length;v++){if(j.childNodes[w].childNodes[v].nodeName=="IMG"){i=doi.dom.outerHTML(j.childNodes[w].childNodes[v])}else{if(j.childNodes[w].childNodes[v].nodeName=="#text"){l+=j.childNodes[w].childNodes[v].nodeValue}else{l+=doi.dom.outerHTML(j.childNodes[w].childNodes[v])}}}}else{if(j.childNodes[w].nodeName=="UL"){for(var v=0;v<j.childNodes[w].childNodes.length;v++){if(j.childNodes[w].childNodes[v].nodeName=="LI"){var u=new doi.widget.menuItem(j.childNodes[w].childNodes[v]);p.addItem(u);u.parent(p)}}}}}}e=true}this.effect=function(){if(doi.dom.isDefined(arguments[0])){s=arguments[0]}return s};this.nodeVisibility=function(){if(doi.dom.isDefined(arguments[0])){h=!!(arguments[0])}return h};this.layout=function(){if(doi.dom.isDefined(arguments[0])){g=arguments[0]}return g};this.zIndex=function(){if(doi.dom.isDefined(arguments[0])){t=doi.dom.parseInt(arguments[0])}return t};this.menuBar=function(){if(arguments[0]){o=arguments[0]}return o};this.level=function(){if(doi.dom.isDefined(arguments[0])){m=doi.dom.parseInt(arguments[0])}return m};this.parent=function(){if(doi.dom.isObject(arguments[0])){r=arguments[0]}return r};this.hide=function(){window.clearInterval(k);k=false;if(p.frame()){p.frame().hide()}doi.dom.removeClass(p.element(),a+"-hover")};this.show=function(B){doi.dom.addClass(B,a+"-hover");if(p.hasItem()){var A=doi.dom.dimension.absolutePosition(B);var D=B.offsetWidth;var z=B.offsetHeight;var G=p.frame().height();var y=p.frame().width();var E=doi.dom.dimension.bodyScroll();var u=doi.dom.dimension.client();var x=(doi.dom.screen.height()>u.height)?doi.dom.screen.height():u.height;var C=(doi.dom.screen.width()>u.width)?doi.dom.screen.width():u.width;if(p.layout()=="h"){var F=A.top+z;var v=A.left;if(F+G-E.scrollTop>u.height){if(A.top-G>0){F=A.top-G}}if(v+y-E.scrollLeft>u.width){v-=(v+y-E.scrollLeft-u.width)+20;if(v<E.scrollLeft){v=E.scrollLeft}}}else{var F=A.top;var v=A.left+B.offsetWidth;if(F+G-E.scrollTop>u.height){F-=(F+G-E.scrollTop-u.height)+20;if(F<E.scrollTop){F=E.scrollTop}}if(v+y-E.scrollLeft>u.width){if(A.left-y>0){v=A.left-y}}}p.frame().show({top:F,left:v})}p.menuBar().registerFrame(B,p)};this.className=function(){if(arguments[0]){a=arguments[0]}return a};this.frameClassName=function(){if(arguments[0]){f=arguments[0]}return f};this.render=function(F){var v=document.createElement("div");j=v;if(F){F.appendChild(j)}else{doi.dom.write(j)}if(p.title()=="-"){var H=document.createElement("hr");if(p.layout()=="h"){doi.dom.className(H,a+"-hseparator");doi.dom.className(v,a+"-hseparator")}else{doi.dom.className(H,a+"-separator");doi.dom.className(v,a+"-separator")}v.appendChild(H);return}doi.event.add(v,"mouseover",function(K){var J=this;if(!k){k=window.setInterval(function(){p.show(J)},1)}});doi.event.add(v,"mouseout",function(K){var J=doi.event.toTarget(K);if(!J){return}while((J!=this)&&(J.nodeName)&&(J.nodeName!="BODY")&&(J.nodeName!="HTML")){J=J.parentNode}if(J==this){return}if(p.frame()&&p.frame().visible()){}else{doi.dom.removeClass(this,a+"-hover")}});var I=document.createElement("table");I.setAttribute("border","0");I.setAttribute("cellPadding","0");I.setAttribute("cellSpacing","0");I.setAttribute("width","100%");I.setAttribute("height","100%");var B=document.createElement("tbody");var D=document.createElement("tr");var z=document.createElement("td");z.innerHTML=p.icon();var y=document.createElement("td");p.element("link").innerHTML=p.title();y.appendChild(p.element("link"));var w=document.createElement("td");if(p.hasItem()){if(p.nodeVisibility()){if(p.layout()=="h"){w.innerHTML="&#9660;"}else{w.innerHTML="&#9658;"}}else{w.innerHTML="&nbsp;"}b=new doi.widget.layer(false,{id:d+"-layer",position:"fixed",className:f,zIndex:t,visibility:"hidden",effect:s});b.render();var u=m+1;if(p.menuBar().attribute().layout.charAt(1)=="h"){var x=document.createElement("table");x.setAttribute("border",0);x.setAttribute("cellPadding",0);x.setAttribute("cellSpacing",0);var E=document.createElement("tbody");var G=document.createElement("tr");p.frame().element().appendChild(x);x.appendChild(E);E.appendChild(G)}for(var A=0;A<p.items().length;A++){p.items()[A].effect(p.effect());p.items()[A].nodeVisibility(p.nodeVisibility());p.items()[A].className(p.frameClassName()+"-item");p.items()[A].frameClassName(p.frameClassName());p.items()[A].layout(p.menuBar().attribute().layout.charAt(1));p.items()[A].level(u);p.items()[A].menuBar(p.menuBar());p.items()[A].zIndex(t+1);if(p.menuBar().attribute().layout.charAt(1)=="h"){var C=document.createElement("td");G.appendChild(C)}else{var C=b.element()}p.items()[A].render(C)}b.resize();doi.dom.className(w,a+"-node-parent")}else{w.innerHTML="&nbsp;";doi.dom.className(w,a+"-node")}doi.dom.className(v,a);doi.dom.className(z,a+"-icon");doi.dom.className(y,a+"-title");v.appendChild(I);I.appendChild(B);B.appendChild(D);D.appendChild(z);D.appendChild(y);D.appendChild(w)};this.frame=function(){return b};this.element=function(){if(arguments[0]=="link"){return n}return j};this.addItem=function(u){c.push(u)};this.title=function(){if(l==""){l="&nbsp;"}return l};this.icon=function(){if(i==""){i="&nbsp;"}return i};this.hasItem=function(){return(c.length>0)};this.items=function(){return c};q()};
