//classic切换
(function () {
    var $ul = $('#classic .c-main ul'),
        $li = $ul.children(),
        $btn = $('#classic .btn div'),
        width = $ul.children().eq(0).width(),
        length = $li.length,
        midIndex = Math.floor(length/2),
        clickTime = 0,
        sumWidth = 0,
        timer;
    changeClassName();
    setTimeout(function () {
        sumWidth = 0;
        $li.each(function () {
            sumWidth += $(this).width();
        });
        $ul.css('marginLeft' , -sumWidth/2+'px').css('opacity' , 1);
    },300);
    $(window).resize(function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            width = $ul.children().eq(0).width();
            sumWidth = 0;
            $li.each(function () {
                sumWidth += $(this).width();
            });
            $ul.animate({'marginLeft' : -sumWidth/2+'px'},300);
        },300);
    });
    $btn.click(function () {
        if (new Date() - clickTime > 350){
            if ($(this).index()){
                midIndex ++;
                midIndex %= length;
                $ul.stop().animate({
                    'marginLeft' : -sumWidth/2 - width + 'px'
                },300,function () {
                    $(this).css('marginLeft' , -sumWidth/2+'px').append($(this).children().first());
                });
            }else{
                midIndex --;
                if(midIndex<0)midIndex=length-1;
                $ul.stop().animate({
                    'marginLeft' : -sumWidth/2 + width + 'px'
                },300,function () {
                    $(this).css('marginLeft' , -sumWidth/2+'px').prepend($(this).children().last());
                });
            }
            changeClassName();
            clickTime = new Date();
        }
    });
    function changeClassName() {
        var a = midIndex,
            b = midIndex + 1,
            c = midIndex - 1;
        if(b>=length)b=0;
        if(c<0)c=length-1;
        $li.removeClass('mid slide');
        $li.eq(a).addClass('mid');
        $li.eq(b).addClass('slide');
        $li.eq(c).addClass('slide');
    }

 
})();

