var imageSize = 0;	
var timeout;

function moveright() {

	var images = document.getElementById('images');
	var left = images.style.left;
	left = left.replace("px", "");

	if (left != imageSize) {
		left = parseInt(left) - 1;
		left = left + 'px';
		images.style.left = left;
		timeout = setTimeout('moveright()', 1);
	}
}


function moveleft() {

	var images = document.getElementById('images');
	var left = images.style.left;
	left = left.replace("px", "");

	if (left != '0') {		
		left = parseInt(left) + 1;
		left = left + 'px';
		images.style.left = left;

		timeout = setTimeout('moveleft()', 1);
	}
}

function cancelmove() {

	clearTimeout(timeout);
}

function getSize() {
	var count = document.getElementById('count');
	

	for (var i=1; i<= count.value; i++) {
		var image = document.getElementById('image_' + i);
		currentImage = image.width;
		currentImage = currentImage + 5;
		imageSize = parseInt(imageSize) - parseInt(currentImage);	
	}

	imageSize = imageSize + 400;
}

function displayPicture(id) {
	var image = document.getElementById(id);
	var code = image.name;
	var caption = image.title;
	
	var container = document.getElementById('imageContainer');
	while (container.firstChild){
		container.removeChild(container.firstChild);
	}

	var captionContainer = document.getElementById('imageCaption');
	while (captionContainer.firstChild){
		captionContainer.removeChild(captionContainer.firstChild);
	}
	captionContainer.appendChild(document.createTextNode(caption));


	var image = document.createElement('img');
	image.src = '/images/photos/testing/' + code;
	image.align = 'center';
	image.id = 'image_current';
	image.onload = function() { document.getElementById('imageContainer').style.width = this.width + 'px'; document.getElementById('imageContainer').style.height = this.height + 'px'; };
	container.appendChild(image);



}
