function galerie(){
	
	this.timer=0;
	
	this.x=0;
	this.y=0;
	this.l=10;
	this.h=10;
	this.dl=20;
	this.dh=100;
	
	this.ygal_buffer=0;
	this.bufferalpha=0;
	
	this.image = new Array();
	this.longueur = 0;
	this.actuelle = 0;

	this.ygal_cont=0;
	this.contalpha=0;
	
	idgal=new Array();
	idgal[0]=this;
	
	this.bgnd=0;
	this.bgndl=0;
	this.bgndh=0;
	this.bgndalpha=0;
		
	this.mode=''; // mode du script
	this.rmode=0; // mode du redenssionneur par defaut arrèté
		
	this.screenl=0;
	this.screenh=0;
	
		
//______________________________________________________________________	init		
	this.init=function(){
	
		this.getScreen();
				
		s='<div id="ygal_screen" style="width:800px;height:600px;background:#000000;position:fixed;top:0px;left:0px;display:none;opacity:0.5;z-index:40000;">'+
		
		'</div><div id="ygal_cont" style="z-index:40001;width:640px;height:480px;background:#eeeeee;position:fixed;top:0px;left:0px;padding:10px;display:none;opacity:0;">'+
			'<div style="margin-bottom:10px;text-align:center;font-family:arial;">'+
			'<span style="cursor:pointer;padding:5px;padding-right:20px;background:#999999;color:#ffffff;margin-right:1px;" onClick="galerie.suivante()"><</span>'+
			'<span style="cursor:pointer;padding:5px;background:#999999;color:#ffffff;margin-right:1px;;" onClick="galerie.fermer()">X</span>'+
			'<span style="cursor:pointer;padding:5px;padding-left:20px;background:#999999;color:#ffffff;" onClick="galerie.precedente()">></span>'+
			'<div style="clear:both;"></div>'+
			'</div>'+
		
		'<img style="display:none;margin:0px auto;border:solid 2px #000000;" id="ygal_buffer" onLoad="galerie.bufferok()">'+
		'</div>'
		
		;
	
		document.getElementById('y_gal').innerHTML=s;


		
		this.ygal_screen=document.getElementById('ygal_screen').style;
				
		this.ygal_cont=document.getElementById('ygal_cont').style;
		
		this.ygal_buffer=document.getElementById('ygal_buffer').style;

		this.redim_bgnd();
		//this.moteurOn();
	}

//______________________________________________________________________	Chargement galerie

	this.charge=function(s){
		
		this.image=s.split('$');
		this.longueur=this.image.length;
		this.longueur-=1;
		this.actuelle=0;
		this.dh=20;
		this.dl=100;
		this.h=20;
		this.l=100;
		this.rmode=1;
		this.mode='open';
		this.moteurOn();
	}

//______________________________________________________________________	Le buffer est mis a jour.
	
	this.bufferok = function(){
		var mode = this.mode;
			switch(mode){
				case('open3'):
					this.mode='open4';
				break;
			}
	}
	
	
//______________________________________________________________________	Mettre à jour les dimensions de l'écran.

	this.getScreen=function()
	{
		this.screenl=document.body.clientWidth;
		this.screenh=document.body.clientHeight;
	}
	
//______________________________________________________________________	status
	this.status=function(){
		s="Resolution : "+screenl+"*"+screenh+" pixels.";
		alert(s);
	}
	
//______________________________________________________________________	redim background

	this.redim_bgnd=function(){
		screenl=document.body.clientWidth;
		screenh=document.body.clientHeight;
		this.ygal_screen.width='100%';
		this.ygal_screen.height='100%';
	}
	
//______________________________________________________________________	Refresh de la galerie

	this.refresh=function(){

		with(this.ygal_cont){	
			top=this.y+'px';
			left=this.x+'px';
			width=this.l+'px';
			height=this.h+'px';
		}	

	}

//______________________________________________________________________	Recentre Galerie

	this.recentre_galerie=function(){
		this.getScreen();
		this.x=(this.screenl/2)-(this.l/2);
		this.y=10;
		this.refresh();
	}
	
//__________________________________________________________________________ Moteur
	
	this.moteur=function(){
		
		rmode=this.rmode;
		
		if(rmode==1){	// si recadreur en marche => stop le mode générale
			
					var dx=(this.dl-this.l)/3;
					var dy=(this.dh-this.h)/3;
					
					this.l+=dx;
					this.h+=dy;
					
						if( this.dl == Math.round(this.l) && this.dh==Math.round(this.h) ){
							this.rmode=0; // coupure auto en fin 
						}
					
					this.recentre_galerie();
		}
		else{
		
		
			mode=this.mode;
			
			switch(mode){
								
				//-------------------------------------------------------------------- Ouverture galerie
				
				case('open'):
					this.bgndalpha=0;
					this.contalpha=0;
					this.mode='open1';
					
					this.ygal_screen.opacity="0";
					this.ygal_screen.filter='alpha(opacity:0)';
					
					this.ygal_cont.opacity="0";
					this.ygal_cont.filter='alpha(opacity:0)';
					
					
					
					this.ygal_screen.display="block";

				break;
				
				case('open1'):
					this.bgndalpha+=5;
						if(this.bgndalpha>=80){
						this.mode='open11';
						this.ygal_cont.display="block";
						
						}
						
					var v=this.bgndalpha;
					this.ygal_screen.opacity=''+v/100;	
					this.ygal_screen.filter='alpha(opacity:'+v+')';
				break;

				case('open11'):
					this.contalpha+=5;
						if(this.contalpha>=100){
						this.mode='open2';
						}
						
					var v=this.contalpha;
					this.ygal_cont.opacity=''+v/100;
					this.ygal_cont.filter='alpha(opacity:'+v+')';
				break;


				case('open2'):
				
					this.bufferalpha-=20;
					
						if(this.bufferalpha<0){
							this.bufferalpha=0;
							this.mode='open22';
						}
				
					this.ygal_buffer.opacity=''+this.bufferalpha/100;
					this.ygal_buffer.filter='alpha(opacity:'+this.bufferalpha+')';
					
				break;
				
				case('open22'):
					this.mode='open3';
					document.getElementById('ygal_buffer').src='photos/'+this.image[this.actuelle]+"big.jpg";
				break;
				
				// mode open 4 declenché par evenement chargement buffer function bufferok()
				
				
				
				case('open4'):
				
					this.ygal_buffer.display="block";
					this.ygal_buffer.opacity=0;
					
					var l = document.getElementById('ygal_buffer').width;
					var h = document.getElementById('ygal_buffer').height;
															
					this.dl=l+30;
					this.dh=h+30;
					
					this.mode='open5';
					this.rmode=1;
				
				break;
				
				case('open5'):
				
					with(this){
						bufferalpha+=20;
						
							if(bufferalpha==100)
							mode='open6';
						ygal_buffer.opacity=bufferalpha/100;
						ygal_buffer.filter='alpha(opacity:'+bufferalpha+')';
					}
				
				break;
				
				case('fermer'):
					this.bufferalpha-=10;
						if(this.bufferalpha <0){
							this.mode='fermer2';
							this.bufferalpha=0;
						}
					this.ygal_buffer.opacity=this.bufferalpha/100;	
					this.ygal_buffer.filter='alpha(opacity:'+this.bufferalpha+')';
				break;
				
				case('fermer2'):
					this.dl=100;
					this.dh=20;
					this.mode='fermer3';
					this.rmode=1;
				break;
				
				case('fermer3'):
					this.ygal_cont.opacity=0;
					this.ygal_cont.filter='alpha(opacity:0)';
					this.ygal_cont.display='none';
					this.mode='fermer4';
				break;
				
				case('fermer4'):
					this.bgndalpha-=10;
						if(this.bgndalpha<=0){
							this.mode='fermer5';
							this.bgndalpha=0;
						}
					this.ygal_screen.opacity=this.bgndalpha/100;	
					this.ygal_screen.filter='alpha(opacity:'+this.bgndalpha+')';	
					
				break;
				
				case('fermer5'):
					this.ygal_screen.display='none';
					this.moteurOff();
				break;
			}
		}
	}	
	
//__________________________________________________________________________ image suivante

	this.suivante=function(){

		this.actuelle-=1;
			if(this.actuelle==-1) this.actuelle=this.longueur-1;

		this.mode='open2';	
	}
	
//__________________________________________________________________________ image precedente

	this.precedente=function(){
	
		this.actuelle+=1;
			if(this.actuelle==this.longueur) this.actuelle=0;

		this.mode='open2';
	}	
	
//__________________________________________________________________________ bouton fermer

	this.fermer=function(){
		this.mode='fermer';
	}	
	

//__________________________________________________________________________ Moteur	 ON

	this.moteurOn=function(){
		this.timer=window.setInterval('idgal[0].moteur()',33);
	}

//__________________________________________________________________________ Moteur	OFF

	
	this.moteurOff=function(){
		window.clearInterval(this.timer);
		
	}

}
