
function moveElement (sElement, direction, distance) {
	var oElement = $(sElement);
	var clip = oElement.parentNode.offsetWidth;
	var strip  = oElement.offsetWidth;
	var currentDistance;
	if (!oElement.style.right) {
 		currentDistance = 0;
 	}
	else {
		currentDistance = oElement.style.right.replace(/px/i,'')*1;
	}
 	distance += currentDistance;
 	/*$('debug').innerHTML = clip + Math.abs(distance);*/
 	
	if ('next' == direction && (clip + Math.abs(distance)) < strip) { /* if offset + container's width equals element width then stop */
		oElement.tween('right', '' + distance);
	}
	else if ('prev' == direction && (distance <= 0)) {
		oElement.tween('right', '' + distance);
	}
	
}

/*
function displayImg (sImg, num) {
	if ($('mainImg').src.indexOf(sImg) > -1) {
		return false;
	}
	$('mainImg').setProperty('src', 'Images/ajax-loader.gif');
	$('mainImg').style.borderColor = '#9A9F90';
	newSrc = 'Projects/Fullsize/' + sImg;
	var currentImg = new Image();
	currentImg.onload = function () {
		fadeInOut = new Fx.Tween('mainImg');
		fadeInOut.start("opacity",0).chain(function() {
			$('mainImg').style.borderColor = '#777777';
			$('mainImg').setProperty('src', currentImg.src).fade('in');
		});
		var totalThumbs = $('nav').getElements('li').each (function (item) {
			if ('imgBox' + num == item.id) {
				item.className = 'current';
			}
			else {
				item.className = '';
			}
		});
	}
	currentImg.src = newSrc;
}
*/
//The right way, but then, explorer acts weird, of-cours.
function displayImg (sImg, num) {
	if ($('mainImg').src.indexOf(sImg) > -1) {
		return false;
	}
	fadeInOut = new Fx.Tween('mainImg');
	fadeInOut.start("opacity",0).chain(function() {
		$('mainImg').title = '';
		$('mainImg').setProperty('src', 'Images/ajax-loader.gif').fade('in');
		newSrc = sImg;

		var currentImg = new Image();
		currentImg.onload = function () {

			fadeInOut.start("opacity",0).chain(function() {
				$('mainImg').setProperty('src', currentImg.src).fade('in');
			});
			var totalThumbs = $('nav').getElements('li').each (function (item) {
				if ('imgBox' + num == item.id) {
					item.className = 'current';
				}
				else {
					item.className = '';
				}
			});
		}
		currentImg.src = newSrc;
		
	});
}

window.addEvent('domready', function() {
	if ($('prev')) {
		$('prev').onclick = function() {
			moveElement('nav','prev',73, 10);
		}
		$('next').onclick = function() {
			moveElement('nav','next',-73, -10);
		}
	}
});
