var Carousel = {
    speed: 3000,
    full_width: 0,
    item_width: 0,
    left_value: 0,

    BuildAll: function() {
        Carousel.Initialize();
    },

    Initialize: function() {
        var run = setInterval('Carousel.Rotate()', Carousel.speed);
        
        // Set the full width of the #main_images UL
        $(".gallery_mask ul").css({ width: ($(".gallery_mask li").width() * $(".gallery_mask li").length) + "px" });
        Carousel.full_width = $(".gallery_mask ul").width();

        Carousel.item_width = $('.gallery_mask li').outerWidth();

        //if mouse hover, pause the auto rotation, otherwise rotate it  
        $('.gallery_mask').hover(
            function() {clearInterval(run);},
            function() {run = setInterval('Carousel.Rotate()', Carousel.speed);}
        );
    },

    Rotate: function() {
        var left_indent = parseInt($('.gallery_mask ul').css('left')) - Carousel.item_width;
        if((Carousel.full_width * -1) == left_indent){ left_indent = 0; };
        $('.gallery_mask ul').animate({ 'left': left_indent }, 1000, function() {});
    },
};

$(document).ready(function() {
    Carousel.BuildAll();
});
