/*
var timer;
var totWidth = imgWidth*nbImages;
var imgWidthOffset = Math.round(imgWidth/10);
*/

function scroll() {
    var scrollingLeft = parseInt(jQuery("#scrolling").css("left"));
    var scrollingOffset = scrollingLeft % totWidth;
    if (-totWidth < scrollingLeft) jQuery("#scrolling").css("left", (scrollingLeft-1)+"px");
    else jQuery("#scrolling").css({ left: scrollingOffset+"px" });
    timer = setTimeout("scroll()", 50);
}

function scrollFwd() {
    var scrollingLeft = parseInt(jQuery("#scrolling").css("left"));
    var scrollingOffset = scrollingLeft % totWidth;
    if (-totWidth < scrollingLeft) jQuery("#scrolling").css("left", (scrollingLeft-1)+"px");
    else jQuery("#scrolling").css({ left: scrollingOffset+"px" });
    timer = setTimeout("scrollFwd()", 1);
}

function scrollRwd() {
    var scrollingLeft = parseInt(jQuery("#scrolling").css("left"));
    var scrollingOffset = scrollingLeft % totWidth;
    if ((carWidth-totWidth) > scrollingLeft) jQuery("#scrolling").css("left", (scrollingLeft+1)+"px");
    else jQuery("#scrolling").css({ left: (scrollingOffset-totWidth)+"px" });
    timer = setTimeout("scrollRwd()", 1);
}

jQuery(document).ready(function(){
    jQuery("#scrolling").append(jQuery("#scrolling").html());
    
    jQuery("#btFwd").hover(function(){
        clearTimeout(timer);
        scroll();
    }, function(){
        clearTimeout(timer);
        scroll();
    }
    ).mouseup(function(){
        clearTimeout(timer);
        scroll();
    }).mousedown(function(){
        clearTimeout(timer);
        scrollFwd();
    });
    
    jQuery("#btRwd").hover(function(){
        clearTimeout(timer);
        scroll();
    }, function(){
        clearTimeout(timer);
        scroll();
    }
    ).mouseup(function(){
        clearTimeout(timer);
        scroll();
    }).mousedown(function(){
        clearTimeout(timer);
        scrollRwd();
    });
    
    jQuery("#scrolling div").hover(function(){
        jQuery("#scrolling div").not(this).children("img").fadeTo("fast", 0.7);
        jQuery(this).children("img").animate({"width": "+="+imgWidthOffset+"px", "height": "+=13px"}, "fast");
        jQuery(this).children("p:first").css("bottom", "33px").css("background-color", "#00975A").css("opacity", 0.7);
        jQuery(this).children("p").show("fast");
        clearTimeout(timer);
    }, function(){
        jQuery("#scrolling div").not(this).children("img").fadeTo("fast", 1.0);
        jQuery(this).children("img").animate({"width": "-="+imgWidthOffset+"px", "height": "-=13px"}, "fast");
        jQuery(this).children("p").hide("fast");
        scroll();
    }).click(function(e){
        location.href=(jQuery(this).children("p").eq(1).children("a:first").attr("href"));
    });
    
    if ((typeof timer != "undefined") && (typeof totWidth != "undefined") && (typeof imgWidthOffset != "undefined")) {
      scroll();
    }

    setTimeout(function() { scroll(); }, 500);
});
