/**
 * @author guy
 */

		
		/* constructor */	
		function carousel( cadreId,  bannerId, effectDuration ) {
			// taux de recouvrement : l'image se déplacera de n% de la taille du cadre
			var fenDepl = 0.9;
			
			this.cadreId = cadreId;
			this.cadreLarg = YAHOO.util.Dom.get(cadreId).clientWidth; 
			
			this.bannerId = bannerId;
			this.bannerLarg = getBannerWidth(bannerId);
			
			/* centrer */
			var depl = Math.round( (this.cadreLarg - this.bannerLarg ) / 2 );
			var mvt = new YAHOO.util.Motion(this.bannerId, { points: { by: [depl,0] } }, 0, YAHOO.util.Easing.easeOut); 
			mvt.animate();
			
			this.duration=effectDuration;
			this.pos = depl;
			this.depl = Math.abs(this.cadreLarg*fenDepl);
			
			this.mvt = mvt;
			this.mvt.duration = effectDuration;
			
		}


		/* methods */
		carousel.prototype = {
			bouge: function ( sens ) {
					 if (this.mvt.currentFrame == this.mvt.totalFrames) {
						var pos=this.pos, depl= sens*this.depl;
						
						// ca depasse à gauche
						if ( (pos+depl) > 0 ) depl=-pos;
						
						// ca depasse à droite
						if ( (pos+depl) < (this.cadreLarg-this.bannerLarg) ) depl=this.cadreLarg-pos-this.bannerLarg; 
							
						this.pos = pos + depl;

						this.mvt.attributes.points = { by: [depl,0] };
						this.mvt.duration = this.duration*Math.abs(depl)/this.depl;
						this.mvt.animate();	
						
						//aptana.log(this.mvt.attributes.duration);
						}
					   },
						
			dumpCarousel: function () {
				alert ("cadreId="+this.cadreId+" cadreLarg="+this.cadreLarg+" bannerId="+this.bannerId+" bannerLarg="+this.bannerLarg+" pos="+this.pos+" depl="+this.depl);
			}
		}
		
			
function getBannerWidth( id ){
			var larg = parseInt(0);
			var imgLargStyle, imgLarg;
			
			var carouselAs = YAHOO.util.Dom.getChildren( id );
		
			for (i=0; i<carouselAs.length; i++)
				if (carouselAs[i].tagName == "A")
					larg = larg + carouselAs[i].childNodes[0].clientWidth;
		
			return larg;
		}
		

