/*
Cette création est mise à disposition selon le Contrat Paternité-Partage des Conditions Initiales à l'Identique 3.0 Unported disponible en ligne http://creativecommons.org/licenses/by-sa/3.0/ ou par courrier postal à Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
*/
/* extension prototype */
var Horinaja = Class.create();
Horinaja.prototype = {
	initialize: function(capture, duree, secExecution, pagination){
		this.capture = capture;
		this.duree = duree;
		this.secExecution = secExecution;
		this.pagination = pagination;
		this.nCell = 0;
		this.id = 1;
		this.po = 0;	
		this.f = $$('div#'+this.capture+' ul li');
		this.px = $(this.capture).getWidth();
		this.pxH = $(this.capture).getHeight();
		this.start();
	},
	start: function(){		
				this.mover = $(this.capture).firstDescendant();	
				this.nCell = this.f.length;	
				for(i=0;i!=this.nCell;i++){
					this.f[i].setStyle({
					  width: this.px+'px',					  
					  float: 'left'
					  });	
				}
				$(this.capture).setStyle({
					overflow:'hidden',
					position: 'relative'
					});
				
				$(this.capture).firstDescendant().setStyle({
					width:(this.px*this.nCell)+'px'
					});	
				this.startPe();
        this.nextButton = $('horinaja-navi-next');
        this.prevButton = $('horinaja-navi-prev');
        Event.observe($(this.nextButton),"click", this.moveP.bind(this));
        Event.observe($(this.prevButton),"click", this.moveP.bind(this));
	},
	startPe: function(){
	this.periodik = new PeriodicalExecuter(this.Pe.bind(this),this.secExecution);	
	},
	stopPe: function(){
	this.periodik.stop();
	},
	effaceP: function(mop){
		this.mop = mop;		
	},
	move: function(xp){
		this.xp = xp;
		new Effect.Move(this.mover, { 
					x: this.xp, 
					y: 0,
					mode:'absolute',
					duration: this.duree,
					transition: Effect.Transitions.sinoidal
				});
	},	
	Pe: function(){
					if(this.id<this.nCell){
							this.po=this.po-this.px;
							this.effaceP(this.id);
							this.id=this.id+1;
							this.move(this.po);
						}else{
							this.po=0;
							this.effaceP(this.id);
							this.id=1;
							this.move(this.po);
						}
	},
	moveP: function(evt){
    var child = Event.element(evt);   
		if(child.hasClassName('horinaja-navi-next')){
      if(this.id<this.nCell){
        this.po=this.po-this.px;
        this.effaceP(this.id);
        this.id=this.id+1;
        this.move(this.po);
      }else{
        this.po=0;
        this.effaceP(this.id);
        this.id=1;
        this.move(this.po);
      }
		}else if(child.hasClassName('horinaja-navi-prev')){
			if(this.id!=1){
        this.po=this.po+this.px;
        this.effaceP(this.id);
        this.id=this.id-1;
        this.move(this.po);
      }else{
        this.po=-this.px*(this.nCell-1);
        this.effaceP(this.id);
        this.id=this.nCell;
        this.move(this.po);
      }
		}
	},
	stopEvent:function(pE)
	{
	   if (!pE)
		 if (window.event)
		   pE = window.event;
		 else
		   return;
	  if (pE.cancelBubble != null)
		 pE.cancelBubble = true;
	  if (pE.stopPropagation)
		 pE.stopPropagation();
	  if (pE.preventDefault)
		 pE.preventDefault();
	}
};

