(function(d){d.fn.qlgallery=function(r){var b=d.extend({},d.fn.qlgallery.defaultOptions,r);return this.each(function(){var f=d(this),l,o=(new Date).getTime(),c=0,q=f.attr("id")?f.attr("id"):"gal_"+o,g=f.children(),h=f.width(),j=g.length*h,e=d("<div>",{id:"viewer"+o,"class":"ql_gallery_viewer",style:"width:2000em;"}),m={init:function(){f.attr("id")!==q&&f.attr("id",q);g.wrapAll(e);e=d("#viewer"+o);if(b.infinite===true){e.css("left","-"+h+"px");g.eq(0).clone().appendTo(e);g.eq(g.length-1).clone().prependTo(e);
j=g.length}d.each(b.controls,function(a,k){k.href=="#play"&&!b.play||d("<a>",k).appendTo(f)});f.delegate("a","click",m.go);f.find(".play").bind("click",function(a){if(l){clearTimeout(l);l=null;d(a.target).text("Play")}else{m.play();d(a.target).text("Stop")}return false});if(b.autoplay)setTimeout(function(){if(l)return false;f.find(".play").trigger("click")},typeof b.autoplay=="number"?b.autoplay:8E3)},go:function(){if(e.is(":animated")===false){var a,k,i,p;i=m.diff();var n=d(this).attr("class");if(b.infinite===
true){i={left:"-="+h+"px"};p={left:"+="+h+"px"};if(n=="next"){a=[i,p];c=(c+1)%j;k="> :first-child";g.eq(c).clone().appendTo(e)}if(n=="back"){a=[p,i];c=c-1<0?j+(c-1):(c-1)%j;k="> :last"}e.animate(a[0],b.speed,b.easing,function(){e.find(k).remove();n=="back"&&g.eq(c-1).clone().prependTo(e);e.animate(a[1],0);if(d.isFunction(b.callback))return b.callback.apply(this,[c,e.css("left")])})}else{if(n=="next"){a=i.rel!==h?{left:i.pos-h+"px"}:{left:"0px"};c=(c+1)%g.length}if(n=="back"){a=i.rel!==j?{left:i.pos+
h+"px"}:{left:"-"+(j-h)+"px"};c=c-1<0?g.length+(c-1):(c-1)%g.length}e.animate(a,b.speed,b.easing,function(){if(d.isFunction(b.callback))return b.callback.call(this,c)});return false}}},diff:function(){var a=e.position().left;if(jQuery.browser.version=="8.0"&&a<-1)a-=1;return{pos:a,rel:Math.floor(a+j)}},play:function(){var a=typeof b.play=="number"?b.play:8E3;f.find(".next").trigger("click");l=setTimeout(m.play,a)}};return m.init()})};d.fn.qlgallery.defaultOptions={speed:600,easing:false,slides:1,
play:false,autoplay:false,infinite:false,callback:false,controls:[{href:"#back","class":"back",text:"Back"},{href:"#next","class":"next",text:"Next"},{href:"#play","class":"play",text:"Play"}]}})(jQuery);

