function FloatingObject(id) {

    this.A  = null;
    this.B  = null;
    this.C  = null;
    this.D  = null;
    this.id = id;
    
    this.currentY       = 0;
    this.startY         = 0;
    this.style          = "";
    this.targetY        = 0;
    this.newTargetY     = 0;    
    this.topOffset      = 200;
    this.startScrolling = 0;
    this.bottomOffset   = 0;    
    this.height         = 0;    
    this.slideTime      = 1200;
        
    this.element        = document.getElementById(this.id);
      
    if(ns6 || ns4) {        
        this.startY = parseInt(this.element.style.top);
        this.height = parseInt(document.defaultView.getComputedStyle(this.element,'')['height']);
    } else if(ie4) {        
        this.startY = parseInt(this.element.style.pixelTop);
        this.height = parseInt(this.element.offsetHeight);
    }       
    this.B = Math.PI / ( 2 * this.slideTime );
    
    //alert(this.height + "  "+ this.startY+" "+this.element.style.top);
}

var Floater = {

    pageHeight : 0,
    floatingObjects : new Array(),
    scrollTop : 0,
    
    add : function(object) {
        this.floatingObjects.push( object );
    },

    start : function() {
        pageHeight  = document.body.clientHeight;
        window.setInterval("Floater.floatingTrigger()", 100);      
        //alert((new Date()).getTime());
        //alert(this.floatingObjects[0].height + " "+ this.floatingObjects[0].startY);
        //alert(ie4+" - "+ns4+" * "+ns6);
    },

    floatingTrigger : function () {
        
        for(i=0 ; i < this.floatingObjects.length; i++){
            if (ns4) {
                this.floatingObjects[i].currentY = document.layers[floatingObjects[i].id].top;
                this.scrollTop = window.pageYOffset;
            } else if(ns6) {
                this.floatingObjects[i].currentY = parseInt(document.getElementById(this.floatingObjects[i].id).style.top);        
                this.scrollTop = window.scrollY;
            } else if(ie4) {
                this.floatingObjects[i].currentY = document.all[this.floatingObjects[i].id].style.pixelTop;
                this.scrollTop  = document.documentElement.scrollTop;        
            }
        }
        
        for(i=0 ; i < this.floatingObjects.length; i++){
            //window.status = this.scrollTop + " "+this.floatingObjects[i].startScrolling + " "+this.floatingObjects[i].height;
            if(this.scrollTop > this.floatingObjects[i].startScrolling) {
                this.floatingObjects[i].newTargetY = this.scrollTop + this.floatingObjects[i].startY-this.floatingObjects[i].topOffset;
                //this.floatingObjects[i].newTargetY = this.floatingObjects[i].scrollTop - this.floatingObjects[i].startY-this.floatingObjects[i].topOffset;
            } else {
                this.floatingObjects[i].newTargetY =  parseInt(this.floatingObjects[i].startY);
            }
            
            //window.status = this.floatingObjects[0].newTargetY+" "+this.scrollTop;
            
            //window.status =this.floatingObjects[i].currentY +" "+ this.floatingObjects[i].newTargetY;
            
            if ( this.floatingObjects[i].currentY != this.floatingObjects[i].newTargetY ) {
                var now = new Date();
                if ( this.floatingObjects[i].newTargetY != this.floatingObjects[i].targetY ) {
                    this.floatingObjects[i].targetY = this.floatingObjects[i].newTargetY;
                    this.floatingObjects[i].A = this.floatingObjects[i].targetY - this.floatingObjects[i].currentY;
                    this.floatingObjects[i].C = now.getTime();
                    
                    if (Math.abs(this.floatingObjects[i].A) > this.findHt) {
                        this.floatingObjects[i].D = this.floatingObjects[i].A > 0 ? this.floatingObjects[i].targetY - this.findHt : this.floatingObjects[i].targetY + this.findHt;
                        this.floatingObjects[i].A = this.floatingObjects[i].A > 0 ? this.findHt : -this.findHt;        
                    } else {
                        this.floatingObjects[i].D = this.floatingObjects[i].currentY;
                    }
                }
                
                var newY = this.floatingObjects[i].A * Math.sin( this.floatingObjects[i].B * ( now.getTime() - this.floatingObjects[i].C ) ) + this.floatingObjects[i].D;
                
                newY = Math.round(newY);
                
                //window.status = (parseInt(newY) + parseInt(this.floatingObjects[i].bottomOffset) + parseInt(this.floatingObjects[i].height)) +" "+ pageHeight;
                if( (parseInt(newY) + parseInt(this.floatingObjects[i].bottomOffset) + parseInt(this.floatingObjects[i].height)) > ( parseInt(pageHeight) ) ) {
                //if( (parseInt(newY) + parseInt(this.floatingObjects[i].bottomOffset) + parseInt(this.floatingObjects[i].height)) > ( parseInt(this.scrollTop) ) ) {
                    newY = ( parseInt(pageHeight) - parseInt(this.floatingObjects[i].bottomOffset) - parseInt(this.floatingObjects[i].height));// + "px";
                }
                
                //window.status = parseInt(pageHeight) +" "+ parseInt(this.floatingObjects[0].bottomOffset) +" "+ parseInt(this.floatingObjects[0].height) + " "+this.floatingObjects[0].startY+" "+this.floatingObjects[0].topOffset+ " "+this.floatingObjects[0].bottomOffset+ " "+this.floatingObjects[0].newTargetY + " " + this.scrollTop;
                
                if( ( this.floatingObjects[i].A > 0 && newY > this.floatingObjects[i].currentY ) ||
                    ( this.floatingObjects[i].A < 0 && newY < this.floatingObjects[i].currentY ) ) {
                    if ( ie4 ) document.all[this.floatingObjects[i].id].style.pixelTop       = newY;
                    //if ( ns4 ) document.layers[this.floatingObjects[i].id].top               = newY;
                    if( ns4 || ns6 ) document.getElementById(this.floatingObjects[i].id).style.top = newY+"px";
                    //alert(document.getElementById(this.floatingObjects[i].id).style.top);
                }
                
               // window.status = document.getElementById(this.floatingObjects[0].id).style.top;
                //window.status = this.floatingObjects[0].id;
            }

        }
        
    }

};
