
(function($){$.fn.scroller=function(options){return this.each(function(){if(this._scroller>0)return;elecounter++;this._scroller=elecounter;var elecount=0,av_width=0,av_height=0,max_h=0,last_height=0,target=this._scroller,start_h=0;var params=$.extend({},$.fn.scroller.defaults,options);H[elecounter]={params:params,target:this,items:{},max_h:0,current_page:params['start'],timed:false};if(jQ('body').find(params['controller']).length){jQ(this).find(params['item']).each(function(){elecount++;var nv_width=jQ(this).outerWidth();var divid=parseInt($(this).attr('id').replace(params['href_prefix'].replace('#',''),''));jQ(this).addClass('is_item_'+divid).css('position',params['position_type']).css('left',nv_width+'px').css('top','0px').css('z-index',elecount);this._scroll_item=divid;H[elecounter].items[divid]=this;av_width+=jQ(this).outerWidth();av_height+=jQ(this).outerHeight();if(jQ(this).outerHeight()>max_h)max_h=jQ(this).outerHeight();});av_width=av_width/elecount;av_height=av_height/elecount;H[elecounter].max_h=max_h;if(elecount>params['visible'])var items_shown=params['visible'];else var items_shown=elecount;jQ(params['container']).css('width',(av_width*items_shown)+'px').css('overflow','hidden');$.scroller.moveto(target,params['start'],params['animate_onload']);if(elecount<params['visible'])jQ(params['controller']).find('li.previous, li.next').addClass('disabled');jQ(params['controller']).find('.'+params['href_prefix'].replace('#','')+params['start']).parent().addClass('active');jQ(params['controller']).find('a').addClass('trigger');$.scroller.init(elecounter);if(params['auto']&&typeof(params['auto'])=="number")H[elecounter].timed=setTimeout("$.scroller.moveto("+(current_page+1)+");",params['auto']);}else alert('NO CONTROLS!');});},$.fn.scroll_to=function(item_number){return $.scroller.moveto(this._scroller,item_number,true);},$.fn.scroller_reinit=function(){return $.scroller.init(this._scroller);}
$.scroller={hash:{},init:function(target){var hashed=H[target],params=hashed.params;jQ(params['controller']).find('a.trigger').click(function(){var pgid=jQ(this).attr('href');if(jQ(this).parent().hasClass('disabled'))return false;else $.scroller.moveto(target,parseInt(pgid.replace(params['href_prefix'],'')),params['animate']);jQ(params['controller']).find('li').removeClass('active');jQ(params['controller']).find('a.'+pgid.replace('#','')).parent().addClass('active');jQ(this).parent().parent().children().removeClass('active');jQ(this).parent().addClass('active');return false;});},beforemove:function(hashed,item_number,target){clearTimeout(hashed.timed);hashed.current_page=item_number;if(hashed.params['before'])eval(hashed.params['before']);},aftermove:function(hashed,item_number,target){var curr=hashed.items[item_number];if(hashed.params['before'])eval(hashed.params['after']);if(hashed.params['tag_body'])$('body').attr('id','body_'+hashed.params['href_prefix'].replace('#','')+item_number);if(hashed.params['auto']&&typeof(hashed.params['auto'])=="number")hashed.timed=setTimeout("$.scroller.moveto("+target+","+((hashed.current_page)+1)+", "+hashed.params['animate']+");",hashed.params['auto']);if(hashed.params['height_resize'])jQ(hashed.params['container']).css('height',jQ(curr).outerHeight()+'px');},moveto:function(target,item_number,animate){var hashed=H[target];$.scroller.beforemove(hashed,item_number,target);for(i in hashed.items){var h=hashed.items[i],av_width=jQ(h).outerWidth();var pos=h._scroll_item;if(pos<item_number){if(animate)jQ(h).animate({'left':"-"+(av_width*(item_number-pos))+'px'},hashed.params['speed']);else jQ(h).css('left',"-"+(av_width*(item_number-pos))+'px');}else if(pos==item_number){if(animate)jQ(h).animate({'left':'0px'},hashed.params['speed'],function(){$.scroller.aftermove(hashed,item_number,target);});else{$.scroller.aftermove(hashed,item_number,target);jQ(h).css('left','0px');}}else{if(animate)jQ(h).animate({'left':(av_width*(pos-item_number))+'px'},hashed.params['speed']);else jQ(h).css('left',(av_width*(pos-item_number))+'px');}}
jQ(hashed.params['controller']).find('li').removeClass('disabled');if(item_number>1)jQ(hashed.params['controller']).find('li.previous a').attr('href',hashed.params['href_prefix']+(item_number-1));else jQ(hashed.params['controller']).find('li.previous').addClass('disabled');if(item_number+hashed.params['visible']<=i)jQ(hashed.params['controller']).find('li.next a').attr('href',hashed.params['href_prefix']+(item_number+1));else jQ(hashed.params['controller']).find('li.next').addClass('disabled');}};$.fn.scroller.defaults={start:1,speed:'slow',visible:1,container:'#container',controller:'#controls',item:'.item',before:false,after:false,auto:false,href_prefix:'#item_',animate:true,animate_onload:false,tag_body:false,position_type:'absolute',height_resize:true};var jQ=jQuery,current_page=0,elecounter=0,H=$.scroller.hash,ie6=$.browser.msie&&($.browser.version=="6.0");})(jQuery);
