function nextFoto() {
	if(interval) {
		clearInterval(interval);
		slideShow();
	} else {
		currentFoto = (currentFoto >= qtdFotos) ? 1 : currentFoto + 1;
		showFoto();
	}
	contaHit();
}

function prevFoto() {
	if(interval) stopSlideShow();
	currentFoto = (currentFoto <= 1) ? qtdFotos : currentFoto - 1;
	showFoto();
	contaHit();
}

function slideShow() {
	slideshowbtn1.innerHTML = "Parar";
	slideshowbtn2.innerHTML = "Parar";
	slideshowbtn1.href = "javascript:stopSlideShow();";
	slideshowbtn2.href = "javascript:stopSlideShow();";
	doSlide();
	interval = window.setInterval("doSlide()", 3000);
}

function doSlide() {
	currentFoto = (currentFoto >= qtdFotos) ? 1 : currentFoto + 1;
	new ImagePreloader([path+"/"+currentFoto+".jpg"], onPreload);
	contaHit();
}

function stopSlideShow() {
	clearInterval(interval);
	interval = null;
	slideshowbtn1.innerHTML = "Slide Show";
	slideshowbtn2.innerHTML = "Slide Show";
	slideshowbtn1.href = "javascript:slideShow();";
	slideshowbtn2.href = "javascript:slideShow();";
}

function showFoto() {
	foto.innerHTML = "<div style='width:620px;height:413px;background:#000;text-align:center;'><img src='/salao/_img/loading.gif' style='margin-top:120px' /></div>";
	new ImagePreloader([path+"/"+currentFoto+".jpg"], onPreload);

}

function onPreload(img) {
	var img = img[0];
	foto.innerHTML = "<img src='"+img.src+"' />";
}


//=============================================================================
// Image Preloader
function ImagePreloader(images,callback) {
	// store the callback
	this.callback = callback;

	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;

	// record the number of images.
	this.nImages = images.length;

	// for each image, call preload()
	for ( var i = 0; i < images.length; i++ )
		this.preload(images[i]);
}

ImagePreloader.prototype.preload = function(image) {
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);

	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;

	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;

	// assign the .src property of the Image object
	oImage.src = image;
}

ImagePreloader.prototype.onComplete = function() {
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages);
}

ImagePreloader.prototype.onload = function() {
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onerror = function() {
	this.bError = true;
	this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onabort = function(){
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}
