(function(a,b,c){b.Slideshow=function(a,c){this.$el=b(c);this.$preloader=b('<div class="cn-loading">Loading...</div>');this.$images=this.$el.find("div.cn-images > img").hide();this.imgCount=this.$images.length;this.isAnimating=false;this._init(a)};b.Slideshow.defaults={current:0};b.Slideshow.prototype={_init:function(a){this.options=b.extend(true,{},b.Slideshow.defaults,a);this._validate();this.current=this.options.current;this.$preloader.appendTo(this.$el);var c=this;this._preloadImages(function(){c.$preloader.hide();c.$images.eq(c.current).show();c.bar=new b.NavigationBar(c.imgCount,c._getStatus());c.bar.getElement().appendTo(c.$el);c._initEvents()})},_preloadImages:function(a){var c=0,d=this;this.$images.each(function(e){var f=b(this);b("<img/>").load(function(){++c;if(c===d.imgCount*2)a.call()}).attr("src",f.attr("src"));b("<img/>").load(function(){++c;if(c===d.imgCount*2)a.call()}).attr("src",f.data("thumb"))})},_validate:function(){if(this.options.current<0||this.options.current>=this.imgCount)this.options.current=0},_getStatus:function(){var a=this.$images.eq(this.current),b,c;this.current===0?c=this.$images.eq(this.imgCount-1):c=a.prev();this.current===this.imgCount-1?b=this.$images.eq(0):b=a.next();return{prevSource:c.data("thumb"),nextSource:b.data("thumb"),prevTitle:c.attr("title"),currentTitle:a.attr("title"),nextTitle:b.attr("title")}},_initEvents:function(){var a=this;this.bar.$navPrev.bind("click.slideshow",function(b){a._navigate("prev");return false});this.bar.$navNext.bind("click.slideshow",function(b){a._navigate("next");return false})},_navigate:function(a){if(this.isAnimating)return false;this.isAnimating=true;var c=this.$images.eq(this.current).css("z-index",998),d=this;a==="prev"?this.current===0?this.current=this.imgCount-1:--this.current:this.current===this.imgCount-1?this.current=0:++this.current;this.$images.eq(this.current).show();c.fadeOut(400,function(){b(this).css("z-index",1);d.isAnimating=false});this.bar.set(this._getStatus())}};b.NavigationBar=function(a,b){this._init(a,b)};b.NavigationBar.prototype={_init:function(a,c){this.$el=b("#barTmpl").tmpl(c);this.$navPrev=this.$el.find("a.cn-nav-prev");this.$thumbPrev=this.$navPrev.children("div");this.$navNext=this.$el.find("a.cn-nav-next");this.$thumbNext=this.$navNext.children("div");this.$statusPrev=this.$el.find("div.cn-nav-content-prev > h3");this.$statusCurrent=this.$el.find("div.cn-nav-content-current > h2");this.$statusNext=this.$el.find("div.cn-nav-content-next > h3");if(a<=1){this.$navPrev.hide();this.$navNext.hide();this.$statusPrev.parent().hide();this.$statusNext.parent().hide()}},getElement:function(){return this.$el},set:function(a){this.$thumbPrev.css("background-image","url("+a.prevSource+")");this.$thumbNext.css("background-image","url("+a.nextSource+")");this.$statusPrev.text(a.prevTitle);this.$statusCurrent.text(a.currentTitle);this.$statusNext.text(a.nextTitle)}};var d=function(a){if(this.console){console.error(a)}};b.fn.slideshow=function(a){if(typeof a==="string"){var c=Array.prototype.slice.call(arguments,1);this.each(function(){var e=b.data(this,"slideshow");if(!e){d("cannot call methods on slideshow prior to initialization; "+"attempted to call method '"+a+"'");return}if(!b.isFunction(e[a])||a.charAt(0)==="_"){d("no such method '"+a+"' for slideshow instance");return}e[a].apply(e,c)})}else{this.each(function(){var c=b.data(this,"slideshow");if(!c){b.data(this,"slideshow",new b.Slideshow(a,this))}})}return this}})(window,jQuery)