/**
 * @author Peter Riet
 */
function cFotoalbum() {
	var _self = this;
	this.blnDiashowGestart = false;
	this.divPhoto;
	this.imgAfbeelding;
	this.preload_images = new Array();
	this.intCurrentPhotoIndex = 0;
	this.intPrevPhotoIndex = 0;
	this.strPhotoBaseURL;
	this.arrPhotos = new Array();
	this.arrFotoOmschrijvingen = new Array();
	this.divOmschrijving;

	this.clickTegel = function(strHref) {
		window.location.href = strHref;	
	}
	
	this.toonOmschrijving = function(event, strOmschrijvingID) {
		var div = document.getElementById("divOmschrijving" + strOmschrijvingID);
		showTooltip(event, div.innerHTML);
	}
	
	this.startStopDiashow = function() {
		if (!_self.blnDiashowGestart) {
			// Verander de knop
			document.getElementById("imgFotoalbumDiashowStart").style.display = "none";
			document.getElementById("imgFotoalbumDiashowStop").style.display = "inline";
			
			_self.blnDiashowGestart = true;
			
			// Start de diashow
			_self.diaShowVolgende();
		}
		else {
			// Verander de knop
			document.getElementById("imgFotoalbumDiashowStart").style.display = "inline";
			document.getElementById("imgFotoalbumDiashowStop").style.display = "none";
			
			_self.blnDiashowGestart = false;
		}
	}	
	
	this.diaShowVolgende = function() {
		if (!_self.blnDiashowGestart) return false;
		
		_self.toonVolgendeFoto();
	
		if (_self.intCurrentPhotoIndex < _self.arrPhotos.length - 1)
			setTimeout("objFotoalbum.diaShowVolgende()", 2000);
		else
			_self.startStopDiashow();
	}

	this.toonFoto = function(intPhotoIndex, strSrc) {
		if (_self.intCurrentPhotoIndex == intPhotoIndex) return;
		
		// Onthou vorige index
		_self.intPrevPhotoIndex = _self.intCurrentPhotoIndex;
		
		_self.intCurrentPhotoIndex = intPhotoIndex;
		
		objPhotoScroll.scrollToPhotoIndex(intPhotoIndex);
		//window.scrollTo(0, 1000000);
		
		var blnFade = true;//false;
		
		if (!blnFade) {
			if (!_self.imgAfbeelding) _self.imgAfbeelding = document.getElementById("imgFotoalbumFoto")
			
			_self.imgAfbeelding.src = _self.strPhotoBaseURL + strSrc;
		}
		else {
			if (!_self.divPhoto) _self.divPhoto = document.getElementById("divFotoalbumFoto")
			
			var i = _self.preload_images.length;
			// preload_images[i] = new Image();
			_self.preload_images[i] = document.createElement("img");
			_self.preload_images[i].src = _self.strPhotoBaseURL + strSrc + "?" + Math.random();
			_self.preload_images[i].id = "preload_image_" + i;
			_self.preload_images[i].onload = _self.insert_image;			
			
			objImageAnimation.setOpacity(_self.preload_images[i], 0);
		
			if (i > 0) {
				objImageAnimation.fadeOut("preload_image_" + (i - 1), 100);
			}
		
			_self.divPhoto.appendChild(_self.preload_images[i]);
		}
	}
	
	this.insert_image = function() {
		var img = document.getElementById("preload_image_" + (_self.preload_images.length - 1));
		
		// Centreer afbeelding
		var objPageSize = getPageSize();
		var intLeft = (objPageSize.pageWidth / 2) - (img.width / 2);
		img.style.left = intLeft + "px";
		_self.divPhoto.style.height = parseInt(img.height, 10) + 20 + "px";
	
		objImageAnimation.fadeIn("preload_image_" + (_self.preload_images.length - 1), 0);
	}

	this.toonVorigeFoto = function() {
		if (_self.intCurrentPhotoIndex == 0) return;
		
		var intPhotoIndex = _self.intCurrentPhotoIndex - 1;
		
		_self.toonFoto(intPhotoIndex, _self.arrPhotos[intPhotoIndex]);
		_self.updateFotoOmschrijving();
		objPhotoScroll.scrollPhotoLeft();
	}
	
	this.toonVolgendeFoto = function() {
		if (_self.intCurrentPhotoIndex == _self.arrPhotos.length - 1) return;
		
		var intPhotoIndex = _self.intCurrentPhotoIndex + 1;
			
		_self.toonFoto(intPhotoIndex, _self.arrPhotos[intPhotoIndex]);
		_self.updateFotoOmschrijving();
		objPhotoScroll.scrollPhotoRight();	
	}

	
	this.updateFotoOmschrijving = function() {
		if (!_self.divOmschrijving) _self.divOmschrijving = document.getElementById("divFotoalbumFotoOmschrijving");
		
		var strOmschrijving = (_self.arrFotoOmschrijvingen[_self.intCurrentPhotoIndex].length > 0) ? _self.arrFotoOmschrijvingen[_self.intCurrentPhotoIndex] : "&nbsp;";
		_self.divOmschrijving.innerHTML = strOmschrijving;
	}
}

var objFotoalbum = new cFotoalbum();