$(document).ready(function(){
    function set_width(){
        var width = $('#gray_header_line').width()-300;
        var floor = Math.floor(width/174);
        if(width > 870){
            width = 870;
        } else {
            width = floor * 174;
        }
        return width;
    }
    $('#carousel_inner').css('width',set_width());
    $('#carousel_ul li:first').before($('#carousel_ul li:last'));

    $('#scroll_div .prev').click(function(){
        var link = $(this);
        //link.css('background-position','0 -32px').unbind('mouseout');
        $('#carousel_ul:not(:animated)').animate({'left' : '-=174px'},500,function(){
            $('#carousel_ul li:last').after($('#carousel_ul li:first'));
            $(this).css('left','-174px');
            //link.css('background-position','0 0').bind('mouseout');
        });
    });

    $('#scroll_div .next').click(function(){
        var link = $(this);
        //link.css('background-position','0 -32px').unbind('mouseout');
        $('#carousel_ul:not(:animated)').animate({'left' : '+=174px'},500,function(){
            $('#carousel_ul li:first').before($('#carousel_ul li:last'));
            $(this).css('left','-174px');
            //link.css('background-position','0 0').bind('mouseout');
        });
    });
    $('#scroll_div a.next, #scroll_div a.prev').mouseover(function(){
        $(this).css('background-position','0 -16px');
    }).mouseout(function(){
        if($('#carousel_ul:not(:animated)')){
            $(this).css('background-position','0 0');
        }
    });
    $(window).resize(function(){
       $('#carousel_inner').css('width',set_width()+"px");
    })
});



