var topElementId = '0', t, b, width_i;
var height_i;
var downElementId;
var el;

$(document).ready(function(){
downElementId = jQuery('#scroller').children().size()-1;
if ($.browser.msie  ){
width_i = 97;
}
else
{
width_i = parseInt($(".items_rotater").css("width").slice(0,-2)) + parseInt($(".items_rotater").css("margin-left").slice(0,-2)) + parseInt($(".items_rotater").css("margin-right").slice(0,-2)) + parseInt($(".items_rotater").css("padding-left").slice(0,-2)) + parseInt($(".items_rotater").css("padding-right").slice(0,-2));
}

el = $('#scroller').children();
$("#scroller").css("width",el.size()*width_i+20+"px");
$("#category").css("width",3*width_i-3+"px");
if (el.size() > 3) {
el.each(function(i){ $(this).attr('id','row'+i); });
t = setTimeout('listSlideUp()', 3000);
}
 
 $("#left").click(function(){
 clearTimeout(t);
 t = setTimeout('listSlideUp()', 500);
 });
 
 $("#right").click(function(){
 clearTimeout(t)
 t = setTimeout('listSlideDown()', 500);
 });

 $("#stop").click(function(){
 clearTimeout(t)
 });
 });


function listSlideUp() {
 $('#scroller').animate({"left": "-="+width_i+"px"}, 500, function(){
 if (topElementId >= 0) {
 var topElement = jQuery('#row'+topElementId).clone().show();
 $('#row'+topElementId).remove();
 $('#scroller').append(topElement);
 $('#scroller').css("left","0px")
 }
 topElementId++;
 downElementId++;
 if (topElementId > jQuery('#scroller').children().size()-1) {
 topElementId = 0;
 }
 if (downElementId > jQuery('#scroller').children().size()-1) {
 downElementId = 0;
 }
 if (downElementId < 0) {
 downElementId = jQuery('#scroller').children().size()-1;
 }
 if (topElementId < 0) {
 topElementId = jQuery('#scroller').children().size()-1;
 }
 });
 t = setTimeout('listSlideUp()', 4000);
 }

 function listSlideDown() {
 if (downElementId < jQuery('#scroller').children().size()) {
 var downElement = jQuery('#row'+downElementId).clone().show();
 $('#row'+downElementId).remove();
 $('#scroller').prepend(downElement);
 $('#scroller').css("left","-"+width_i+"px")
 }
 downElementId--;
 topElementId--;
 if (topElementId > jQuery('#scroller').children().size()-1) {
 topElementId = 0;
 }
 if (downElementId > jQuery('#scroller').children().size()-1) {
 downElementId = 0;
 }
 if (downElementId < 0) {
 downElementId = jQuery('#scroller').children().size()-1;
 }
 if (topElementId < 0) {
 topElementId = jQuery('#scroller').children().size()-1;
 }
 $('#scroller').animate({"left": "+="+width_i+"px"}, 500, function(){});
 t = setTimeout('listSlideDown()', 4000);
 }
