$.namespace("trapeze.styleform");trapeze.styleform=$.Class.extend({settings:null,forms:null,wrap_template:'<%(wrap_tag) class="%(wrap_class)"></%(wrap_tag)>',text_corner_template:'<div class="%(tag_class)" %(add_attr)><!-- --></div>',select_fake_template:'<div class="fake-select"><div class="%(select_fake_class)">%(selected_option)</div></div>',checkbox_radio_fake_template:'<span class="%(fake_class)"><!-- --></span>',render_corner:function(a,e,d,b,c){if(!$.support.opacity){e+=1}return trapeze.render_template(this.text_corner_template,{tag_class:a,add_attr:'style="top:'+e+"px;left:"+d+'px;"'})},style_textfield:function(a){if(($(a).attr("type")=="text")||($(a).attr("type")=="password")){corner_width=this.settings.input_text_corner;tag="div";tag_class=this.settings.input_text_wrap}else{corner_width=this.settings.textarea_corner;tag="div";tag_class=this.settings.textarea_wrap}$(a).wrap(trapeze.render_template(this.wrap_template,{wrap_tag:tag,wrap_class:tag_class})).before(this.render_corner(this.settings.textfield_corner_tl,0,0,0,0)).before(this.render_corner(this.settings.textfield_corner_tr,0,($(a).outerWidth()-corner_width),0,(corner_width*-1))).after(this.render_corner(this.settings.textfield_corner_br,($(a).outerHeight()-corner_width),($(a).outerWidth()-corner_width),(corner_width*-1),(corner_width*-1))).after(this.render_corner(this.settings.textfield_corner_bl,($(a).outerHeight()-corner_width),0,(corner_width*-1),0))},style_checkbox_radio:function(c){var b=$(c).attr("type")+"-"+this.settings.checkbox_radio_wrap_class;var d=this.settings.checkbox_radio_fake_class+"-"+$(c).attr("type");var a=($(c).attr("type")=="checkbox")?this.settings.checkbox_height:this.settings.radio_height;$(c).wrap(trapeze.render_template(this.wrap_template,{wrap_tag:"span",wrap_class:b})).before(trapeze.render_template(this.checkbox_radio_fake_template,{fake_class:d})).hide().parent().find("."+d).bind("mousedown",this.checkbox_radio_push.bind(this)).bind("mouseup",this.checkbox_radio_push.bind(this)).css("background-position","0 -"+(a*($(c).attr("checked")?2:0))+"px")},checkbox_radio_push:function(a){var b=$(a.currentTarget).next("input");var d=this.settings.checkbox_radio_fake_class+"-"+$(b).attr("type");if(a.type=="mouseup"){if(b.attr("type")=="checkbox"){b.attr("checked",(b.attr("checked")?false:true))}else{b.parents("form").find('input:radio[name="'+b.attr("name")+'"]').each(function(){$(this).attr("checked",false).parent().find("."+d).css("background-position","0 -0")});b.attr("checked",true)}}var c=(b.attr("type")=="checkbox")?this.settings.checkbox_height:this.settings.radio_height;c*=(a.type=="mouseup"?(b.attr("checked")?2:0):(b.attr("checked")?3:1));$(a.currentTarget).css("background-position","0 -"+(c+1)+"px");if(a.type=="mouseup"){b.trigger("change")}},style_select:function(b){var a=this.settings.select_wrap_class;if($(b).is("[class*='size-']")){a+=" "+a+"-"+/^size-\d{1,2}/i.exec($(b).attr("class"))[0]}$(b).wrap(trapeze.render_template(this.wrap_template,{wrap_tag:"div",wrap_class:a})).before(trapeze.render_template(this.select_fake_template,{select_fake_class:this.settings.select_fake_class,selected_option:$(b).find("option").eq(b.selectedIndex).text()})).css("height",($(b).parent().find("."+this.settings.select_fake_class).outerHeight()+"px")).fadeTo(0,0).bind("change",this.select_click.bind(this)).parent().css("height",$(b).height()+"px").find(".fake-select").prepend(trapeze.render_template(this.text_corner_template,{tag_class:this.settings.select_left,add_attr:""})).append(trapeze.render_template(this.text_corner_template,{tag_class:this.settings.select_right,add_attr:""})).parent().find("."+this.settings.select_fake_class).css("width",($(b).width()-($(b).parent().find("."+this.settings.select_left).width()+$(b).parent().find("."+this.settings.select_right).width()))+"px")},select_click:function(a){$(a.currentTarget).parent().find("."+this.settings.select_fake_class).text($(a.currentTarget).find("option").eq(a.currentTarget.selectedIndex).text())},style_forms:function(){if(this.settings.style_input){this.forms.find("input:text").not(this.forms.find("."+this.settings.input_text_wrap+" input:text")).each(function(a,b){this.style_textfield(b)}.bind(this))}if(this.settings.style_password){this.forms.find("input:password").not(this.forms.find("."+this.settings.input_text_wrap+" input:password")).each(function(a,b){this.style_textfield(b)}.bind(this))}if(this.settings.style_textarea){this.forms.find("textarea").not(this.forms.find("."+this.settings.textarea_wrap+" textarea")).each(function(a,b){this.style_textfield(b)}.bind(this))}if(this.settings.style_checkbox){this.forms.find("input:checkbox").not(this.forms.find(".checkbox-"+this.settings.checkbox_radio_wrap_class+" input:checkbox")).each(function(a,b){this.style_checkbox_radio(b)}.bind(this))}if(this.settings.style_radio){this.forms.find("input:radio").not(this.forms.find(".radio-"+this.settings.checkbox_radio_wrap_class+" input:radio")).each(function(a,b){this.style_checkbox_radio(b)}.bind(this))}if(this.settings.style_select){this.forms.find("select").not(this.forms.find("."+this.settings.select_wrap_class+" select")).each(function(a,b){this.style_select(b)}.bind(this))}this.settings.on_complete()},init:function(a){var b={checkbox_height:"19",radio_height:"18",select_width:"200",style_checkbox:false,style_radio:false,style_select:true,style_input:true,style_password:true,style_textarea:true,style_image:false,style_submit:false,textfield_corner_tl:"textfield-corner-tl",textfield_corner_tr:"textfield-corner-tr",textfield_corner_br:"textfield-corner-br",textfield_corner_bl:"textfield-corner-bl",input_text_wrap:"input-text-wrapper",input_text_corner:6,textarea_wrap:"textarea-wrapper",textarea_corner:6,select_wrap_class:"select-wrapper",select_fake_class:"select-active-item",select_left:"fake-select-left",select_right:"fake-select-right",checkbox_radio_wrap_class:"wrapper",checkbox_radio_fake_class:"fake",on_complete:function(){},selector:null};this.settings=$.extend({},b,a);this.forms=$(this.settings.selector);this.style_forms()}});
