(function(a){a.fn.marquee=function(b){b=a.extend({vertical:true,speed:500,delay:3e3,interactive:true,visibleItems:1},b||{});return this.each(function(){var c=a(this);c.css("overflow","hidden");!b.vertical&&c.css("white-space","nowrap");var d=[],h=0,e=0,i=false,j="playing",l,n=0,g=true;m();o();f();b.interactive&&c.mouseover(function(){j="stopped";f()}).mouseout(function(){j="playing";f()});function m(){d=[];var h=c.children().length;if(h>b.visibleItems){var e=c.children().first();e.clone().appendTo(c);var f=1;while(f%b.visibleItems!=0){e=e.next();e.clone().appendTo(c);f++}g=true}else g=false;c.children().each(function(){var b=a(this);d.push(b)})}function o(){h=0;var e=b.visibleItems,f=n=parseInt(Math.round((b.vertical?c.height():c.width())*1/(e*1)));a.each(d,function(g,e){var a=e,c=b.vertical?"height":"width";a.css("overflow","hidden").css(c,f+"px");!b.vertical&&a.css("display","inline-block");a.data("scrollTarget",h);if(g<d.length-1)h+=b.vertical?a.outerHeight():a.outerWidth()})}function f(){switch(j){case"playing":l=setTimeout(p,b.delay);break;case"stopped":clearTimeout(l)}}function p(){if(!i){if(d.length==0){f();return}i=true;e=(e+1)%d.length;var a=d[e].data("scrollTarget"),h=c[0]._scrollPosition=b.vertical?c.scrollTop():c.scrollLeft();if(!g)k();else c.animate({_scrollPosition:a},{step:function(a){if(b.vertical)c.scrollTop(a);else c.scrollLeft(a)},duration:b.speed,complete:k})}}function k(){if(e>=d.length-(g?b.visibleItems:0)){e=0;if(b.vertical)c.scrollTop(0);else c.scrollLeft(0)}i=false;f()}})};a.fn.marquee.version="1.0"})(jQuery)
