var scrollWrapW, myScroll;
var rollDirection = 0; //0Îª×ó 1ÎªÓÒ
var speed = 5000;
function __scrollBox() {
    if (rollDirection == 0) {
        scrollWrapW = -($('#newgoods li').eq(0).outerWidth(true) + $('#newgoods li').eq(1).outerWidth(true)) + 'px';
        $('ul').animate({ left: scrollWrapW }, {
            duration: 200,
            complete: function () {
                $('#newgoods').append($('#newgoods li:first')).append($('#newgoods li:first'));
                $('#newgoods').css("left", "0");
            }
        });
    } else {
        var last = $('#newgoods li').length - 1;
        var last2 = $('#newgoods li').length - 2;
        scrollWrapW = -($('#newgoods li').eq(last).outerWidth(true) + $('#newgoods li').eq(last2).outerWidth(true)) + 'px';
        $('ul').animate({ left: 0 }, {
            duration: 200,
            complete: function () {
                $('#newgoods').prepend($('#newgoods li:last')).prepend($('#newgoods li:last'));
                $('#newgoods').css("left", scrollWrapW);
            }
        });
    }
}
function mtitem(obj, height) {
    $(obj).find("ul:first").animate({
        marginTop: "-" + height + "px"
    }, 500, function () {
        $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
    });
}
var mytalk = setInterval('mtitem(".hot_talk","100")', 3000);
var goodsitem = null;
$(document).ready(function () {
    /* roll control */
    myScroll = setInterval(__scrollBox, speed),
    $('#newgoods,.new_goods_right,.new_goods_left').hover(function () {
        clearInterval(myScroll);
    }, function () {
        myScroll = setInterval(__scrollBox, speed);
    }),
    /* left control */
    $('.new_goods_right').click(function () {
        rollDirection = 0; __scrollBox();
    }),
    $('.new_goods_left').click(function () {
        rollDirection = 1; __scrollBox();
    }),
    mytalk,
    $(".hot_talk").hover(
        function () { clearInterval(mytalk); },
        function () {
            mytalk = setInterval('mtitem(".hot_talk","100")', 5000)
    }),
    $(".goods_hot li a").mouseover(function () {
        if (goodsitem) goodsitem.className = "";
        this.className = "sel";
        goodsitem = this;
    }),
    $($(".goods_hot li a")[0]).mouseover()
})
