$(document).ready(function()
{$(".ui-scroller").each(function(i){var autoScrollTimer
var index=0;var scroller=$(this).css({position:"relative",overflow:"hidden"})
var controlWidth=scroller.innerWidth()
var items=scroller.children().css({"width":controlWidth,"float":"left"})
var scrollPane=$("<div class=\"scroller\"></div>").append(items).appendTo(this).css({width:(controlWidth*items.length),position:"relative"})
if(items.length>1)
{$("<a class='prev' href='#'>Previous</a>").appendTo(this).bind("click",function(e){scrollTo(index-1);e.preventDefault();return false})
$("<a class='next' href='#'>Next</a>").appendTo(this).bind("click",function(e){scrollTo(index+1);return false})}
scroller.bind("mouseover",function(){pause()})
scroller.bind("mouseout",function(){play()})
play()
function pause()
{if(autoScrollTimer)autoScrollTimer=clearInterval(autoScrollTimer)}
function play()
{pause()
autoScrollTimer=setInterval(function(){scrollTo(++index)},7000+i*500)}
function scrollTo(newIndex)
{switch(newIndex)
{case-1:index=items.length-1;break;case items.length:index=0;break;default:index=newIndex;break;}
var end=index*controlWidth
scrollPane.stop();scrollPane.animate({left:-end+"px"},350)}})})
