/***********************************************
* Photo Carrousel
* version 1.0
*
* Author: Michiel Steendam
***********************************************/

var SCROLL_SPEED = 5;

var scrolling = 0;	// positive number means scrolling right, negative number means scrolling left
var photoListDiv = null;
var photoCarrouselDiv = null;

function scroll(numberOfPixels) {
	if (scrolling == 0) {
		photoListDiv = document.getElementById('photoList');
		photoCarrouselDiv = document.getElementById('photoCarrousel');

		//alert("photoList width = " + photoListDiv.offsetWidth + " (moet 830 zijn)");
		
		if (photoListDiv) {
			if (parseInt(photoListDiv.style.left) - numberOfPixels > 0) {
				numberOfPixels = parseInt(photoListDiv.style.left);
			}
			else if (parseInt(photoListDiv.offsetWidth) - parseInt(photoCarrouselDiv.offsetWidth) - numberOfPixels <= Math.abs(parseInt(photoListDiv.style.left))) {
				numberOfPixels = parseInt(photoListDiv.offsetWidth) - parseInt(photoCarrouselDiv.offsetWidth) + parseInt(photoListDiv.style.left);
			}

			scrolling += numberOfPixels;
			// alert("scrolling: " + numberOfPixels);
			doScroll();
		} else {
			alert('No div with id photoList found!');
		}
	}
}

function doScroll() {
	var scrollStep = 0;

	if (scrolling > 0) {
		if (scrolling - SCROLL_SPEED < 0) {
			scrollStep = scrolling;
			scrolling = 0;
		} else {
			scrolling -= SCROLL_SPEED;
			scrollStep = SCROLL_SPEED;
		}
		photoListDiv.style.left = (parseInt(photoListDiv.style.left) - scrollStep) + "px";
	}
	else if (scrolling < 0) {
		if (scrolling + SCROLL_SPEED > 0) {
			scrollStep = -scrolling;
			scrolling = 0;
		} else {
			scrolling += SCROLL_SPEED;
			scrollStep = SCROLL_SPEED;
		}
		photoListDiv.style.left = (parseInt(photoListDiv.style.left) + scrollStep) + "px";
	}

	//alert("scrolling = " + scrolling);
	if (scrolling != 0) {
		//alert("scrolling: " + scrolling);
		window.setTimeout("doScroll()", 10);
	}
}

function stopScroll() {
	scrolling = 0;
}
