(function(a){a.fn.extend({lightSwitch:function(b){var c={animSpeed:120,hoverSpeed:100,switchImg:"/static/images/lightswitch/switch-1.png",switchImgCover:"/static/images/lightswitch/switchplate.png",switchImgCoverWidth:"63px",switchImgCoverHeight:"18px",disabledImg:"disabled.png",onShift:"0px 0px",offShift:"-37px 0px",peekOff:"-6px 0px",peekOn:"-31px 0px"};var b=a.extend(c,b);return this.each(function(){var e=b;var d=a(this);if(a(this).attr("disabled")){a(this).css({display:"none"}).after('<span><img src="'+e.disabledImg+'" /></span>')}else{a(this).css({display:"none"}).after('<span class="switch"><img src="'+e.switchImgCover+'" width="'+e.switchImgCoverWidth+'" height="'+e.switchImgCoverHeight+'" /></span>')}a("+ span.switch",this).css({display:"inline-block","background-image":'url("'+e.switchImg+'")',"background-repeat":"no-repeat",overflow:"hidden",cursor:"pointer","margin-right":"2px"});a("+ span.switch",this).click(function(){if(a(this).prev().is(":radio")){radioGroupName=a(this).prev().attr("name");a('input[name="'+radioGroupName+'"]:checked + span').stop().animate({"background-position":e.offShift},e.animSpeed)}if(a(this).prev().is(":checked")){a(this).stop().animate({"background-position":e.offShift},e.animSpeed);a(this).prev().removeAttr("checked")}else{a(this).stop().animate({"background-position":e.onShift},e.animSpeed);if(a(this).prev().is(":radio")){a('input[name="'+radioGroupName+'"]:checked').removeAttr("checked")}a(this).prev("input").attr("checked","checked")}}).hover(function(){a(this).stop().animate({"background-position":a(this).prev().is(":checked")?e.peekOff:e.peekOn},e.hoverSpeed)},function(){a(this).stop().animate({"background-position":a(this).prev().is(":checked")?e.onShift:e.offShift},e.hoverSpeed)});a("+ span",this).css({"background-position":a(this).is(":checked")?e.onShift:e.offShift});a("input + span").live("click",function(){return false});a(this).change(function(){radioGroupName=a(this).attr("name");if(a(this).is(":radio")){a(this).stop().animate({"background-position":e.onShift},e.animSpeed);a('input[name="'+radioGroupName+'"] + span').stop().animate({"background-position":e.offShift},e.animSpeed)}a(this).next("span").stop().animate({"background-position":a(this).is(":checked")?e.onShift:e.offShift},e.animSpeed)})})}})})(jQuery);
