/*
===============================
DotControl copyright 2010
===============================
*/

function StartSlidebox() {
    var autoPlayTime = 7000;
    SetSelected();
    autoPlayTimer = setInterval(autoPlay, autoPlayTime);
    thumbsUpdateTimer = setInterval(SetSelected, "1000");
    function autoPlay() {
        Slidebox('next');
    }
    var yPosition = $('#slidebox').height() / 2 - $('#slidebox .next').height() / 2;
    $('#slidebox .next').css('top', yPosition);
    $('#slidebox .previous').css('top', yPosition);
};

//slide page to id
function Slidebox(slideTo, autoPlay) {
    var animSpeed = 1000; //animation speed
    var easeType = 'easeInOutExpo'; //easing type
    var sliderWidth = $('#slidebox').width();
    var leftPosition = $('#slidebox .container').css("left").replace("px", "");
    $("#slidebox .content").each(function (i) {
        totalContent = i * sliderWidth;
        $('#slidebox .container').css("width", totalContent + sliderWidth);
    });
    if (!$("#slidebox .container").is(":animated")) {
        if (slideTo == 'next') { //next
            if (autoPlay == 'stop') {
                clearInterval(autoPlayTimer);
            }
            if (leftPosition == -totalContent) {
                $('#slidebox .container').animate({ left: 0 }, 3000, easeType); //reset
            } else {
                $('#slidebox .container').animate({ left: '-=' + sliderWidth }, animSpeed, easeType); //next
            }
        } else if (slideTo == 'previous') { //previous
            if (autoPlay == 'stop') {
                clearInterval(autoPlayTimer);
            }
            if (leftPosition == '0') {
                $('#slidebox .container').animate({ left: '-' + totalContent }, animSpeed, easeType); //reset
            } else {
                $('#slidebox .container').animate({ left: '+=' + sliderWidth }, animSpeed, easeType); //previous
            }
        } else {
            var slide2 = (slideTo - 1) * sliderWidth;
            if (leftPosition != -slide2) {
                clearInterval(autoPlayTimer);
                $('#slidebox .container').animate({ left: -slide2 }, animSpeed, easeType); //go to number
            }
        }
    }
}

function SetSelected() {
    var leftPosition = $('#slidebox .container').css("left").replace("px", "");
    var sliderWidth = $('#slidebox').width();
    $('.Current').removeClass('Current');
    var thumbNumber = Math.round(-leftPosition / sliderWidth) + 1;
    $('.thumb' + thumbNumber).addClass('Current');
}



