teaser_should_move = true;
teaser_current_pos = -1;

function teaser_build_control() {
    inner =document.getElementById('teaser-inner')
    control = document.getElementById('teaser-control');
    num = inner.getElementsByTagName('div').length
    for(i=0; i<num; i++) {
        child = document.createElement('button');
        child.innerHTML = i+1;
        child.setAttribute('onclick', 'teaser_move_to('+i+')')
        control.appendChild(child)
    }
}

function teaser_move_to(to) {
    pos_to = to*960;
    controls = document.getElementById('teaser-control').getElementsByTagName('button')
    for(i=0;i<controls.length;i++) {
        controls[i].setAttribute('class', '')
    }
    controls[to].setAttribute('class', 'active')
    teaser_current_pos = to;
    $('#teaser-inner').animate({
        right: pos_to
    }, 1000, 'easeOutBack', function() {});
}

function teaser_move_auto() {
    if(teaser_should_move) {
        num = document.getElementById('teaser-inner').getElementsByTagName('div').length
        if(teaser_current_pos >= num-1) teaser_current_pos = -1;
        teaser_current_pos++;
        teaser_move_to(teaser_current_pos)
    }
    setTimeout('teaser_move_auto()', 10000);
}

$(document).ready(function() {
    if(document.getElementById('teaser')) {
        $('#teaser').mouseover(function() {
            teaser_should_move = false;
        }).mouseout(function() {
            teaser_should_move = true;
        });

        teaser_build_control();
        teaser_move_auto();
        document.getElementById('teaser').style.backgroundImage = 'None';
    }
});
