Picker.Attach=new Class({Extends:Picker,options:{togglesOnly:!0,showOnInit:!1,blockKeydown:!0},initialize:function(a,b){var c,d,e;this.parent(b),this.attachedEvents=[],this.attachedElements=[],this.toggles=[],this.inputs=[];c=function(a){if(this.attachedElements.contains(a.target))return;this.close()}.bind(this),d=this.picker.getDocument().addEvent("click",c),e=function(a){return a.stopPropagation(),!1};this.picker.addEvent("click",e),this.options.toggleElements&&(this.options.toggle=d.getElements(this.options.toggleElements)),this.attach(a,this.options.toggle)},attach:function(a,b){var c,d,e,f,g,h,i;typeOf(a)=="string"&&(a=document.id(a)),typeOf(b)=="string"&&(b=document.id(b));c=Array.from(a),d=Array.from(b),e=[].append(c).combine(d),f=this,g=function(a){var b=f.options.blockKeydown&&a.type=="keydown"&&!["tab","esc"].contains(a.key),c=a.type=="keydown"&&["tab","esc"].contains(a.key),d=a.target.get("tag")=="a";(b||d)&&a.preventDefault(),(c||d)&&f.close()},h=function(a){return function(b){var c=b.target.get("tag");if(c=="input"&&b.type=="click"&&!a.match(":focus")||f.opened&&f.input==a)return;c=="a"&&b.stop(),f.position(a),f.open(),f.fireEvent("attached",[b,a])}},i=function(a,b){return function(c){f.opened?b(c):a(c)}};return e.each(function(a){var b,c,e,j;if(f.attachedElements.contains(a))return;b={},c=a.get("tag"),e=h(a),j=i(e,g);if(c=="input"){if(!f.options.togglesOnly||!d.length)b={focus:e,click:e,keydown:g};f.inputs.push(a)}else d.contains(a)?(f.toggles.push(a),b.click=j):b.click=e;a.addEvents(b),f.attachedElements.push(a),f.attachedEvents.push(b)}),this},detach:function(a,b){var c,d,e,f;typeOf(a)=="string"&&(a=document.id(a)),typeOf(b)=="string"&&(b=document.id(b));c=Array.from(a),d=Array.from(b),e=[].append(c).combine(d),f=this;return e.length||(e=f.attachedElements),e.each(function(a){var c,d,e,b=f.attachedElements.indexOf(a);if(b<0)return;c=f.attachedEvents[b];a.removeEvents(c),delete f.attachedEvents[b],delete f.attachedElements[b];d=f.toggles.indexOf(a);d!=-1&&delete f.toggles[d];e=f.inputs.indexOf(a);d!=-1&&delete f.inputs[e]}),this},destroy:function(){return this.detach(),this.parent()}})