(function(a){a.fn.imageScroller=function(b){return this.each(function(){var g=a(this);var c=0;var d=a.extend({speed:"2000",loading:"Loading images...",direction:"left",stopByMouse:false},b||{});g.children().hide();g.append("<div style='clear:both; padding: 0px; margin: 0px;'><div id='loading'>"+d.loading+"</div></div>");a("img",g).each(function(){var h=new Image();var i=a(this).attr("src");a(h).load(function(){c++}).attr("src",i)});var e=window.setInterval(function(){if(c==a("img",g).length){window.clearInterval(e);a("#loading").remove();g.children().show();var h=0;a.each(g.children(":not(div)"),function(){switch(d.direction){case"left":case"right":if(a(this).children().length){a(this).width(a(this).children(":eq(0)").width())}h+=a(this).width();break;case"top":case"bottom":a(this).css("display","block");if(a(this).children().length){a(this).height(a(this).children(":eq(0)").height())}h+=a(this).height();break}a(this).css({margin:"0px",padding:"0px",clear:"both"});if(d.stopByMouse){a(this).bind("mouseover",function(){a("div:eq(0)",g).stop()}).bind("mouseout",function(){f(a("div:eq(0)",g),d)})}a("div:eq(0)",g).append(a(this))});switch(d.direction){case"left":a("div:eq(0)",g).css("width",h+"px");break;case"right":a("div:eq(0)",g).css("width",h+"px");a("div:eq(0)",g).css({marginLeft:-(h-g.width())+"px"});break;case"top":a("div:eq(0)",g).css("height",h+"px");break;case"bottom":a("div:eq(0)",g).css("height",h+"px");a("div:eq(0)",g).css({marginTop:-(h-g.height())+"px"});break}f(a("div:eq(0)",g),d)}},100);function f(h,j){switch(j.direction){case"left":var l=-(h.children(":eq(0)").width());var i=j.speed-(Math.abs(parseInt(h.css("marginLeft")))*(j.speed/h.children(":eq(0)").width()));break;case"right":var l=-(h.width()-h.parents("div:eq(0)").width())+h.children(":last").width();var i=j.speed-((h.children(":last").width()-(Math.abs(parseInt(h.css("marginLeft")))-Math.abs(l)))*(j.speed/h.children(":last").width()));break;case"top":var k=-(h.children(":eq(0)").height());var i=j.speed-(Math.abs(parseInt(h.css("marginTop")))*(j.speed/h.children(":eq(0)").height()));break;case"bottom":var k=-(h.height()-h.parents("div:eq(0)").height())+h.children(":last").height();var i=j.speed-((h.children(":last").height()-(Math.abs(parseInt(h.css("marginTop")))-Math.abs(k)))*(j.speed/h.children(":last").height()));break}h.animate({marginLeft:(l||"0")+"px",marginTop:(k||"0")+"px"},i,"linear",function(){switch(j.direction){case"left":h.append(a(this).children(":eq(0)"));h.css("marginLeft","0px");break;case"right":h.prepend(a(this).children(":last"));h.css("marginLeft",-(h.width()-h.parents("div:eq(0)").width())+"px");break;case"top":h.append(a(this).children(":eq(0)"));h.css("marginTop","0px");break;case"bottom":h.prepend(a(this).children(":last"));h.css("marginTop",-(h.height()-h.parents("div:eq(0)").height())+"px");break}f(h,j)})}})}})(jQuery);