var KeyNavList=Class.create({initialize:function(e,c){var b=this.onClick.bindAsEventListener(this),f,d=0,a=this.onHover.bindAsEventListener(this);this.element=$(e);this.options=c||{};this.index=-1;this.entryCount=this.element.firstDescendant().childElements().size();for(;d<this.entryCount;d++){f=this.getEntry(d);f.writeAttribute("autocompleteIndex",d);f.observe("click",b);f.observe("mouseover",a)}this.options.onShow=this.options.onShow||function(g){new Effect.Appear(g,{duration:0.15})};this.options.onHide=this.options.onHide||function(g){new Effect.Fade(g,{duration:0.15})};this.element.observe("blur",this.onBlur.bind(this));document.observe("keypress",this.onKeyPress.bindAsEventListener(this))},show:function(){this.active=true;if(!this.element.visible()){this.options.onShow(this.element)}if(!this.iefix&&(navigator.appVersion.indexOf("MSIE")>0)&&(this.element.getStyle("position")=="absolute")){this.element.insert({after:'<iframe id="'+this.element.id+'_iefix" style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="javascript:false;" frameborder="0" scrolling="no"></iframe>'});this.iefix=$(this.element.id+"_iefix")}if(this.iefix){setTimeout(this.fixIEOverlapping.bind(this),50)}},fixIEOverlapping:function(){this.iefix.clonePosition(this.element).setStyle({zIndex:1}).show();this.element.setStyle({zIndex:2})},hide:function(){this.active=false;this.stopIndicator();if(this.element.visible()){this.options.onHide(this.element)}if(this.iefix){this.iefix.hide()}},startIndicator:function(){if(this.options.indicator){$(this.options.indicator).show()}},stopIndicator:function(){if(this.options.indicator){$(this.options.indicator).hide()}},onKeyPress:function(a){if(!this.active){return}switch(a.keyCode){case Event.KEY_TAB:case Event.KEY_RETURN:this.selectEntry();a.stop();case Event.KEY_ESC:this.hide();this.active=false;a.stop();return;case Event.KEY_LEFT:case Event.KEY_RIGHT:return;case Event.KEY_UP:this.markPrevious();this.render();a.stop();return;case Event.KEY_DOWN:this.markNext();this.render();a.stop();return}},onHover:function(c){var b=c.findElement("LI"),a=parseInt(b.readAttribute("autocompleteIndex"));if(this.index!=a){this.index=a;this.render()}c.stop()},onClick:function(b){var a=b.findElement("LI");this.index=parseInt(a.readAttribute("autocompleteIndex"));this.selectEntry();this.hide();b.stop()},onBlur:function(){setTimeout(this.hide.bind(this),250);this.active=false},render:function(){if(this.entryCount>0){for(var a=0;a<this.entryCount;a++){[this.getEntry(a)].invoke(this.index==a?"addClassName":"removeClassName","selected")}this.show();this.active=true}else{this.hide();this.active=false}},markPrevious:function(){if(this.index>0){this.index--}else{this.index=this.entryCount-1}},markNext:function(){if(this.index<this.entryCount-1){this.index++}else{this.index=0}},getEntry:function(a){return this.element.down().down(a)},getCurrentEntry:function(){return this.getEntry(this.index)},selectEntry:function(){this.active=false;if(typeof this.options.onChoose=="function"){this.options.onChoose(this.getCurrentEntry())}}});