function DiaporamaViewer(diaporama){

	this.diaporama = diaporama;
	this.currentDiapoShown		= 0;

	this.img1CurrentOpacity 	= 0;
	this.img2CurrentOpacity 	= 100;

	this.nextImageTimeout 		= 2000;

	this.opacityAnimationTimeOut 	= 25;
	this.opacityAnimationStep 	= 5;
	this.currentAnimationStep	= 0;

	this.opacityAnimationLog  	= "";

	
	this.showFirstDiapo 		= DiaporamaViewer_showFirstDiapo;

	//obtenir les div contenant les images;
	this.getFirstImageDiv 		= DiaporamaViewer_getFirstImageDiv;
	this.getSecondImageDiv 		= DiaporamaViewer_getSecondImageDiv;
	//obtenir les images;

	this.getFirstImage 		= DiaporamaViewer_getFirstImage;
	this.getSecondImage 		= DiaporamaViewer_getSecondImage;

	//obtenir le div du titre
	this. getTitleDiv 		= DiaporamaViewer_getTitleDiv
	this.getPriceDiv			= DiaporamaViewer_getPriceDiv;

	this.getViewer 			= DiaporamaViewer_getViewer;

	this.animateOpacity 		= DiaporamaViewer_AnimateOpacity;
	this.endOpacityAnimation 	= DiaporamaViewer_endOpacityAnimation;
	this.setOpacity 		= DiaporamaViewer_setOpacity;
	this.stopAnimation		= DiaporamaViewer_stopAnimation;

	this.showDiapo 			= DiaporamaViewer_showDiapo;
	this.showNextDiapo		= DiaporamaViewer_showNextDiapo;

	this.getDiaporamaTitleDiv	= DiaporamaViewer_getDiaporamaTitleDiv;
	
}

function DiaporamaViewer_setOpacity(imageIndex){
	opacity = (imageIndex == 1) ? this.img1CurrentOpacity : this.img2CurrentOpacity ;
	image = (imageIndex == 1) ? this. getFirstImage() : this.getSecondImage();
	isIE = (document.all && !window.opera);

	val = (isIE) ? 'alpha(opacity=' + opacity + ');' : opacity / 100;
	
	

	if(isIE){ 
		image.style.filter = val;
	} 
	else{ 
		image.style.opacity = val;
	}
}


function DiaporamaViewer_showNextDiapo(){
	if(this.currentDiapoShown == this.diaporama.diapos.length -1){
		this.currentDiapoShown = 0;
	}else{
		++this.currentDiapoShown;
	}
	this.showDiapo(this.currentDiapoShown);
}

function DiaporamaViewer_showDiapo(diapoIndex){
	
	this.animateOpacity();
	this.getFirstImage().src 				= this.diaporama.getDiapo(diapoIndex).src;
	this.getTitleDiv().innerHTML 				= this.diaporama.getDiapo(diapoIndex).name; 
	//2010-11-21 
	this.getPriceDiv().innerHTML				= this.diaporama.getDiapo(diapoIndex).price; 
	document.forms['DiaporamaViewerForm'].action 		= this.diaporama.getDiapo(diapoIndex).url;

}

function DiaporamaViewer_stopAnimation(){
	clearTimeout(toBeforeNextImage);
	this.endOpacityAnimation();
}

function DiaporamaViewer_endOpacityAnimation(){

	clearTimeout(opacityAnimation);
	this.getSecondImage().src = this.getFirstImage().src;

	this.img1CurrentOpacity = 0;
	this.img2CurrentOpacity = 100;

	
}

function DiaporamaViewer_AnimateOpacity(){

	this.img1CurrentOpacity +=  this.opacityAnimationStep;
	this.img2CurrentOpacity -=  this.opacityAnimationStep;
	++this.currentAnimationStep;

	this.opacityAnimationLog += 'image 1 ' + this.img1CurrentOpacity + '\n';
	this.opacityAnimationLog += 'image 2 ' + this.img2CurrentOpacity + '\n\n';

	

	if(this. img1CurrentOpacity < 100){
		opacityAnimation = setTimeout("diapoRamaViewer.animateOpacity()", this.opacityAnimationTimeOut);
	}else{
		
		

		
		this.endOpacityAnimation();


		//alert(this.opacityAnimationLog);
		this.opacityAnimationLog  = "";

		toBeforeNextImage = setTimeout("showNextImage()",this.nextImageTimeout);
		
	}

	this.setOpacity(1);
	this.setOpacity(2);

}

function DiaporamaViewer_showFirstDiapo(){
	this.getDiaporamaTitleDiv().innerHTML = this.diaporama.title;
	this.showDiapo(0);
}


function DiaporamaViewer_getDiaporamaTitleDiv(){
	return document.getElementById("diaporama_viewer_diaporama_title");
}



function DiaporamaViewer_getViewer(){
	return document.getElementById('diaporama_viewer');
}

function DiaporamaViewer_getFirstImageDiv(){
	return document.getElementById('diaporama_viewer_imagediv1');
}
function DiaporamaViewer_getSecondImageDiv(){
	return document.getElementById('diaporama_viewer_imagediv2');
}
function DiaporamaViewer_getFirstImage(){
	return document.images['diaporama_viewer_image1'];
}
function DiaporamaViewer_getSecondImage(){
	return document.images['diaporama_viewer_image2'];
}
function DiaporamaViewer_getTitleDiv(){
	return document.getElementById('diaporama_viewer_title');
}

//2010-11-21 ajout d'une fonction pour obtenir l'element HTML contenant le prix
function DiaporamaViewer_getPriceDiv(){
	return document.getElementById('diaporama_viewer_price');
}



