﻿var HOT = { built: [1, 0, 0], current: 0, step: 488, done: true, a: 'a_', div: 'div_con', ul: 'hotTop' }
var nextIndex = 1;
var Turn = {}
Turn.pre = function(obj) {
    if (obj.current == 0) {
        nextIndex = 1;
        return;
    } else {
        nextIndex = obj.current;
        Turn.go(obj, obj.current - 1);
    }
}
Turn.next = function(obj) {
    if (obj.current == 2) {
        nextIndex = 0;
        return;
    } else {
        nextIndex = obj.current + 2;
        Turn.go(obj, obj.current + 1);
    }
}
Turn.go = function(obj, index) {
    nextIndex = index;
    if (obj.current == index || !obj.done) { return; }
    for (var i = 0; i < 3; i++) {
        if (obj.built[i] == 0) {
            obj.built[i] = 1;
        }
    }
    obj.done = false;
    var span = -index + obj.current;
    XY.scrollCross.scroll($(obj.div), obj.step, span, parseInt($(obj.div).style.marginLeft) || 0, cb, 10);
    function cb() {
        obj.current = index;
        obj.done = true;
        for (var i = 0; i < 3; i++) {
            $(obj.a + i).className = '';
        }
        $(obj.a + index).className = 'now';
    }
}
var XY = {};

XY.scrollCross = { interval: 0, count: 0, duration: 0, step: 0, srcObj: null, callback: null };
XY.scrollCross.doit = function(obj, b, c, d) {
    var s = XY.scrollCross;
    obj.style.marginLeft = cpu(s.count, b, c, d) + 'px';
    s.count++;
    if (s.count == d) {
        clearInterval(s.interval);
        s.count = 0;
        obj.style.marginLeft = b + c + 'px';
        s.callback();
    }
    function cpu(t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; };
}
XY.scrollCross.scroll = function(obj, step, span, beign, callback, duration) {
    var s = XY.scrollCross;
    s.duration = duration;
    s.callback = callback;
    s.interval = setInterval(function() { s.doit(obj, beign, step * span, duration) }, 10);
}

var auto = setInterval(function() {
    if (nextIndex >= 3) nextIndex = 0;
    if (nextIndex <= 0) nextIndex = 0;
    Turn.go(HOT, nextIndex);
    nextIndex++;
}, 6000);

auto = null;
