(function(c){function b(j,h,f,e){var i=j[h];if(c.isFunction(i)){try{return i.call(f,e)}catch(g){if(j.alert){alert("Error calling scrollable."+h+": "+g)}else{throw g}return false}}return true}var d=null;function a(o,m){var r=this;if(!d){d=r}var e=!m.vertical;var g=c(m.items,o);var k=0;var p=o.siblings(m.navi).eq(0);var h=o.siblings(m.prev).eq(0);var j=o.siblings(m.next).eq(0);var i=o.siblings(m.prevPage).eq(0);var n=o.siblings(m.nextPage).eq(0);c.extend(r,{getVersion:function(){return[1,0,1]},getIndex:function(){return k},getConf:function(){return m},getSize:function(){return r.getItems().size()},getPageAmount:function(){return Math.ceil(this.getSize()/m.size)},getPageIndex:function(){return Math.ceil(k/m.size)},getRoot:function(){return o},getItemWrap:function(){return g},getItems:function(){return g.children()},seekTo:function(t,z,u){z=z||m.speed;if(c.isFunction(z)){u=z;z=m.speed}if(t<0){t=0}if(t>r.getSize()-m.size){return r}var v=r.getItems().eq(t);if(!v.length){return r}if(b(m,"onBeforeSeek",r,t)===false){return r}if(e){var y=-(v.outerWidth(true)*t);g.animate({left:y},z,m.easing,u?function(){u.call(r)}:null)}else{var x=-(v.outerHeight(true)*t);g.animate({top:x},z,m.easing,u?function(){u.call(r)}:null)}if(p.length){var s=m.activeClass;var w=Math.ceil(t/m.size);w=Math.min(w,p.children().length-1);p.children().removeClass(s).eq(w).addClass(s)}if(t===0){h.add(i).addClass(m.disabledClass)}else{h.add(i).removeClass(m.disabledClass)}if(t>=r.getSize()-m.size){j.add(n).addClass(m.disabledClass)}else{j.add(n).removeClass(m.disabledClass)}d=r;k=t;b(m,"onSeek",r,t);return r},move:function(u,t,s){var v=k+u;if(m.loop&&v>(r.getSize()-m.size)){v=0}return this.seekTo(v,t,s)},next:function(t,s){return this.move(1,t,s)},prev:function(t,s){return this.move(-1,t,s)},movePage:function(u,t,s){return this.move(m.size*u,t,s)},setPage:function(w,x,u){var t=m.size;var s=t*w;var v=s+t>=this.getSize();if(v){s=this.getSize()-m.size}return this.seekTo(s,x,u)},prevPage:function(t,s){return this.setPage(this.getPageIndex()-1,t,s)},nextPage:function(t,s){return this.setPage(this.getPageIndex()+1,t,s)},begin:function(t,s){return this.seekTo(0,t,s)},end:function(t,s){return this.seekTo(this.getSize()-m.size,t,s)},reload:function(){return q()},click:function(t,w,u){var v=r.getItems().eq(t);var s=m.activeClass;if(!v.hasClass(s)&&(t>=0||t<this.getSize())){r.getItems().removeClass(s);v.addClass(s);var y=Math.floor(m.size/2);var x=t-y;if(x>r.getSize()-m.size){x--}if(x!==t){return this.seekTo(x,w,u)}}return r}});if(c.isFunction(c.fn.mousewheel)){o.bind("mousewheel.scrollable",function(t,u){var s=c.browser.opera?1:-1;r.move(u>0?s:-s,50);return false})}h.addClass(m.disabledClass).click(function(){r.prev()});j.click(function(){r.next()});n.click(function(){r.nextPage()});i.addClass(m.disabledClass).click(function(){r.prevPage()});if(m.keyboard){c(window).unbind("keypress.scrollable").bind("keypress.scrollable",function(s){var t=d;if(!t){return}if(e&&(s.keyCode==37||s.keyCode==39)){t.move(s.keyCode==37?-1:1);return s.preventDefault()}if(!e&&(s.keyCode==38||s.keyCode==40)){t.move(s.keyCode==38?-1:1);return s.preventDefault()}return true})}function q(){p.each(function(){var v=c(this);if(v.is(":empty")||v.data("me")==r){v.empty();v.data("me",r);for(var t=0;t<r.getPageAmount();t++){var u=c("<"+m.naviItem+"/>").attr("href",t).click(function(x){var w=c(this);w.parent().children().removeClass(m.activeClass);w.addClass(m.activeClass);r.setPage(w.attr("href"));return x.preventDefault()});if(t===0){u.addClass(m.activeClass)}v.append(u)}}else{var s=v.children();s.each(function(w){var x=c(this);x.attr("href",w);if(w===0){x.addClass(m.activeClass)}x.click(function(){v.find("."+m.activeClass).removeClass(m.activeClass);x.addClass(m.activeClass);r.setPage(x.attr("href"))})})}});if(m.clickable){r.getItems().each(function(t,s){var u=c(this);if(!u.data("set")){u.bind("click.scrollable",function(){r.click(t)});u.data("set",true)}})}if(m.hoverClass){r.getItems().hover(function(){c(this).addClass(m.hoverClass)},function(){c(this).removeClass(m.hoverClass)})}return r}q();var f=null;function l(){f=setInterval(function(){r.next()},m.interval)}if(m.interval>0){o.hover(function(){clearInterval(f)},function(){l()});l()}}jQuery.prototype.scrollable=function(e){var f=this.eq(typeof e=="number"?e:0).data("scrollable");if(f){return f}var g={size:5,vertical:false,clickable:true,loop:false,interval:0,speed:400,keyboard:true,activeClass:"active",disabledClass:"disabled",hoverClass:null,easing:"swing",items:".items",prev:".prev",next:".next",prevPage:".prevPage",nextPage:".nextPage",navi:".navi",naviItem:"a",onBeforeSeek:null,onSeek:null,alert:true};c.extend(g,e);this.each(function(){var h=new a(c(this),g);c(this).data("scrollable",h)});return this}})(jQuery);