
var can_autoMove = true;

var autoAutostart = null;
var frameTimerID = null;
var autoFrameTimerID = null;
var auto_course = 'next';

function movePhotoFrame(course, step, id)
{
	try {
	    var step = (step ? step : 5);
	    var elem = document.getElementById(id);
	    var start = elem.scrollLeft;

	    if (course == 'next') {
	        elem.scrollLeft = start + step;
	    }

	    if (course == 'prev') {
	        elem.scrollLeft = start - step;
	    }
	} catch (e) {}
}

function startMovephotoFrame(course, id, speed)
{
    if (autoAutostart) {
        clearInterval(autoAutostart)
    }
    autoAutostart = null;

    autoStopMove();
    stopMovePhotoFrame();
    auto_course = course;
    frameTimerID = setInterval(function() {
        movePhotoFrame(course, speed, id);
    }, 30);
}

function stopMovePhotoFrame()
{
    if (frameTimerID) {
        clearInterval(frameTimerID);
    }
    frameTimerID = null;
}

function moveNext(id, course)
{
    course = (course ? true : false);
    if (course) {
        startMovephotoFrame('next', id);
    } else {
        startMovephotoFrame('prev', id);
    }
}

function moveStop()
{
    stopMovePhotoFrame();
    autoAutostart = setTimeout(autoStartMove, 5000);
}


function autoStartMove ()
{
    if (can_autoMove) {
        autoStopMove();
        frameTimerID = setInterval(function() {
            movePhotoFrame(auto_course, 1);
        }, 40);
    }
}

function autoStopMove()
{
    if (autoFrameTimerID) {
        clearInterval(autoFrameTimerID);
    }
    autoFrameTimerID = null;
}
