/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
   h - height in pixel of the floating object
   x - padding in pixel from the left side of floating object to the left side of browser window
   y - padding in pixel from the top side of floating object to the top side of browser window
   z - slide time in milisecond
                 */

function fgcAddEvent(element,event, func) {
 
    if (element.addEventListener)
        element.addEventListener(event, func, false);
    else if (element.attachEvent) {
        element.attachEvent('on'+event,func)
    }
}
function MyClass (h, x, y, z, id) {
    var isDOM, floaterObj;
    var isNS, pageHeight;
    var paddingX, paddingY, scrollTop, currentY, targetY, A, B, C, D;
    var slideTime;

    /*
   h - height in pixel of the floating object
   x - padding in pixel from the left side of floating object to the left side of browser window
   y - padding in pixel from the top side of floating object to the top side of browser window
   z - slide time in milisecond
                 */
    
    this.placeFloater=function() {
        if (isNS) {
            scrollTop = window.pageYOffset;
        } else {
            // scrollTop = document.body.scrollTop;
            var B= document.body; //IE 'quirks'
            var D= document.documentElement; //IE with doctype
            D= (D.clientHeight)? D: B;
            scrollTop = D.scrollTop;           
        }

        currentY = parseInt(floaterObj.top);

        this.mainTrigger();

    }

    this.mainTrigger=function() {
        var newTargetY = scrollTop + paddingY;
        // console.log('currentY='+currentY+" : newTargetY="+newTargetY);
        if ( currentY != newTargetY ) {
            
            if ( newTargetY != targetY ) {
                
                targetY = newTargetY;
                this.floatStart();
            }
            this.animator();
        }
    }

    this.floatStart=function() {
        var now = new Date();
        A = targetY - currentY;
        B = Math.PI / ( 2 * slideTime );
        C = now.getTime();
        if (Math.abs(A) > pageHeight) {
            D = A > 0 ? targetY - pageHeight : targetY + pageHeight;
            A = A > 0 ? pageHeight : -pageHeight;
        } else {
            D = currentY;
        }
    }

    this.animator=function() {
        var now = new Date();
        var newY = A * Math.sin( B * ( now.getTime() - C ) ) + D;
        newY = Math.round(newY);
        if (( A > 0 && newY > currentY ) || ( A < 0 && newY < currentY )) {
            floaterObj.top = newY + (isDOM ? 'px' : '');
        }
       
    }
    this.refreshValues=function() {
        if (isNS) {
            pageHeight = window.innerHeight - 20;
        } else {
            pageHeight = document.body.clientHeight;
        }

        this.placeFloater();
    }

    this.setUp=function(h, x, y, z, id) {
        if (document.getElementById) {
            isDOM = true;
            floaterObj = document.getElementById(id).style;
        } else {
            isDOM = false;
            floaterObj = document.floater;
        }
        if (navigator.appName == 'Netscape') {
            isNS = true;
        } else {
            isNS = false;
        }

        paddingX = x;
        paddingY = y;
        slideTime = z;

       // floaterObj.left = paddingX + (isDOM ? 'px' : '');
        floaterObj.top = '-' + h + (isDOM ? 'px' : '');
        var obj=this;

        fgcAddEvent(window,'resize',function() {
            obj.refreshValues();
        })
       
        window.setInterval(function() {
            obj.refreshValues();
        }, 10);

        this.refreshValues();
    }


    this.setUp(h, x, y, z, id);

}
function slide_scroll(h, x, y, z, id) {    
   
    fgcAddEvent(window, 'load',function() {
        var rdVar='var'+id;
           eval(rdVar + "= new  MyClass(60, 0, 0 , 1500, '"+id+"')");
       

    })
    
}


