var listChanger = Class.create(); listChanger.prototype = { initialize:function(holderId, className) { this.changer = document.getElementById(holderId).getElementsByTagName("select")[0]; this.elements = document.getElementsByClassName(className, holderId); this.currentIndex = 0; var index = Cookie.get(holderId + "_last_selected_index_in_cookie"); var thisCopy = this; if(index) { this.currentIndex = index; } this.options = this.changer.getElementsByTagName("option"); this.options[this.currentIndex].selected = true; for( var i=0; i < this.elements.length; i++ ) { Element.hide( this.elements[i] ); } Element.show( this.elements[this.currentIndex] ); Event.observe ( this.changer, "change", function(event) { thisCopy.changeOption(); } ); Event.observe ( this.changer, 'keypress', this.checkKey.bindAsEventListener(this) ); }, checkKey: function(event) { var code = event.keyCode; if(code == Event.KEY_UP || code == Event.KEY_LEFT ) { if( (this.currentIndex - 1 ) > -1 ) { this.changer.selectedIndex = this.currentIndex - 1; } if( navigator.userAgent.indexOf('MSIE') != -1 && code == Event.KEY_UP ) { this.changer.selectedIndex += 1; } this.changeOption() ; } if(code == Event.KEY_DOWN || code == Event.KEY_RIGHT ) { if( (this.currentIndex + 1 ) < this.options.length ) { this.changer.selectedIndex = this.currentIndex + 1; } if( navigator.userAgent.indexOf('MSIE') != -1 && code == Event.KEY_DOWN ) { this.changer.selectedIndex -= 1; } this.changeOption() ; } }, changeOption: function() { if( this.currentIndex != this.changer.selectedIndex ) { Element.hide( this.elements[ this.currentIndex ] ); this.currentIndex = this.changer.selectedIndex; Element.show( this.elements[this.currentIndex] ); Cookie.set( this.changer.parentNode.id + "_last_selected_index_in_cookie", this.currentIndex, 30); } } }