var imageCounter = 0;
var running = false;
var timer;
var firstDone = false;
function runListingSlideShow(imageNumber) {
	if (imageNumber>=0) {
		imageCounter = imageNumber;
	} else {
		if (running) {
			if (imageCounter > 0 ){firstDone = true};
			imageCounter = ((imageCounter + 1) % imagesTotal);
		}
		if (imageCounter == 0 && firstDone == true ){
			onFin();
		}
	}
	if (document.all){
		document.images.ListingImage.style.filter="blendTrans(duration=2)";
		document.images.ListingImage.filters.blendTrans.Apply();
	}
	document.images.ListingImage.src = ListingImages[imageCounter].src;
	if (document.getElementById('ListingLink')){
		document.getElementById('ListingLink').href = ListingLinks[imageCounter];
	}
	if (document.images.ListingImage.alt){
		document.images.ListingImage.alt = ListingAlts[imageCounter];
	}
	if (document.getElementById('ListingDesc')){
		document.getElementById('ListingDesc').innerHTML = ListingDescs[imageCounter];
	}
	
	if (document.all){
		document.images.ListingImage.filters.blendTrans.Play();
	}
	if (running) {
		timer = setTimeout('runListingSlideShow(-1);', 6000);
	}
}
function controlSlideShow(command) {
	if (command=='pause') {
		if (running==true) {
			running=false;
			clearTimeout(timer);
		}
	}
	else if (command=='play') {
	 	if (running==false) {
			running=true;
			timer = setTimeout('runListingSlideShow(-1);', 6000);
	 	}
	}
	else if (command=='back') {
		clearTimeout(timer);
		if (imageCounter>0){
			runListingSlideShow((imageCounter - 1) % imagesTotal);
		}else{
			runListingSlideShow(imagesTotal-1);
		}
	}
	 else if (command=='forward') {
	 	clearTimeout(timer);
	 	runListingSlideShow((imageCounter + 1) % imagesTotal);
	}
}
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}