﻿/*
Copyright by Audi 2006
http://audi.tw
http://www.carousel.com.tw
歡迎應用於無償用途散播，並請勿移除本版權宣告

*/

var currentX = currentY = 0;
var whichIt = null;
var lastScrollX = 0; lastScrollY = 0;
var isNS = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >=5)) ? 1 : 0;
var isIE = (document.all) ? 1: 0;
var isOP = (navigator.userAgent.toLowerCase().indexOf("opera") != -1) ? 1 : 0;
var layerWidth,layerHeight;

var scrollSpeed=30		//捲動速度

function initFloater(){
	if (isIE){ // mean ie4,ie5,ie5.5 or above
		layerHeight=document.getElementById('cMain').clientHeight;
		layerWidth=document.getElementById('cMain').clientWidth;
	}

	if (isNS){
		layerHeight=document.getElementById('cMain').offsetHeight;
		layerWidth=document.getElementById('cMain').offsetWidth;
	}

	bHeight=(isNS)?window.innerHeight:document.body.clientHeight;
	bWidth=(isNS)?window.innerWidth:document.body.clientWidth;

	//width=960,height=132;

	newY=132;
	newX=(bWidth-976)/2+220;

	if (isNS){
		newX=(bWidth>976)?((bWidth-976)/2+220):220;
		document.getElementById('cMain').style.top=newY+'px';
		document.getElementById('cMain').style.left=newX+'px';
	}

	if (isIE){
		newX=(bWidth>976)?((bWidth-976)/2+220):220;
		document.getElementById('cMain').style.pixelTop=newY;
		//document.getElementById('cMain').style.pixelLeft=newX;
	}

	if (isOP){
		newX=(bWidth>976)?((bWidth-976)/2+220):220;
		document.getElementById('cMain').style.top=newY+'px';
		document.getElementById('cMain').style.left=newX+'px';
	}

	window.setInterval('heartBeat()',1);
}

function heartBeat() {
	if(isIE){
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
		//"iebody" is a variable that now contains the proper reference to "scrollLeft" and "scrollTop" in IE, regardless of the IE version or doctype.
		diffY = iebody.scrollTop;
		diffX = 0;
	}

	if(isNS){
		diffY = self.pageYOffset;
		diffX = 0;
	}

	if (diffY<132){diffY=0;}else{diffY-=132;}

	if (document.getElementById('cMain').style.visibility!='hidden'){
		if(diffY != lastScrollY){
			percent = 1 * (diffY - lastScrollY) / scrollSpeed;
			if(percent > 0) percent = Math.ceil(percent);
			else percent = Math.floor(percent);

			if (isNS){
				newY=parseInt(document.getElementById('cMain').style.top);
				newY+=percent;
				newY=newY+'px';
				document.getElementById('cMain').style.top = newY;
			}
			if (isIE){
				newY=parseInt(document.getElementById('cMain').style.pixelTop);
				newY+=percent;
				newY=newY;
				document.getElementById('cMain').style.pixelTop = newY;
			}

			lastScrollY += percent;
		}
	}
	//window.status='Y:'+ diffY;
}


