(function(a){var b={};var c={};var d;a.fn.theatre=function(){var b=arguments;(this.length?this:a(document)).each(function(){c.initAll.apply(a(this),b)});return this};c.loadEffect=function(c){if(!d){a('script[src*="jquery.theatre-"], link[href*="theatre.css"]').first().each(function(){d=(this.href||this.src).replace(/\/[^\/]*(#.*)?$/,"")})}var e=d+"/effect."+c.split(":")[0]+".js";a("head").append('<script type="text/javascript" src="'+e+'"></script>');return b[c]};c.initAll=function(d){if(typeof d=="object"||!d||d=="init"){return c.init.apply(this,arguments)}if(d=="effect"){if(typeof arguments[2]=="function"){return b[arguments[1]]=arguments[2]}else{a.error("Elixon Theatre cannot register effect object unless it is a Function.")}}var e=this.data("theatre");if(!e)return false;switch(d){case"jump":var f;switch(f){case"first":f=0;break;case"last":f=e.actors.length-1;break;default:f=(parseInt(arguments[1])-1)%e.actors.length;f=(Math.abs(Math.floor(f/e.actors.length)*e.actors.length)+f)%e.actors.length}if(typeof arguments[2]!="undefined"){if(typeof e.settings.speedOrig=="undefined")e.settings.speedOrig=e.settings.speed;e.settings.speed=arguments[2]}while(e.index!=f){if(e.effect.jump){e.effect.jump(f);e.index=f}else{this.theatre(e.index<f?"next":"prev")}}c.onMove.apply(this);if(typeof e.settings.speedOrig!="undefined")e.settings.speed=e.settings.speedOrig;break;case"next":case"prev":if(!arguments[1])this.theatre("stop");e.index=(e.index+(d=="next"?1:-1))%e.actors.length;e.index=(Math.abs(Math.floor(e.index/e.actors.length)*e.actors.length)+e.index)%e.actors.length;c.onMove.apply(this);c.updatePaging.apply(this);e.effect[d].apply(e.effect,Array.prototype.slice.call(arguments,1));break;case"play":case"stop":c[d].apply(this,arguments);break;default:a.error('Elixon Theatre method "'+d+'" does not exist on jQuery.theatre!')}};c.init=function(d){c.destroy.apply(this);var e={selector:'> *:not(".theatre-control")',effect:"horizontal",speed:1e3,still:3e3,autoplay:true,controls:"horizontal",itemWidth:false,itemHeight:false,width:false,height:false,onMove:false};if(d){a.extend(e,d)}var f=a(e.selector,this);var g={paging:e.paging&&a(e.paging),actors:f,effect:false,settings:e,interval:false,index:0};var h=typeof e.effect=="function"?e.effect:b[e.effect]||c.loadEffect(e.effect);if(!h)a.error('Elixon Theatre does not support effect "'+e.effect+'"!');g.effect=new b[e.effect](this,f,e,g);this.addClass("theatre").data("theatre",g);this.addClass("theatre-"+e.effect.replace(/[^a-z0-9]+/ig,"-"));if(e.width)this.css("width",e.width);if(e.height)this.css("height",e.height);f.each(function(){var b=a(this);if(!b.data("theatre")){b.data("theatre",{width:b.width(),height:b.height()})}b.load(function(){b.data("theatre",{width:b.width(),height:b.height()})})});if(e.itemWidth||e.itemHeight){var i=this;f.each(function(){var b=a(this);if(e.itemWidth){b.css("width",e.itemWidth=="max"?i.width()-b.outerWidth()+b.width()+"px":e.itemWidth)}if(e.itemHeight){b.css("height",e.itemHeight=="max"?i.height()-b.outerHeight()+b.height()+"px":e.itemHeight)}})}f.addClass("theatre-actor").stop(true,true);g.effect.init();if(e.autoplay){c.play.apply(this)}c.appendControls.apply(this);c.onMove.apply(this);c.generatePaging.apply(this)};c.onMove=function(){var a=this.data("theatre");if(typeof a.settings.onMove!="function")return;a.settings.onMove.apply(this,[a.index,a.actors[a.index],a]);this.trigger("theatreMove",[a.index,a.actors[a.index],a])};c.generatePaging=function(){var b=this;var d=this.data("theatre");if(!d.paging)return;d.paging.each(function(){var c=a(this);var e=[];a("> *",c).each(function(){e.push(a("<div></div>").append(this).html())});var f=e[e.length-1];for(var g=0;g<d.actors.length;g++){var h=e.length<g+1?f:e[g];(function(a){c.append(h.replace("{#}",a)+"\n");c.children().last().click(function(){b.theatre("jump",a)})})(g+1)}});c.updatePaging.apply(this)};c.updatePaging=function(){var b=this.data("theatre");if(!b.paging)return;b.paging.each(function(){var c=a(this);a("> *",c).removeClass("active").eq(b.index).addClass("active")})};c.appendControls=function(){settings=this.data("theatre").settings;if(settings.controls=="horizontal"||settings.controls=="vertical"){var b=this;this.append('<a class="theatre-control theatre-control-'+settings.controls+'-next theatre-next"><span></span></a>');this.append('<a class="theatre-control theatre-control-'+settings.controls+'-prev theatre-prev"><span></span></a>');this.append('<a class="theatre-control theatre-control-'+settings.controls+'-play theatre-play"><span></span></a>');this.append('<a class="theatre-control theatre-control-'+settings.controls+'-stop theatre-stop"><span></span></a>');a(".theatre-next",this).click(function(){b.theatre("next")});a(".theatre-prev",this).click(function(){b.theatre("prev")});a(".theatre-play",this).click(function(){b.theatre("play")});a(".theatre-stop",this).click(function(){b.theatre("stop")});this.mouseenter(function(){a(".theatre-control",b).fadeIn()});this.mouseleave(function(){a(".theatre-control",b).fadeOut()});a(".theatre-control",this).fadeOut(0)}this.append('<a class="theatre-control theatre-sign" rel="copyright license" style="position: absolute !important; display: none !important;" href="http://www.webdevelopers.eu/jquery/theatre" title="jQuery carousel plugin"><span style="display: none !important;">Elixon Theatre jQuery Plugin</span></a>')};c.destroy=function(){var b=this.data("theatre");if(b){clearInterval(b.interval);this.theatre("jump",0);if(typeof b.effect.destroy=="function")b.effect.destroy();this.removeClass("theatre-"+b.settings.effect.replace(/[^a-z0-9]+/ig,"-"));b.actors.each(function(){var b=a(this);var c=b.data("theatre");b.width(c.width);b.height(c.height)})}a(".theatre-control",this).remove()};c.play=function(){var a=this.data("theatre");var b=this;b.theatre("stop");a.interval=setInterval(function(){b.theatre("next",true)},a.settings.speed+a.settings.still)};c.stop=function(){var a=this.data("theatre");clearInterval(a.interval);a.interval=false};b["fade"]=b["slide"]=b["show"]=function(a,b,c,d){var e={fade:{show:"fadeIn",hide:"fadeOut",initStyle:{margin:0,top:0,left:0,position:"absolute",display:"none"}},slide:{show:"slideDown",hide:"slideUp",initStyle:{}},show:{show:"show",hide:"hide",initStyle:{}}}[c.effect];this.init=function(){b[e.hide](0).css(e.initStyle).first()[e.show](0)};this.next=function(){b.stop(true,true).css("z-index",0)[e.hide](c.speed).eq(d.index).css("z-index",10)[e.show](c.speed)};this.prev=function(){b.stop(true,true).css("z-index",0)[e.hide](c.speed).eq(d.index).css("z-index",10)[e.show](c.speed)};this.destroy=function(){b.stop(true,true).css({zIndex:"",top:"",left:"",position:"",margin:""})[e.show](0)}};b["vertical"]=b["horizontal"]=function(b,c,d){var e={horizontal:{size:"outerWidth",direction:"left"},vertical:{size:"outerHeight",direction:"top"}}[d.effect];this.init=function(){c.fadeOut(0);this.align(0,0);c.fadeIn()};this.next=function(){var c=a(d.selector,b).first();var f=this.align(-c[e.size](true));var g=c.parentsUntil(".theatre");(g.length?g:c).last().appendTo(b)};this.prev=function(){var c=a(d.selector,b).last();var f=c.parentsUntil(".theatre");(f.length?f:c).last().prependTo(b);c.stop(true,true).css(e.direction,-c[e.size](true));this.align(0)};this.destroy=function(){c.stop(true,true).css(e.direction,"").css({opacity:"",left:"",top:""})};this.align=function(c,f){var g=false;a(d.selector,b).each(function(){var b=null;var g=a(this);if(c<0){b=function(){g.css(e.direction,c)}}var h={};h[e.direction]=c;g.stop(true,true).animate(h,isNaN(f)?d.speed:f,b);c+=g[e.size](true)});return c}};b["3d"]=function(b,c,d){d.resize=false;var e=0;var f=[];var g;var h;this.init=function(){var a=this;g=b.width()*.5;h=b.height()*.8;c.each(function(a){var d=2*Math.PI*a/c.length+Math.PI/2;var e=Math.cos(d);var g=Math.sin(d);var h=10;var i=.2;var j=(g+1)/2*(1-i)+i;var k=e*(b.width()-h)/2+b.width()/2;var l=g*(b.height()-h)/2+b.height()/2;f.push({left:k,top:l,x:e,y:g,size:j,rad:d})});this.animate()};this.next=function(){if(++e>c.length-1)e=0;this.animate()};this.prev=function(){if(--e<0)e=c.length-1;this.animate()};this.destroy=function(){c.stop(true,true).css({"z-index":"",opacity:"",left:"",top:""})};this.animate=function(){var b=this;c.stop();c.each(function(i){var j=f[(i-e+c.length)%c.length];var k=b.calcDim(a(this),g,h,j.size);var l=Math.round(j.left-j.x*k[0]/2-k[0]/2);var m=Math.round(j.top-j.y*k[1]/2-k[1]/2);a(this).css({"z-index":Math.round(j.size*1e3)}).animate({opacity:j.size,left:l,top:m,width:k[0],height:k[1]},d.speed)})};this.calcDim=function(a,b,c,d){var e=a.data("theatre");var f=b;var g=e.height/e.width*f;if(g>c){f=b*(c/g);g=c}return[Math.round(f*d),Math.round(g*d)]}}})(jQuery)

