/*
Last Updated: September 29, 2016 at 8:06:05 PM

@Package rcSwitcher
Author Ahmed Saad <a7mad.sa3d.2014@gmail.com>

@version 4.0
Compressed with s.press
http://www.beyondf.com/spress
*/
(function(b){var a={$switcher:b("<span>",{"class":"swraper"}).hide(),$toggler:b("<span>",{"class":"stoggler"}),$on:b("<span>",{"class":"slabel-on"}),$off:b("<span>",{"class":"slabel-off"}),$blob:b("<span>",{"class":"sblob"}),themes:["light","modern","dark","flat"],};var c={start:function(e,d){this.setTemplateStyle(d,e);e.$this.each(function(g,f){this.makeSwitcher(b(f),e,d)}.bind(this));this.behaviour(e)},makeSwitcher:function(k,j,g){var f=k.attr("name").replace(/(\[\])+$/,""),e=k.attr("value")||"",h=k.attr("type"),d=(h=="checkbox")?j.checkboxs:j.radios,i={components:{},"$input":k};i.$switcher=a.$switcher.clone().attr({"input-name":f,"input-value":e,"input-type":h});if(j.cssValues.dir=="rtl"){i.$switcher.addClass("rtl")}i.components.$toggler=a.$toggler.clone();i.components.$on=a.$on.clone().html(k.attr("data-ontext")||g.onText);i.components.$off=a.$off.clone().html(k.attr("data-offtext")||g.offText);i.components.$blob=a.$blob.clone();if(g.reverse){i.components.$toggler.append(i.components.$off,i.components.$blob,i.components.$on).appendTo(i.$switcher)}else{i.components.$toggler.append(i.components.$on,i.components.$blob,i.components.$off).appendTo(i.$switcher)}k.before(i.$switcher);if(k[0].checked){i.switcherChecked=true;this.turnOn(i,j,false,true)}else{i.switcherChecked=false;this.turnOff(i,j,false,true)}inputDisabled=k[0].disabled;if(inputDisabled){i.switcherDisabled=true;i.$switcher.addClass("disabled").attr("title","switch is disabled!")}else{i.switcherDisabled=false}if(family=d.group[f]){family.group[e]=i;family.length++}else{d.group[f]=family={group:{},length:1};family.group[e]=i;d.groupLength++;if(h=="radio"){family.enabled=0;family.disabled=0;family.switchable=false}}if(h=="radio"){if(inputDisabled){family.disabled++}else{family.enabled++}if(k[0].checked){family.checkedKey=e}family.switchable=(family.enabled>=2)?true:false}j.$switchers=j.$switchers.add(i.$switcher);d.length++;i.$switcher.show();k.on("change",function(l){this.trackChanges({type:h,name:f,value:e,},j)}.bind(this))},setTemplateStyle:function(e,h){a.$switcher.css({width:[e.width,"px"].join(""),"line-height":[e.height,"px"].join("")}).removeClass(a.themes.join(" ")).addClass(e.theme);h.cssValues.switcherWidth=e.width;h.cssValues.switcherHeight=e.height;h.cssValues.blobOffset=e.blobOffset;h.cssValues.blobWidth=h.cssValues.blobHeight=h.cssValues.switcherHeight-e.blobOffset*2;a.$blob.css({width:h.cssValues.blobWidth,height:h.cssValues.blobHeight});if(e.reverse){h.transformOff=["translateX(",h.transformDir,h.cssValues.blobWidth/2+h.cssValues.blobOffset,"px)"].join("");h.transformOn=["translateX(",h.transformDir,h.cssValues.switcherWidth-h.cssValues.blobWidth/2-h.cssValues.blobOffset,"px)"].join("")}else{h.transformOn=["translateX(",h.transformDir,h.cssValues.blobWidth/2+h.cssValues.blobOffset,"px)"].join("");h.transformOff=["translateX(",h.transformDir,h.cssValues.switcherWidth-h.cssValues.blobWidth/2-h.cssValues.blobOffset,"px)"].join("")}h.transformOn={"-webkit-transform":h.transformOn,"-moz-transform":h.transformOn,"-o-transform":h.transformOn,"-ms-transform":h.transformOn,transform:h.transformOn};h.transformOff={"-webkit-transform":h.transformOff,"-moz-transform":h.transformOff,"-o-transform":h.transformOff,"-ms-transform":h.transformOff,transform:h.transformOff};a.$toggler.css("font-size","");if(e.height<20||e.autoFontSize){a.$toggler.css({"font-size":[e.height/2,"px"].join("")})}a.$switcher.css("margin","");if(e.autoStick){var i=h.$this.first(),d=i.prev("label"),g;if(d){g=i.parent().width();g-=(e.inputs)?i.outerWidth(true):0;g-=d.outerWidth(true);var f=g-e.width;f-=(e.theme=="dark")?0:2;if(h.cssValues.dir=="rtl"){a.$switcher.css("margin-right",f)}else{a.$switcher.css("margin-left",f)}}}},toggle:function(h,g,d){var e,f;if(h.type=="checkbox"){e=g.checkboxs.group[h.name];f=e.group[h.value];if(!f.$input[0].disabled){if(d){status=f.$input[0].checked?"turnOn":"turnOff"}else{status=f.$input[0].checked?"turnOff":"turnOn"}this[status](f,g,d)}}else{e=g.radios.group[h.name];f=e.group[h.value];if(d&&f.$input[0].checked==f.switcherChecked){return}if(d&&!f.$input[0].checked){console.log("can not disable radio button, try to activate another sibiling one to deactivate current.");f.$input.prop("checked",true);return}if(!f.$input[0].disabled&&e.switchable){if(e.checkedKey!=h.name){this.turnOff(e.group[e.checkedKey],g,d);this.turnOn(f,g,d);e.checkedKey=h.value}}}},trackChanges:function(g,f){var d,e;if(g.type=="checkbox"){d=f.checkboxs.group[g.name]}else{d=f.radios.group[g.name]}e=d.group[g.value];if(e.$input[0].checked!=e.switcherChecked){if(e.switcherDisabled){e.$input.prop("checked",e.switcherChecked);if(g.type=="radio"){d.group[d.checkedKey].$input.prop("checked",true)}}else{this.toggle(g,f,true)}}if(e.$input[0].disabled!=e.switcherDisabled){if(e.$input[0].disabled){if(!e.$switcher.hasClass("disabled")){e.$switcher.addClass("disabled")}if(g.type=="radio"){d.disabled++;d.enabled--;if(e.$input[0].checked==true){d.switchable=false}}e.switcherDisabled=true;e.$input.trigger("disable.rcSwitcher",e)}else{e.$switcher.removeClass("disabled");e.$input.trigger("enable.rcSwitcher",e);if(g.type=="radio"){--d.disabled;++d.enabled;if(d.enabled-d.disabled>=2){d.switchable=true}}e.switcherDisabled=false}}},turnOff:function(g,f,d,e){g.components.$toggler.css(f.transformOff).removeClass("on").addClass("off");g.switcherChecked=false;if(e){return}if(!d){g.$input.prop("checked",false)}g.$input.trigger("turnoff.rcSwitcher",g);g.$input.trigger("toggle.rcSwitcher",[g,"turnoff"])},turnOn:function(g,f,d,e){g.components.$toggler.css(f.transformOn).addClass("on").removeClass("off");g.switcherChecked=true;if(e){return}if(!d){g.$input.prop("checked",true)}g.$input.trigger("turnon.rcSwitcher",g);g.$input.trigger("toggle.rcSwitcher",[g,"turnon"])},behaviour:function(d){d.$this.on("click",function(f){f.preventDefault();f.stopPropagation()}.bind(this));d.$switchers.on("click",function(g){var f={};f.type=g.currentTarget.getAttribute("input-type");f.name=g.currentTarget.getAttribute("input-name");f.value=g.currentTarget.getAttribute("input-value");this.toggle(f,d);g.preventDefault();g.stopPropagation()}.bind(this))},};b.fn.rcSwitcher=function(d){var e={checkboxs:{group:{},groupLength:0,length:0,},radios:{group:{},groupLength:0,length:0,},$switchers:b([]),cssValues:{},};e.$this=this.filter("input[type=checkbox], input[type=radio]");if(e.$this.length==0){return}e.cssValues.dir=window.getComputedStyle(e.$this[0],null).direction||"ltr";e.transformDir=(e.cssValues.dir=="rtl")?"":"-";d=b.extend({onText:"ON",offText:"OFF",reverse:false,inputs:false,width:56,height:20,blobOffset:1,autoFontSize:false,theme:"light",autoStick:false,},d||{});if(!d.inputs){e.$this.css("display","none")}if(a.themes.indexOf(d.theme)==-1){d.theme="light"}c.start(e,d);return this}})(jQuery);