(function(n){"use strict";n.fn.bjqs=function(t){var r=n.extend({},{width:700,height:300,animtype:"fade",animduration:450,animspeed:4e3,automatic:!0,showcontrols:!1,centercontrols:!0,nexttext:"Next",prevtext:"Prev",showmarkers:!0,centermarkers:!0,keyboardnav:!0,hoverpause:!0,usecaptions:!1,randomstart:!0,responsive:!1},t),o=this,e=o.find("ul.bjqs"),f=e.children("li"),l=null,y=null,p=null,c=null,v=null,a=null,w=null,b=null,i={slidecount:f.length,animating:!1,paused:!1,currentslide:1,nextslide:0,currentindex:0,nextindex:0,interval:null},u={width:null,height:null,ratio:null},s={fwd:"forward",prev:"previous"},k=function(){f.addClass("bjqs-slide");r.responsive?d():nt();i.slidecount>1?(r.randomstart&&ot(),r.showcontrols&&it(),r.showmarkers&&rt(),r.keyboardnav&&ut(),r.hoverpause&&r.automatic&&ft(),r.animtype==="slide"&&tt()):r.automatic=!1;r.usecaptions&&et();r.animtype!=="slide"||r.randomstart||(i.currentindex=1,i.currentslide=2);e.show();f.eq(i.currentindex).show();r.automatic&&(i.interval=setInterval(function(){h(s.fwd,!1)},r.animspeed))},d=function(){u.width=o.outerWidth();u.ratio=u.width/r.width;u.height=r.height*u.ratio;r.animtype==="fade"&&(f.css({height:r.height,width:"100%"}),f.children("img").css({height:r.height,width:"100%"}),e.css({height:r.height,width:"100%"}),o.css({height:r.height,"max-width":r.width,position:"relative"}),u.width<r.width&&(f.css({height:u.height}),f.children("img").css({height:u.height}),e.css({height:u.height}),o.css({height:u.height})),n(window).resize(function(){u.width=o.outerWidth();u.ratio=u.width/r.width;u.height=r.height*u.ratio;f.css({height:u.height});f.children("img").css({height:u.height});e.css({height:u.height});o.css({height:u.height})}));r.animtype==="slide"&&(f.css({height:r.height,width:r.width}),f.children("img").css({height:r.height,width:r.width}),e.css({height:r.height,width:r.width*r.slidecount}),o.css({height:r.height,"max-width":r.width,position:"relative"}),u.width<r.width&&(f.css({height:u.height}),f.children("img").css({height:u.height}),e.css({height:u.height}),o.css({height:u.height})),n(window).resize(function(){u.width=o.outerWidth();u.ratio=u.width/r.width;u.height=r.height*u.ratio;f.css({height:u.height,width:u.width});f.children("img").css({height:u.height,width:u.width});e.css({height:u.height,width:u.width*r.slidecount});o.css({height:u.height});a.css({height:u.height,width:u.width});g(function(){h(!1,i.currentslide)},200,"some unique string")}))},g=function(){var n={};return function(t,i,r){r||(r="Don't call this twice without a uniqueId");n[r]&&clearTimeout(n[r]);n[r]=setTimeout(t,i)}}(),nt=function(){f.css({height:r.height,width:r.width});e.css({height:r.height,width:r.width});o.css({height:r.height,width:r.width,position:"relative"})},tt=function(){w=f.eq(0).clone();b=f.eq(i.slidecount-1).clone();w.attr({"data-clone":"last","data-slide":0}).appendTo(e).show();b.attr({"data-clone":"first","data-slide":0}).prependTo(e).show();f=e.children("li");i.slidecount=f.length;a=n('<div class="bjqs-wrapper"><\/div>');r.responsive&&u.width<r.width?(a.css({width:u.width,height:u.height,overflow:"hidden",position:"relative"}),e.css({width:u.width*(i.slidecount+2),left:-u.width*i.currentslide})):(a.css({width:r.width,height:r.height,overflow:"hidden",position:"relative"}),e.css({width:r.width*(i.slidecount+2),left:-r.width*i.currentslide}));f.css({float:"left",position:"relative",display:"list-item"});a.prependTo(o);e.appendTo(a)},it=function(){l=n('<ul class="bjqs-controls"><\/ul>');y=n('<li class="bjqs-next"><a href="#" data-direction="'+s.fwd+'">'+r.nexttext+"<\/a><\/li>");p=n('<li class="bjqs-prev"><a href="#" data-direction="'+s.prev+'">'+r.prevtext+"<\/a><\/li>");l.on("click","a",function(t){t.preventDefault();var r=n(this).attr("data-direction");i.animating||(r===s.fwd&&h(s.fwd,!1),r===s.prev&&h(s.prev,!1))});if(p.appendTo(l),y.appendTo(l),l.appendTo(o),r.centercontrols){l.addClass("v-centered");var u=(o.height()-y.children("a").outerHeight())/2,f=u/r.height*100,t=f+"%";y.find("a").css("top",t);p.find("a").css("top",t)}},rt=function(){if(c=n('<ol class="bjqs-markers"><\/ol>'),n.each(f,function(t){var e=t+1,f=t+1,u;r.animtype==="slide"&&(f=t+2);u=n('<li><a href="#">'+e+"<\/a><\/li>");e===i.currentslide&&u.addClass("active-marker");u.on("click","a",function(n){n.preventDefault();i.animating||i.currentslide===f||h(!1,f)});u.appendTo(c)}),c.appendTo(o),v=c.find("li"),r.centermarkers){c.addClass("h-centered");var t=(r.width-c.width())/2;c.css("left",t)}},ut=function(){n(document).keyup(function(n){i.paused||(clearInterval(i.interval),i.paused=!0);i.animating||(n.keyCode===39?(n.preventDefault(),h(s.fwd,!1)):n.keyCode===37&&(n.preventDefault(),h(s.prev,!1)));i.paused&&r.automatic&&(i.interval=setInterval(function(){h(s.fwd)},r.animspeed),i.paused=!1)})},ft=function(){o.hover(function(){i.paused||(clearInterval(i.interval),i.paused=!0)},function(){i.paused&&(i.interval=setInterval(function(){h(s.fwd,!1)},r.animspeed),i.paused=!1)})},et=function(){n.each(f,function(t,i){var r=n(i).children("img:first-child").attr("title");r||(r=n(i).children("a").find("img:first-child").attr("title"));r&&(r=n('<p class="bjqs-caption">'+r+"<\/p>"),r.appendTo(n(i)))})},ot=function(){var n=Math.floor(Math.random()*i.slidecount)+1;i.currentslide=n;i.currentindex=n-1},st=function(n){n===s.fwd?f.eq(i.currentindex).next().length?(i.nextindex=i.currentindex+1,i.nextslide=i.currentslide+1):(i.nextindex=0,i.nextslide=1):f.eq(i.currentindex).prev().length?(i.nextindex=i.currentindex-1,i.nextslide=i.currentslide-1):(i.nextindex=i.slidecount-1,i.nextslide=i.slidecount)},h=function(n,t){if(!i.animating&&(i.animating=!0,t?(i.nextslide=t,i.nextindex=t-1):st(n),r.animtype==="fade"&&(r.showmarkers&&(v.removeClass("active-marker"),v.eq(i.nextindex).addClass("active-marker")),f.eq(i.currentindex).fadeOut(r.animduration),f.eq(i.nextindex).fadeIn(r.animduration,function(){i.animating=!1;i.currentslide=i.nextslide;i.currentindex=i.nextindex})),r.animtype==="slide")){if(r.showmarkers){var o=i.nextindex-1;o===i.slidecount-2?o=0:o===-1&&(o=i.slidecount-3);v.removeClass("active-marker");v.eq(o).addClass("active-marker")}i.slidewidth=r.responsive&&u.width<r.width?u.width:r.width;e.animate({left:-i.nextindex*i.slidewidth},r.animduration,function(){i.currentslide=i.nextslide;i.currentindex=i.nextindex;f.eq(i.currentindex).attr("data-clone")==="last"?(e.css({left:-i.slidewidth}),i.currentslide=2,i.currentindex=1):f.eq(i.currentindex).attr("data-clone")==="first"&&(e.css({left:-i.slidewidth*(i.slidecount-2)}),i.currentslide=i.slidecount-1,i.currentindex=i.slidecount-2);i.animating=!1})}};k()}})(jQuery)