!function(a){var b=!1,c=!1,d={isUrl:function(a){var b=new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$","i");return!!b.test(a)},loadContent:function(a,b){a.html(b)},addPrefix:function(a){var b=a.attr("id"),c=a.attr("class");"string"==typeof b&&""!==b&&a.attr("id",b.replace(/([A-Za-z0-9_.\-]+)/g,"sidr-id-$1")),"string"==typeof c&&""!==c&&"sidr-inner"!==c&&a.attr("class",c.replace(/([A-Za-z0-9_.\-]+)/g,"sidr-class-$1")),a.removeAttr("style")},execute:function(d,f,g){"function"==typeof f?(g=f,f="sidr"):f||(f="sidr");var q,r,s,h=a("#"+f),i=a(h.data("body")),j=a("html"),k=h.outerWidth(!0),l=h.data("speed"),m=h.data("side"),n=h.data("displace"),o=h.data("onOpen"),p=h.data("onClose"),t="sidr"===f?"sidr-open":"sidr-open "+f+"-open";if("open"===d||"toggle"===d&&!h.is(":visible")){if(h.is(":visible")||b)return;if(c!==!1)return void e.close(c,function(){e.open(f)});b=!0,"left"===m?(q={left:k+"px"},r={left:"0px"}):(q={right:k+"px"},r={right:"0px"}),i.is("body")&&(s=j.scrollTop(),j.css("overflow-x","hidden").scrollTop(s)),n?i.addClass("sidr-animating").css({width:i.width(),position:"absolute"}).animate(q,l,function(){a(this).addClass(t)}):setTimeout(function(){a(this).addClass(t)},l),h.css("display","block").animate(r,l,function(){b=!1,c=f,"function"==typeof g&&g(f),i.removeClass("sidr-animating")}),o(),i.addClass("sidr-open")}else{if(!h.is(":visible")||b)return;b=!0,"left"===m?(q={left:0},r={left:"-"+k+"px"}):(q={right:0},r={right:"-"+k+"px"}),i.is("body")&&(s=j.scrollTop(),j.removeAttr("style").scrollTop(s)),i.addClass("sidr-animating").animate(q,l).removeClass(t),h.animate(r,l,function(){h.removeAttr("style").hide(),i.removeAttr("style"),a("html").removeAttr("style"),b=!1,c=!1,"function"==typeof g&&g(f),i.removeClass("sidr-animating")}),p()}}},e={open:function(a,b){d.execute("open",a,b)},close:function(a,b){d.execute("close",a,b)},toggle:function(a,b){d.execute("toggle",a,b)},toogle:function(a,b){d.execute("toggle",a,b)}};a.sidr=function(b){return e[b]?e[b].apply(this,Array.prototype.slice.call(arguments,1)):"function"!=typeof b&&"string"!=typeof b&&b?void a.error("Method "+b+" does not exist on jQuery.sidr"):e.toggle.apply(this,arguments)},a.fn.sidr=function(b){var c=a.extend({name:"sidr",speed:200,side:"left",source:null,renaming:!0,body:"body",displace:!0,onOpen:function(){},onClose:function(){}},b),f=c.name,g=a("#"+f);if(0===g.length&&(g=a("<div />").attr("id",f).appendTo(a("body"))),g.addClass("sidr").addClass(c.side).data({speed:c.speed,side:c.side,body:c.body,displace:c.displace,onOpen:c.onOpen,onClose:c.onClose}),"function"==typeof c.source){var h=c.source(f);d.loadContent(g,h)}else if("string"==typeof c.source&&d.isUrl(c.source))a.get(c.source,function(a){d.loadContent(g,a)});else if("string"==typeof c.source){var i="",j=c.source.split(",");if(a.each(j,function(b,c){i+='<div class="sidr-inner">'+a(c).html()+"</div>"}),c.renaming){var k=a("<div />").html(i);k.find("*").each(function(b,c){var e=a(c);d.addPrefix(e)}),i=k.html()}d.loadContent(g,i)}else null!==c.source&&a.error("Invalid Sidr Source");return this.each(function(){var b=a(this),c=b.data("sidr");c||(b.data("sidr",f),"ontouchstart"in document.documentElement?(b.bind("touchstart",function(a){a.originalEvent.touches[0];this.touched=a.timeStamp}),b.bind("touchend",function(a){var b=Math.abs(a.timeStamp-this.touched);b<200&&(a.preventDefault(),e.toggle(f))})):b.on( 'click',function(a){a.preventDefault(),e.toggle(f)}))})}}(jQuery);
