﻿var leftscrolling = false;
var rightscrolling = false;
var alltheimagesWidth;
var SCROLL_WIDTH = 39;
var SLIDE_RESPONSE = 20;

scrolldirection = 'left';

function InitalizeScroll(direction) {

    var alltheimages = document.getElementById('alltheimages');
    alltheimagesWidth = alltheimages.offsetWidth;
    
    if (direction == 'left') {
        leftscrolling = true;
        scrolldirection = 'left';
        startScrolling();
    }
    else if (direction == 'right') {
        rightscrolling = true;
        scrolldirection = 'right';
        startScrolling();
    }
}

function startScrolling() {
    var alltheimages = document.getElementById('alltheimages');
    var currentPosition = parseInt(alltheimages.style.left);
              
    if (scrolldirection == 'left') {
        if (!leftscrolling) {
            return;
        }
        if (currentPosition != 0) {
            alltheimages.style.left = currentPosition + SCROLL_WIDTH + "px";
            setTimeout(startScrolling, SLIDE_RESPONSE);
        }
    }
  else if (scrolldirection == 'right') {
        if (!rightscrolling) {
            return;
        }
        if (currentPosition > -(alltheimagesWidth-450)) {
            alltheimages.style.left = currentPosition - SCROLL_WIDTH + "px";
            setTimeout(startScrolling, SLIDE_RESPONSE);
        }
    }
    return false;
}

function stopScrolling() {
    leftscrolling = false;
    rightscrolling = false;
}

function showimage(img) {
    var imagetoshow = document.getElementById('imagetoshow');
    imagetoshow.src = img.src.replace('thumbs', 'large');
    imagetoshow.style.display = "block";
}
