var boxResize = function(objet,container){
	fontSize=$(container).getStyle('font-size').toInt();
	lContainerEm=$(container).offsetWidth.toInt()/fontSize;
	hContainerEm=$(container).offsetHeight.toInt()/fontSize;
	rapportSource=objet.width/objet.height;
	rapportBox=lContainerEm/hContainerEm;
	if (rapportSource>rapportBox){
		lObj=lContainerEm+'em';
		hObj=lObj.toInt()/rapportSource+'em';
	}
	else{
		hObj=hContainerEm+'em';
		lObj=hObj.toInt()*rapportSource+'em';
	}
	marginLeft=Math.floor((lContainerEm-lObj.toInt())/2)+'em';
	marginTop=(hContainerEm-hObj.toInt())/2+'em';
	//alert(lObj+','+hObj+','+marginLeft+','+marginTop);
	$(container).getElement('img').setStyles({
		'width': lObj,
		'height': hObj,
		'margin-left': marginLeft,
		'margin-top': marginTop
	});
}

var redimensionneFenetre = function(){
	rContainer=$('container').offsetWidth/$('container').offsetHeight;
	rFenetre=window.getSize().x.toInt()/window.getSize().y.toInt();

	if (rContainer>rFenetre){
		fontSize=Math.floor(window.getSize().x/100);
		//alert('pour moi c est OK');
	}
	else {
		fontSize=Math.floor(window.getSize().y/57);
		//alert('pour moi c est OK');
	}
	$('container').setStyle('font-size', fontSize);
}

// Ma super classe de slideShow

var slideShow = new Class ({
	initialize : function(liste,endroit){
		this.listeImage = liste;
		this.i = 0;
		this.mesImages = [];
		this.endroit = $$('#'+endroit+' img')[0];
		this.parent = $(endroit);
		this.temps = 0;
		this.endroit.setStyle('opacity', 0);
		this.charge();
		
	},
	charge : function (){
		this.mesImages[this.i] = new Asset.image (this.listeImage[this.i], {
			onload : this.affiche.bind(this)
		});
	},
	
	
	affiche : function (){
		//alert(this.parent.get('background-image'));
		this.temp='url(\'fond.gif\')';
		$$('.photo').setStyle('background-image',this.temp);
		temps=Math.floor(Math.random()*5000)+3000; //delai aléatoire
		//temps=3000;
		this.monEndroit = this.endroit;
		this.maDiapo = this.mesImages[this.i];
		this.endroit.get('tween').start('opacity',0).chain (function(){
			this.monEndroit.src = this.maDiapo.src;
			this.monEndroit.get('tween').start('opacity',1);
		}.bind(this));
		this.i++;
		if (this.i==this.listeImage.length) {
			this.i=0;
			this.recommence.delay(this.temps,this);
		}
		else {
			this.charge.delay(temps,this);
		}
	},
	recommence : function (){
		$$('.photo').setStyle('background-image',this.temp);
		temps=Math.floor(Math.random()*4000)+2000; //delai aléatoire
		//temps=3000;
		this.monEndroit = this.endroit;
		this.maDiapo = this.mesImages[this.i];
		this.endroit.get('tween').start('opacity',0).chain (function(){
			this.monEndroit.src = this.maDiapo.src;
			this.monEndroit.get('tween').start('opacity',1);
		}.bind(this));
		this.i++;
		if (this.i==this.listeImage.length) this.i=0;
		this.recommence.delay(temps,this);
	}		
});
