var jTemplateSelector=new Class({Implements:Options,options:{templates:{},form:'jTmplSelectForm',reset:'jTemplateReset',change:'jTemplateChange',rolling:'jTemplateRolling',directory:'jTemplateDirectory',list:'jTmplDirectories',toggle:'jTemplateToggle',msg:'tpscurimg',selected:null,base:null,duration:365},selector:null,initialize:function(options){this.setOptions(options);if(this.options.templates.length<1)return;if(document.id(this.options.list)){this.selector=document.id(this.options.list);this.selector.addEvent('change',function(){this.onChange()}.bind(this))}if(document.id(this.options.reset))document.id(this.options.reset).addEvent('click',function(e){if(e)e.stop();document.id(this.options.directory).set('value','');Cookie.dispose('jTemplateSelector');document.id(this.options.form).submit()}.bind(this));if(document.id(this.options.rolling))document.id(this.options.rolling).addEvent('click',function(e){if(e)e.stop();var next=false,selected=this.options.selected;this.selector.getElements('option').each(function(e,i){if(e.get('value')==selected){next=i+1;}});if(next==this.selector.options.length)next=0;this.selector.options.selectedIndex=next;this.onChange();if(document.id(this.options.change))document.id(this.options.change).fireEvent('click');}.bind(this));if(document.id(this.options.change))document.id(this.options.change).addEvent('click',function(e){if(e)e.stop();Cookie.write('jTemplateSelector',document.id(this.options.directory).get('value'),{path:'/',duration:this.options.duration});document.id(this.options.form).submit()}.bind(this));if(document.id(this.options.toggle))document.id(this.options.toggle).addEvent('click',function(e){if(e)e.stop();var id=document.id(this.options.toggle).get('rel');Cookie.write('jTemplateSelector',id,{path:'/',duration:this.options.duration});document.id(this.options.directory).set('value',id);document.id(this.options.form).submit()}.bind(this));},onChange:function(){var v=this.selector.get('value');if(typeof this.options.templates[v]=='undefined')return;var n=this.options.templates[v];var tt=document.id(this.options.msg);if(tt){var t='/template_thumbnail.png';if(tt.src.indexOf('no_image')<0){tt.src=tt.src.replace(/templates\/.+?\//,'templates/'+n+'/')}else{tt.src=this.options.base+n+t}}document.id(this.options.directory).set('value',v)}});