/**
 * jQuery Scrollbox Plugin Beta1
 *
 * @author Hunter Wu
 * @version Beta1 (last modified 6 Jan. 2010)
 */
(function(){jQuery.fn.scrollbox=function(a){a=jQuery.extend({linear:false,startDelay:4,delay:5,step:5,speed:32,switchItems:1,direction:"vertical",distance:"auto",autoPlay:true,onMouseOverPause:true,paused:false,queue:null},a);a.scrollOffset=a.direction=="vertical"?"scrollTop":"scrollLeft";if(a.queue)a.queue=jQuery("#"+a.queue);return this.each(function(){var f=null,e=null,i=false,c=jQuery(this);if(a.onMouseOverPause){c.bind("mouseover",function(){i=true});c.bind("mouseout",function(){i=false})}var d=c.children("ul:first-child"),
j=function(){if(!i){var b=d.children("li:first-child");b=a.distance!="auto"?a.distance:a.direction=="vertical"?b.height():b.width();if(a.linear)g=Math.min(c[0][a.scrollOffset]+a.step,b);else{g=Math.max(3,parseInt((b-c[0][a.scrollOffset])*0.3,10));var g=Math.min(c[0][a.scrollOffset]+g,b)}c[0][a.scrollOffset]=g;if(g>=b){for(b=0;b<a.switchItems;b++)if(a.queue&&a.queue.hasChildNodes()&&a.queue.getElementsByTagName("li").length>0){d.append(a.queue.getElementsByTagName("li")[0]);d.remove(d.children("li:first-child"))}else d.append(d.children("li:first-child"));
c[0][a.scrollOffset]=0;clearInterval(f);if(a.autoPlay)e=setTimeout(h,a.delay*1E3)}}},k=function(){if(!i){if(c[0][a.scrollOffset]==0){d.children("li");for(var b=0;b<a.switchItems;b++)d.children("li:last-child").insertBefore(d.children("li:first-child"));b=c.children("li:first-child");b=a.distance!="auto"?a.distance:a.direction=="vertical"?b.height():b.width();c[0][a.scrollOffset]=b}if(a.linear)b=Math.max(c[0][a.scrollOffset]-a.step,0);else{b=Math.max(3,parseInt(c[0][a.scrollOffset]*0.3,10));b=Math.max(c[0][a.scrollOffset]-
b,0)}c[0][a.scrollOffset]=b;if(b==0){clearInterval(f);if(a.autoPlay)e=setTimeout(h,a.delay*1E3)}}},h=function(){clearInterval(f);f=setInterval(j,a.speed)},l=function(){clearInterval(f);f=setInterval(k,a.speed)},m=function(b){a.delay=b||a.delay;clearTimeout(e);if(a.autoPlay)e=setTimeout(h,a.delay*1E3)};if(a.autoPlay)e=setTimeout(h,a.startDelay*1E3);c.bind("resetClock",function(b){m(b)});c.bind("forward",function(){clearTimeout(e);h()});c.bind("backward",function(){clearTimeout(e);l()});c.bind("speedUp",
function(b){if(typeof b=="undefined")b=Math.max(1,parseInt(a.speed/2,10));a.speed=b});c.bind("speedDown",function(b){if(typeof b=="undefined")b=a.speed*2;a.speed=b})})}})();

