/*
 * @filename:	pws_dropdownmenu.js
 * @version:	0.1
 * @revision:	1
 * @project:	PWS
 *
 * @author:		Giulio D'Ambrosio <giulio.dambrosio@poste.it>
 * @created:	28/mag/08
 * @modified:	28/mag/08 13:00:38
 *
 * @copyright:	2006-2008	Giulio D'Ambrosio @ PWS
 *
 * @desc:	Estensione per menu a comparsa
 *
 * @TODO:		
 */
function pws_DropDownMenu(id,C,o,G,B,l){this.af='vertical';this.ai={"show":0,"hide":400};this.H={"show":0,"hide":100};this.position={"level1":{"top":0,"left":0},"levelX":{"top":0,"left":0}};this.zIndex={"visible":500,"hidden": -1};this.T={"ie":Boolean(document.body.currentStyle),"ie5":(navigator.appVersion.indexOf("MSIE 5.5")!= -1||navigator.appVersion.indexOf("MSIE 5.0")!= -1),"ie6":(navigator.appVersion.indexOf("MSIE 6.0")!= -1)};this.R=0;this.J=[];this.t=[];this.U=[];this.M=[];this.v=[];this.av=0;this.C=false;this.o=false;this.G=false;this.B=false;this.l=false;this.id=id;var self=this;if(!self.T.ie){self.T.ie5=false;self.T.ie6=false;}function attachEvent(element,ad,handler){Event.observe(element,ad,handler);return;if(element.addEventListener)element.addEventListener(ad,handler,false);else element.attachEvent("on"+ad,handler);};function ar(f){var j=$(f);while(j&& !j.Q){self.M[self.J.indexOf(j.id)]++;self.v[self.t.indexOf(j.id)]++;j=j.O;}setTimeout(function(a,b){return function(){an(a);}}(f),self.ai.show);};function aq(f){var j=$(f);while(j&& !j.Q){self.M[self.J.indexOf(j.id)]--;self.v[self.t.indexOf(j.id)]--;j=j.O;}setTimeout(function(a,b){return function(){an(a);}}(f),self.ai.hide);};function I(am){var el=$(am);if(self.v[self.t.indexOf(am)]>0){if(self.C&&(el.tagName=='LI'||el.tagName=='A')){el.className=self.C;}}else{if(self.o&&(el.tagName=='LI'||el.tagName=='A')){el.className=self.o;}}};function as(f){var el=$(f);if(el.tagName!='UL')return;if(!self.U.contains(f)){self.U.push(f);}el.isOpen=true;el.style.position='absolute';el.style.display='block';el.style.visibility='visible';el.style.zIndex=self.zIndex.visible+el.P;var position=Element.positionedOffset(el.parentNode);el.style.top=position.top+"px";el.style.left=(position.left+Element.getWidth(el.parentNode)-10)+"px";};function at(f){var el=$(f);if(el.tagName!='UL')return;if(f==self.U.al()){self.U.pop();}el.isOpen=false;el.style.display='none';el.style.visibility='hidden';el.style.zIndex=self.zIndex.hidden;};function an(f){if(!self.J.contains(f))return;var ao;var j=$(f);while(j&& !j.Q){ao=self.M[self.J.indexOf(f)];if(ao>0){as(f);}else{at(f);}j=j.O;}};function ae(evt){var g=Event.element(evt);var f=false;if(g.L){f=g.L.id;}else if(g.m){f=g.m.id;}self.v[self.t.indexOf(g.id)]++;if(g.F){var k=g.F;var c;while(k){self.v[self.t.indexOf(k.id)]++;setTimeout(function(a,b){return function(){I(a);}}(k.id),self.H.show);c=k.firstChild;while(c){if(c.tagName=='A'){self.v[self.t.indexOf(c.id)]++;setTimeout(function(a,b){return function(){I(a);}}(c.id),self.H.show);}c=c.nextSibling;}k=(k.m&&k.m.D)?k.m.D:false;}}if(g.tagName=='LI'||g.tagName=='A'){setTimeout(function(a,b){return function(){I(a);}}(g.id),self.H.show);}if(f){ar(f);}};function V(evt){var g=Event.element(evt);var f=false;if(g.L){f=g.L.id;}else if(g.m){f=g.m.id;}self.v[self.t.indexOf(g.id)]--;if(g.F){var k=g.F;var c;while(k){self.v[self.t.indexOf(k.id)]--;setTimeout(function(a,b){return function(){I(a);}}(k.id),self.H.show);c=k.firstChild;while(c){if(c.tagName=='A'){self.v[self.t.indexOf(c.id)]--;setTimeout(function(a,b){return function(){I(a);}}(c.id),self.H.show);}c=c.nextSibling;}k=(k.m&&k.m.D)?k.m.D:false;}}if(g.tagName=='LI'||g.tagName=='A'){setTimeout(function(a,b){return function(){I(a);}}(g.id),self.H.hide);}if(f){aq(f);}};function ah(el,P){var i,c,d,r;var A,ag,ac;var aa;el.id='j-'+self.R++;if(self.R==1){el.D=false;el.m=false;el.F=false;el.O=false;el.Q=true;el.isOpen=true;el.style.display='block';el.zIndex=self.zIndex.visible;if(self.l){el.className=self.l;}if(!self.T.ie){el.style.overflowX='hidden';}}else{el.Q=false;el.isOpen=false;el.style.display='none';el.style.position='absolute';el.style.whiteSpace='nowrap';el.style.zIndex=self.zIndex.hidden;if(self.B){el.className=self.B;}}el.au=true;el.P=P;el.A=0;c=el.firstChild;while(c){if(c.nodeType!=1||c.tagName!='LI'){c=c.nextSibling;continue;}el.A++;c.id='item-'+self.R++;self.v.push(0);self.t.push(c.id);c.D=false;c.m=el;c.F=el.parentNode.tagName=='LI'?el.parentNode:false;if(self.o){c.className=self.o;}d=c.firstChild;A=new Array();aa=false;while(d){if(d.nodeType!=1){d=d.nextSibling;continue;}switch(d.tagName){case 'UL':aa=d;c.L=d;d.D=c;d.m=false;d.F=false;d.O=el;c.style.zIndex=self.zIndex.hidden;attachEvent(c,'mouseover',ae);attachEvent(c,'mouseout',V);ah(d,P+1);self.M.push(0);self.J.push(d.id);break;default:case 'A':d.id='item-'+self.R++;self.v.push(0);self.t.push(d.id);A.push(d);if(self.o){d.className=self.o;}d.F=el.parentNode.tagName=='LI'?el.parentNode:false;d.D=c;d.m=el;attachEvent(d,'mouseover',ae);attachEvent(d,'mouseout',V);ac=ak(d,c);for(i=0;i<ac.length;i++){A.push(ac[i]);}break;}d=d.nextSibling;}while(A.length){ag=A.pop();ag.L=aa;}c=c.nextSibling;}};function ak(d,c){var r=d.firstChild;A=new Array();while(r){if(r.nodeType!=1){r=r.nextSibling;continue;}r.D=c;A.push(r);attachEvent(r,'mouseover',ae);attachEvent(r,'mouseout',V);self.v.push(0);self.t.push(r.id);ak(r,c);r=r.nextSibling;}return A;};function aw(C,o,G,B,l){if(typeof l!="undefined"){self.C=C;}if(typeof l!="undefined"){self.o=o;}if(typeof l!="undefined"){self.G=G;}if(typeof l!="undefined"){self.B=B;}if(typeof l!="undefined"){self.l=l;}};function ab(){if(!$(self.id)){return alert("pws_DropDownMenu.ab() failed. Element '"+self.id+"' does not exist.");}if(self.af!="horizontal"&&self.af!="vertical"){return alert("pws_DropDownMenu.ab() failed. Unknown menu type: '"+self.type+"'");}var ap=$(self.id).getElementsByTagName('ul');ah(ap[0],0);};if(typeof C!="undefined"){self.C=C;}if(typeof o!="undefined"){self.o=o;}if(typeof G!="undefined"){self.G=G;}if(typeof B!="undefined"){self.B=B;}if(typeof l!="undefined"){self.l=l;}ab();};function ax(str){var K=$('debugdiv');if(!K)return;K.innerHTML=K.innerHTML+str+'<br/>';if(K.innerHTML.length>250){K.innerHTML='<p>'+str+'</p>';}};if(typeof Array.prototype.indexOf=="undefined"){Array.prototype.indexOf=function(item){for(var i=0;i<this.length;i++){if(this[i]===item){return i;}}return-1;}}if(typeof Array.prototype.al=="undefined"){Array.prototype.al=function(){return this[this.length-1];}}if(typeof Array.prototype.contains=="undefined"){Array.prototype.contains=function(s){for(var i=0;i<this.length;i++){if(this[i]===s){return true;}}return false;}}