﻿
var intevalId = null;
var scroll = true;
var SCROLL_STEP = 1;
var TIME_INTERVAL = 10;
var totalPictureCount = 0; ;
var imageCountInView = 5;
var imageWidth = 111;
var isScrolling = false;
var MAX_LEFT = 0;

function scrollPanel() {
    var panelElement = document.getElementById("pictureViewerSlidePictureContainer");
    if (panelElement != null) {

        if (totalPictureCount == 0 || MAX_LEFT == 0) {
            totalPictureCount = (parseInt(panelElement.style.width) / imageWidth) - 1;
            MAX_LEFT = -1 * ((totalPictureCount - imageCountInView) * imageWidth + 10);
        }

        var elementLeft = parseFloat(panelElement.offsetLeft) + SCROLL_STEP;

        if (elementLeft > MAX_LEFT && elementLeft < 0)//right most picture is in view
        {
            panelElement.style.left = elementLeft + "px";
        }
        else 
        {
            //reverse direction;
            SCROLL_STEP = -1 * SCROLL_STEP;
        }
    }
}

function startScroll(direction) 
{
    if (direction == "left") {
        if (SCROLL_STEP > 0) {
            SCROLL_STEP = -1 * SCROLL_STEP;
        }
    }
    else if (direction == "right") {
        if (SCROLL_STEP < 0) {
            SCROLL_STEP = -1 * SCROLL_STEP;
        }
    }
    //stop before starting
    stopScroll();
    intevalId = window.setInterval(scrollPanel, TIME_INTERVAL);
    isScrolling = true;
}

function stopScroll()
{
    if (intevalId != null) 
    {
        window.clearInterval(intevalId);
        isScrolling = false;
    }
}

function pauseScroll() 
{
    stopScroll();
    //isScrolling = true;
}

function resumeScroll() 
{
    if (SCROLL_STEP > 0)//was scrolling in right
    {
        startScroll('right');
    }
    else
    { startScroll('left'); }
}   
