function initHeartBeat(){
	backElement = document.getElementById('back');
	backElementHalf = backElement.width/2;
	movingElement = document.getElementById("backToTop");
	originalMoveingElementTopSize = parseInt(movingElement.style.top);
	downloadTop = getOffsetTop("download");
	lastScrollX = 0; lastScrollY = 0;
	windowWidth = 0;
	NewEdge = 0;
	NS = 0;
	IE =0;

	if(navigator.appName == 'Netscape'){
		NS = 1;
	}else if(navigator.appName == 'Microsoft Internet Explorer'){
		IE = 1;
	}
	currentX = currentY = 0; 
	whichIt = null;
	if(NS || IE) {action = setInterval("heartBeatY()",20);}//原來值是1000
}
	

function heartBeatY() {  
	 
    if(IE) {
        diffY = document.body.scrollTop;
    }
    if(NS) { 
        diffY = self.pageYOffset;         
    }
    if (diffY > downloadTop){
    	setStyleVisibility("backToTop",true);
    }
    else{
	    setStyleVisibility("backToTop",false);
    }
    if(diffY != lastScrollY ) {
       //topLength = movingElement.style.top.length;
	   //MovedElementTopSize = movingElement.style.top.substring(0, topLength - 2) * 1;
	   MovedElementTopSize = parseInt(movingElement.style.top);
	   if(diffY > originalMoveingElementTopSize){
	 		diffY += 50;
            diffY -= originalMoveingElementTopSize;
            percent = .1 * (diffY - lastScrollY);
        	if(percent > 0) {
         	   percent = Math.ceil(percent);
       		}else{
         	   percent = Math.floor(percent);
       		}		 
            topVal = (MovedElementTopSize + percent) + 'px' ;
        	movingElement.style.top= topVal;
        	lastScrollY = lastScrollY + percent;
        }else{
			lastScrollY = 0;
			movingElement.style.top = originalMoveingElementTopSize + 'px';
        }        
    }
} 


	
function heartBeatX(){
    if(IE) {        
        windowWidth = document.body.clientWidth;
    }
    if(NS) {         
        windowWidth = window.innerWidth;
    }
    NewEdge = windowWidth/2+196;
    if(windowWidth > backElement.width){
        if(backElement.style.marginLeft != NewEdge ){
        movingElement.style.left = NewEdge+'px';
        }
    }else if(windowWidth < backElement.width){
        movingElement.style.left = '0px';
    }
}