var InvisionSelector=Class.create({initialize:function(container,styles,options){this.container=$(container);this.styles=$A(styles);this.body=$$('body')[0];this.id=this.container.identify();this.options=Object.extend({label:'',callback:null,styleTitles:{}},options||{});this.buildSwitcher();},buildSwitcher:function(){this.switcher=new Element('div',{id:this.id+"_options"}).update(this.options.label);this.styleOptions=new Element('ul',{'class':'style-options'})
this.container.insert(this.switcher);this.switcher.insert(this.styleOptions);this.temp=[];this.styles.each(function(style,index){this.temp[index]=new Element('li',{id:style}).update(this.options.styleTitles[style]||"");this.styleOptions.insert(this.temp[index]);}.bind(this));this.loadPreferences();this.setPreferences();},loadPreferences:function(){var cookie=Cookie.get("invisionselector_"+this.id);if(cookie==''||cookie==null){cookie=this.styles[0];}
this.styles.each(function(style){this.body.removeClassName(style);}.bind(this));this.body.addClassName(cookie);this.currentStyle=cookie;},setPreferences:function(){this.temp.each(function(element){element.observe('click',function(event){var newStyle=element.readAttribute('id');if(newStyle!=this.currentStyle){this.replaceClass(this.body,this.currentStyle,newStyle);Cookie.set("invisionselector_"+this.id,newStyle,365);this.currentStyle=newStyle;if(typeof this.options.callback=="function"){this.options.callback();}}
Event.stop(event);}.bind(this));}.bind(this));},replaceClass:function(elem,old_class,new_class){$(elem).addClassName(new_class);$(elem).removeClassName(old_class);}});