(function(a,b){var c=a(b),d=false,e=false;var f='    <div class="ui-switch">                                 \n      <div class="ui-switch-mask">                          \n        <div class="ui-switch-master">                      \n          <div class="ui-switch-upper">                     \n            <span class="ui-switch-handle"></span>          \n          </div>                                            \n          <div class="ui-switch-lower">                     \n            <div class="ui-switch-labels">                  \n              <a href="#" class="ui-switch-on">{{on}}</a>   \n              <a href="#" class="ui-switch-off">{{off}}</a> \n            </div>                                          \n          </div>                                            \n        </div>                                              \n      </div>                                                \n      <div class="ui-switch-middle"></div>                  \n    </div>';c.bind("mousedown",function(a){if(a.which<=1&&!a.metaKey&&!a.shiftKey&&!a.altKey&&!a.ctrlKey){d=true}}).bind("mouseup",function(a){d=false});c.bind("mouseup touchend",function(){e=false;if(a(".ui-switch[data-dragging]").length>0){a(".ui-switch[data-dragging]").data("controls").snap();e=true}});var g={build:function(b,c){b.hide();b.attr("tabindex","-1");var g=b.find("option"),h=b.val(),i=!!b.attr("disabled");var j={on:c.on||g.first().val(),off:c.off||g.last().val()},k={on:g.filter("[value="+j.on+"]").text(),off:g.filter("[value="+j.off+"]").text()};var l=a(f.replace("{{on}}",k.on).replace("{{off}}",k.off));l.addClass(b.val()===j.on?"on":"off");if(i){l.addClass("disabled")}var m=l.find(".ui-switch-master"),n=l.find(".ui-switch-handle");l.insertAfter(b);var o=l.find("a").map(function(b,c){return a(c).width()}),p=Math.max(o[0],o[1]);l.find(".ui-switch-middle").width(p+43);l.find("a").width(p);var q="-"+(p+21)+"px",r="-2px";m.css({left:q});n.css({left:p+16+"px"});if(j.on===h){m.css({left:r})}b.data("switch",l);l.data("select",b);l.data("animating",false);l.data("offset",l.offset()).data("dimensions",{width:l.width(),height:l.height()}).data("center",{left:l.data("offset").left+l.data("dimensions").width/2,top:l.data("offset").top+l.data("dimensions").height/2});a.event.special["switch:slide"]={_default:function(b,c){var d=a(b.target);if(!c&&d.data("switchEvent")){c=d.data("switchEvent");d.removeData("switchEvent")}if(!(c==="on"||c==="off")){throw'jQuery/Switch: "switch:slide" event must be triggered with an additional parameter of "on" or "off"'}d.trigger("switch:slide"+c)}};var s=l.data("controls",{_to:function(a,b){if(!b){b={silent:false}}if(!i&&!b.silent){l.data("switchEvent",a);l.trigger("switch:slide",[a])}else if(!i){l.trigger("switch:slide"+a)}return l},on:function(a){return s._to("on",a)},off:function(a){return s._to("off",a)},toggle:function(a){return s._to(b.val()===j.on?"off":"on",a)},snap:function(a){if(!a){a={}}if(!l.data("animating")&&l.attr("data-dragging")){if(l.find(".ui-switch-handle").offset().left+15>l.data("center").left){a.silent=l.data("select").val()==j.on;return s.on(a)}else{a.silent=l.data("select").val()==j.off;return s.off(a)}}else{return l}}})&&l.data("controls");b.bind("change",function(){d=false;s[b.val()===j.on?"on":"off"]()});l.attr("tabindex","0").bind("keyup",function(a){if(a.which===13){s.toggle()}});l.find("a").attr("tabindex","-1");l.bind("mouseup touchend",function(a){a.preventDefault();if(!l.attr("data-dragging")){s.toggle()}});l.bind("mousedown touchstart",function(a){a.preventDefault();var b,c;if(a.type==="touchstart"){b=a.originalEvent.targetTouches[0].pageX;c=a.originalEvent.targetTouches[0].pageY}else{b=a.pageX;c=a.pageY}var d=parseInt(m.css("left")),e=l.data("offset").left+d,f=e-b;l.data("modifier",f)});l.bind("mouseleave touchcancel",function(a){if(!e){l.data("controls").snap()}else{e=false}});l.bind("mousemove touchmove",function(a){a.preventDefault();if(!i&&(a.type==="touchmove"||d)){l.attr("data-dragging","true");var b,c;if(a.type==="touchmove"){b=a.originalEvent.targetTouches[0].pageX;c=a.originalEvent.targetTouches[0].pageY}else{b=a.pageX;c=a.pageY}var e=l.data("offset"),f=l.data("dimensions"),g=l.data("center");var h=b+l.data("modifier"),j=e.left-(p+35);if(h>j+18&&h<=j-19+f.width){m.offset({left:h})}}});l.bind("switch:slideon",function(){l.data("animating",true).removeAttr("data-dragging");m.stop().animate({left:r},"fast",function(){l.data("animating",false).data("select").val(j.on);l.removeClass("off").addClass("on");d=false;e=false})});l.bind("switch:slideoff",function(){l.data("animating",true).removeAttr("data-dragging");m.stop().animate({left:q},"fast",function(){l.data("animating",false).data("select").val(j.off);l.removeClass("on").addClass("off");d=false;e=false})});return b},update:function(a){var b=a.data("switch");b.data("offset",b.offset()).data("dimensions",{width:b.width(),height:b.height()}).data("center",{left:b.data("offset").left+b.data("dimensions").width/2,top:b.data("offset").top+b.data("dimensions").height/2});return a}};a.fn.switchify=function(b){this.each(function(c,d){var e=a(d);if(b!=="update"&&e.data("switch")){return}g[b==="update"?"update":"build"](e,b||{})});return this}})(jQuery,window.document)