/**
 * jQuery.scrollerota
 * Version 1.0
 * Copyright (c) 2011 c.bavota - http://bavotasan.com
 * Dual licensed under MIT and GPL.
 * Date: 02/04/2011
**/
(function($){$.fn.scrollerota=function(options){var defaults={width:800,height:300,padding:10,speed:3500,timer:8400,slideshow:true,easing:'easeInOutQuart'};var options=$.extend(defaults,options);return this.each(function(){var obj,images,texts,first,last,imglimit,txtlimit,itemNum,totalWidth,totalHeight,txtTop,imgLeft,txtMove,imgMove;obj=$(this);images=obj.find("ul.images");texts=obj.find("ul.text");first=images.find("li:first");last=images.find("li:last");first.clone().appendTo(images);last.clone().prependTo(images);first=texts.find("li:first");last=texts.find("li:last");first.clone().appendTo(texts);last.clone().prependTo(texts);itemNum=images.find("li").length;totalWidth=itemNum*options.width;totalHeight=itemNum*options.height;imglimit=-((itemNum-1)*options.width);txtlimit=-((itemNum-1)*options.height);images.css({width:totalWidth+"px",height:options.height+"px",left:-options.width+"px"}).find("li").css({width:options.width+"px",height:options.height+"px"}).end().find("li img").css({width:options.width+"px",height:options.height+"px"});texts.css({height:totalHeight+"px",top:-options.height+"px"}).find("li").css({height:(options.height-(options.padding*2))+"px",padding:options.padding+"px"});if(options.slideshow){loop=setTimeout(function(){autoScroll(1,1);},options.timer);obj.append('<div class="controls"><a href="javascript:void(0)" class="prev"></a> <a href="javascript:void(0)" class="play"></a> <a href="javascript:void(0)" class="pause"></a> <a href="javascript:void(0)" class="next"></a></div>')
obj.find(".pause").live("click",function(){clearTimeout(loop);obj.find(".play, .pause").toggle();});obj.find(".play").live("click",function(){loop=setTimeout(function(){autoScroll(1,1);},options.timer);obj.find(".play, .pause").toggle();});}else{obj.append('<div class="controls"><a href="javascript:void(0)" class="prev"></a> <a href="javascript:void(0)" class="next"></a></div>')}
obj.find(".next, .prev").live("click",function(){if($(this).hasClass("next")){autoScroll(1,0);}else{autoScroll(0,0);}
if(options.slideshow){clearTimeout(loop);obj.find(".play").show();obj.find(".pause").hide();}});function autoScroll(next,auto){txtTop=texts.css('top').replace("px","");imgLeft=images.css('left').replace("px","");txtMove=(next)?txtTop-options.height:parseInt(txtTop)+parseInt(options.height);imgMove=(next)?imgLeft-options.width:parseInt(imgLeft)+parseInt(options.width);texts.not(':animated').animate({top:txtMove+"px"},options.speed,options.easing,function(){if(txtMove==txtlimit){texts.css({top:-options.height+"px"});}
if(txtMove==0){texts.css({top:(txtlimit+options.height)+"px"});}});images.not(':animated').animate({left:imgMove+"px"},options.speed,options.easing,function(){if(imgMove==imglimit){images.css({left:-options.width+"px"});}
if(imgMove==0){images.css({left:(imglimit+options.width)+"px"});}});if(auto&&options.slideshow){loop=setTimeout(function(){autoScroll(1,1);},options.timer);}}});};})(jQuery);
