(function(a){function p(d,b){var c={align:"center",valign:"center"};a.extend(c,b);if(0===d.height())d.load(function(){p(a(this),b)});else{var f=v(),e=f.width,f=f.height,g=d.width(),l=d.height()/g,h;f/e>l?(g=f/l,l=f):(g=e,l*=e);h={width:g+"px",height:l+"px",top:"auto",bottom:"auto",left:"auto",right:"auto"};isNaN(parseInt(c.valign,10))?"top"==c.valign?h.top=0:"bottom"==c.valign?h.bottom=0:h.top=(f-l)/2:h.top=0-(l-f)/100*parseInt(c.valign,10)+"px";isNaN(parseInt(c.align,10))?"left"==c.align?h.left=
0:"right"==c.align?h.right=0:h.left=(e-g)/2:h.left=0-(g-e)/100*parseInt(c.align,10)+"px";d.css(h)}}function w(){r.fadeOut("fast",function(){a(this).remove()})}function v(){var a=window,b="inner";"innerWidth"in window||(a=document.documentElement||document.body,b="client");return{width:a[b+"Width"],height:a[b+"Height"]}}var x=a("<img />").addClass("vegas-background"),k=a("<div />").addClass("vegas-overlay"),r=a("<div />").addClass("vegas-loading"),e=a(),m=null,g=[],b=0,t=5E3,u=function(){},n,q={init:function(d){var g;
g=a("body").css("backgroundImage")?a("body").css("backgroundImage").replace(/url\("?(.*?)"?\)/i,"$1"):void 0;var c={src:g,align:"center",valign:"center",fade:0,loading:!0,load:function(){},complete:function(){}};a.extend(c,a.vegas.defaults.background,d);c.loading&&r.prependTo("body").fadeIn();var f=x.clone();f.css({position:"fixed",left:"0px",top:"0px"}).bind("load",function(){f!=e&&(a(window).bind("load resize.vegas",function(a){p(f,c)}),e.is("img")?(e.stop(),f.hide().insertAfter(e).fadeIn(c.fade,
function(){a(".vegas-background").not(this).remove();a("body").trigger("vegascomplete",[this,b-1]);c.complete.apply(f,[b-1])})):f.hide().prependTo("body").fadeIn(c.fade,function(){a("body").trigger("vegascomplete",[this,b-1]);c.complete.apply(this,[b-1])}),e=f,p(e,c),c.loading&&w(),a("body").trigger("vegasload",[e.get(0),b-1]),c.load.apply(e.get(0),[b-1]),b&&(a("body").trigger("vegaswalk",[e.get(0),b-1]),c.walk.apply(e.get(0),[b-1])))}).attr("src",c.src);return a.vegas},destroy:function(d){d&&"background"!=
d||(a(".vegas-background, .vegas-loading").remove(),a(window).unbind("*.vegas"),e=a());d&&"overlay"!=d||a(".vegas-overlay").remove();clearInterval(n);return a.vegas},overlay:function(d){var b={src:null,opacity:null};a.extend(b,a.vegas.defaults.overlay,d);k.remove();k.css({margin:"0",padding:"0",position:"fixed",left:"0px",top:"0px",width:"100%",height:"100%"});!1===b.src&&k.css("backgroundImage","none");b.src&&k.css("backgroundImage","url("+b.src+")");b.opacity&&k.css("opacity",b.opacity);k.prependTo("body");
return a.vegas},slideshow:function(d,k){var c={step:b,delay:t,preload:!1,loading:!0,backgrounds:g,walk:u};a.extend(c,a.vegas.defaults.slideshow,d);c.backgrounds!=g&&(d.step||(c.step=0),d.walk||(c.walk=function(){}),c.preload&&a.vegas("preload",c.backgrounds));g=c.backgrounds;t=c.delay;b=c.step;u=c.walk;clearInterval(n);if(!g.length)return a.vegas;var f=function(){0>b&&(b=g.length-1);if(b>=g.length||!g[b-1])b=0;var d=g[b++];d.walk=c.walk;d.loading=c.loading;"undefined"==typeof d.fade&&(d.fade=c.fade);
d.fade>c.delay&&(d.fade=c.delay);a.vegas(d)};f();k||(m=!1,a("body").trigger("vegasstart",[e.get(0),b-1]));m||(n=setInterval(f,c.delay));return a.vegas},next:function(){var d=b;b&&(a.vegas("slideshow",{step:b},!0),a("body").trigger("vegasnext",[e.get(0),b-1,d-1]));return a.vegas},previous:function(){var d=b;b&&(a.vegas("slideshow",{step:b-2},!0),a("body").trigger("vegasprevious",[e.get(0),b-1,d-1]));return a.vegas},jump:function(d){var g=b;b&&(a.vegas("slideshow",{step:d},!0),a("body").trigger("vegasjump",
[e.get(0),b-1,g-1]));return a.vegas},stop:function(){var d=b;b=0;m=null;clearInterval(n);a("body").trigger("vegasstop",[e.get(0),d-1]);return a.vegas},pause:function(){m=!0;clearInterval(n);a("body").trigger("vegaspause",[e.get(0),b-1]);return a.vegas},get:function(a){if(null===a||"background"==a)return e.get(0);if("overlay"==a)return k.get(0);if("step"==a)return b-1;if("paused"==a)return m},preload:function(b){var e=[],c;for(c in b)if(b[c].src){var f=document.createElement("img");f.src=b[c].src;
e.push(f)}return a.vegas}};a.vegas=function(b){if(q[b])return q[b].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof b&&b)a.error("Method "+b+" does not exist");else return q.init.apply(this,arguments)};a.vegas.defaults={background:{},slideshow:{},overlay:{}}})(jQuery);