(function(a){function p(){if(a("body").css("backgroundImage")){return a("body").css("backgroundImage").replace(/url\("?(.*?)"?\)/i,"$1")}}function o(){d.fadeOut("fast",function(){a(this).remove()})}function n(){d.prependTo("body").fadeIn()}function m(b,c){var d={align:"center",valign:"center"};a.extend(d,c);var e=a(window).width(),f=a(window).height(),g=b.width(),h=b.height(),i=f/e,j=h/g,k,l,m,n,o;if(i>j){k=f/j;l=f}else{k=e;l=e*j}o={width:k+"px",height:l+"px",top:"auto",bottom:"auto",left:"auto",right:"auto"};if(!isNaN(parseInt(d.valign))){o["top"]=0-(l-f)/100*parseInt(d.valign)+"px"}else if(d.valign=="top"){o["top"]=0}else if(d.valign=="bottom"){o["bottom"]=0}else{o["top"]=(f-l)/2}if(!isNaN(parseInt(d.align))){o["left"]=0-(k-e)/100*parseInt(d.align)+"px"}else if(d.align=="left"){o["left"]=0}else if(d.align=="right"){o["right"]=0}else{o["left"]=(e-k)/2}b.css(o)}var b=a("<img />").addClass("vegas-background"),c=a("<div />").addClass("vegas-overlay"),d=a("<div />").addClass("vegas-loading"),e=a(),f=null,g=[],h=0,i=5e3,j=function(){},k,l={init:function(c){var d={src:p(),align:"center",valign:"center",fade:0,loading:true,load:function(){},complete:function(){}};a.extend(d,a.vegas.defaults.background,c);if(d.loading){n()}var f=b.clone();f.css({position:"fixed",left:"0px",top:"0px"}).imagesLoadedForVegas(function(){if(f==e){return}a(window).bind("resize.vegas",function(a){m(f,d)});if(e.is("img")){e.stop();f.hide().insertAfter(e).fadeIn(d.fade,function(){a(".vegas-background").not(this).remove();a("body").trigger("vegascomplete",[this,h-1]);d.complete.apply(f,[h-1])})}else{f.hide().prependTo("body").fadeIn(d.fade,function(){a("body").trigger("vegascomplete",[this,h-1]);d.complete.apply(this,[h-1])})}e=f;m(e,d);if(d.loading){o()}a("body").trigger("vegasload",[e.get(0),h-1]);d.load.apply(e.get(0),[h-1]);if(h){a("body").trigger("vegaswalk",[e.get(0),h-1]);d.walk.apply(e.get(0),[h-1])}}).attr("src",d.src);return a.vegas},destroy:function(b){if(!b||b=="background"){a(".vegas-background, .vegas-loading").remove();a(window).unbind("resize.vegas");e=null}if(b=="overlay"){a(".vegas-overlay").remove()}return a.vegas},overlay:function(b){var d={src:null,opacity:null};a.extend(d,a.vegas.defaults.overlay,b);c.remove();c.css({margin:"0",padding:"0",position:"fixed",left:"0px",top:"0px",width:"100%",height:"100%"});if(d.src){c.css("backgroundImage","url("+d.src+")")}if(d.opacity){c.css("opacity",d.opacity)}c.prependTo("body");return a.vegas},slideshow:function(b,c){var d={step:h,delay:i,preload:false,backgrounds:g,walk:j};a.extend(d,a.vegas.defaults.slideshow,b);if(d.backgrounds!=g){if(!b.step){d.step=0}if(!b.walk){d.walk=function(){}}if(d.preload){a.vegas("preload",d.backgrounds)}}g=d.backgrounds;i=d.delay;h=d.step;j=d.walk;clearInterval(k);if(!g.length){return a.vegas}var l=function(){if(h<0){h=g.length-1}if(h>=g.length||g[h-1]===undefined){h=0}var b=g[h++];b.walk=d.walk;if(b.fade>d.delay){b.fade=d.delay}a.vegas(b)};l();if(!c){f=false;a("body").trigger("vegasstart",[e.get(0),h-1])}if(!f){k=setInterval(l,d.delay)}return a.vegas},next:function(){var b=h;if(h){a.vegas("slideshow",{step:h},true);a("body").trigger("vegasnext",[e.get(0),h-1,b-1])}return a.vegas},previous:function(){var b=h;if(h){a.vegas("slideshow",{step:h-2},true);a("body").trigger("vegasprevious",[e.get(0),h-1,b-1])}return a.vegas},jump:function(b){var c=h;if(h){a.vegas("slideshow",{step:b},true);a("body").trigger("vegasjump",[e.get(0),h-1,c-1])}return a.vegas},stop:function(){var b=h;h=0;f=null;clearInterval(k);a("body").trigger("vegasstop",[e.get(0),b-1]);return a.vegas},pause:function(){f=true;clearInterval(k);a("body").trigger("vegaspause",[e.get(0),h-1]);return a.vegas},get:function(a){if(a==null||a=="background"){return e.get(0)}if(a=="overlay"){return c.get(0)}if(a=="step"){return h-1}if(a=="paused"){return f}},preload:function(b){for(var c in b){if(b[c].src){a('<img src="'+b[c].src+'">')}}return a.vegas}};a.vegas=function(b){if(l[b]){return l[b].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof b==="object"||!b){return l.init.apply(this,arguments)}else{a.error("Method "+b+" does not exist")}};a.vegas.defaults={background:{},slideshow:{},overlay:{}};a.fn.imagesLoadedForVegas=function(a){function g(){if(--d<=0&&this.src!==e){setTimeout(f);c.unbind("load error",g)}}function f(){a.call(b,c)}var b=this,c=b.find("img").add(b.filter("img")),d=c.length,e="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";if(!d){f()}c.bind("load error",g).each(function(){if(this.src!=""&&(this.complete||this.complete===undefined)){var a=this.src;this.src=e;this.src=a}});return b}})(jQuery)
