
function Marquee(box,content,speed,dirc,coefOverSpeed){
    //ini les variables
    this.timer = 20;
    this.box=$(box);
    this.content=$(content);
    this.speed=speed || 1;
    this.dirc=dirc || 'left';
    this.coefDirc=1;
    this.coefOverSpeed=coefOverSpeed || 3;
    this.inverseDirc=(this.dirc=='bottom' || this.dirc=='right');
    var verticalDirc=(this.dirc=='bottom' || this.dirc=='top');

    //on repositionne les élements + cache les scrolls 
    this.box.style.overflow='hidden';
    this.box.style.position='relative';//ie7 bug
    this.content.style.position='relative';

    //calcule la dimension du conteneur  + la dimention du contenue 
    var boxDim=this.box['client'+(verticalDirc?'Height':'Width')];
    var contentDim=this.content['offset'+(verticalDirc?'Height':'Width')];

    if (contentDim > boxDim) {
        //on retient la moitier de la dim , pour le mouse over
        this.middleDim=boxDim/2;

        //on definit les position max et de départ
        this.leftStartStep = 0;
        this.leftMaxDim = -(contentDim-boxDim);
        this.rightStartStep = -(contentDim-boxDim);
        this.rightMaxDim = 0;
        this.currentStep = (this.inverseDirc ? this.rightStartStep : this.leftStartStep);

        //ajoutes les evenemnts
        this.eventOver=this.onMouseover.bindAsEventListener(this);
        Event.observe(this.box,'mouseover',this.eventOver);

        this.eventOut=this.onMouseout.bindAsEventListener(this);
        Event.observe(this.box,'mouseout',this.eventOut);

        this.interval=setInterval(this.interval.bind(this),35);

        this.eventUnload=this.unload.bindAsEventListener(this);
        Event.observe(window,'unload',this.eventUnload.bind(this));
    }
}
Marquee.prototype = {
    onMouseout : function(e){
        Event.stopObserving(this.box,'mousemove',this.eventMouseMove);
        this.coefDirc=1;
    },
    onMouseover : function(e){
        this.coefDirc = 0;
        /* 
        var dim=Element.viewportOffset(this.box);
        if(this.dirc=='top' || this.dirc=='bottom'){
        this.coor=[dim[1],dim[1]+this.box.clientHeight];
        }else this.coor=[dim[0],dim[0]+this.box.clientWidth];
        this.mouseMove(e);
        this.eventMouseMove=this.mouseMove.bindAsEventListener(this);
        Event.observe(this.box,'mousemove',this.eventMouseMove);
        */
    },
    interval : function(){
        if (this.timer >= 20) {
            var coeff = 100;
            if(this.currentStep > this.rightMaxDim - 100)
                coeff = coeff - (98 + (this.currentStep - this.rightMaxDim));
             else if(this.currentStep < this.leftMaxDim + 100)
                coeff = coeff - (98 - (this.currentStep - this.leftMaxDim));

            var acc=Math.ceil(this.speed*this.coefDirc*coeff/100);
            var incr = (this.inverseDirc ? this.currentStep+acc : this.currentStep-acc)
            $(this.content).style['left'] = incr+'px';
            this.currentStep = incr;


            if(this.inverseDirc)
            {
                if (this.currentStep >= this.rightMaxDim)
                {
                    this.timer = 0;
                    this.inverseDirc = false;
                    this.currentStep=this.leftStartStep;
                }
            }
            else
            {
                if (this.currentStep <= this.leftMaxDim)
                {
                    this.timer = 0;
                    this.inverseDirc = true;
                    this.currentStep=this.rightStartStep;
                }
            }
        }
        else 
            this.timer++;
    },
    mouseMove:function(e){
        if (this.dirc=='top' || this.dirc=='bottom')
            var mouseCoor=Event.pointer(e).y;
        else
            var mouseCoor=Event.pointer(e).x;
        var inverseCoeff=(mouseCoor-this.coor[0]>this.coor[1]-mouseCoor);
        var coef=inverseCoeff?this.coor[1]-mouseCoor:mouseCoor-this.coor[0];
        this.coefDirc=((this.middleDim-coef)/this.middleDim)*this.coefOverSpeed;
        if (inverseCoeff)this.coefDirc=-this.coefDirc;
        if (this.inverseDirc)this.coefDirc=-this.coefDirc;
    },
    unload : function(){
        clearInterval(this.interval);
        Event.stopObserving(this.box,'mouseover',this.eventOver);
        Event.stopObserving(this.box,'mouseout',this.eventOut);
        Event.stopObserving(window,'unload',this.eventUnload.bind(this));    
    }
}


