﻿/*基本操作*/
function tep$(id){
	return document.getElementById(id);
}

function closeBanner(id) {
	var thisObj = tep$(id);
	//var thisObj = tep$('followDiv1');
	thisObj.parentNode.removeChild(thisObj);
	//thisObj = tep$('followDiv2');
	//thisObj.parentNode.removeChild(thisObj);
}
var float_Top=100;	//112
var float_Heigth = 310;	//300

function resetFloatAdTop() {
	var nowScrollTop = parseInt(document.documentElement.scrollTop);
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	var wrap=tep$("wrap");
	var leftFollowAdChild = tep$("leftFollowAd").childNodes;
	var rightFollowAdChild = tep$("rightFollowAd").childNodes;

	var hasAd = false;
	var allAd=0;
	for(var i=0,len=leftFollowAdChild.length;i<len;i++){
		var div = leftFollowAdChild[i];
		if(div.nodeType != 1) { continue; }
		if (div) {
			if(wrap){
				var left=wrap.offsetLeft-(div.offsetWidth+10);
				if(left<0) left=10;
				div.style.left=left+"px";	//
			}
			div.style.top = (nowScrollTop+float_Top+allAd*float_Heigth)+"px";	//
			hasAd = true;
			allAd++;
		}
		div = null;
	}
	
	var allAd=0;
	for(var i=0,len=rightFollowAdChild.length;i<len;i++){
		var div = rightFollowAdChild[i];
		if(div.nodeType != 1) { continue; }
		if (div) {
			if(wrap){
				var right=wrap.offsetLeft+wrap.offsetWidth+10;
				if(windowWidth<(wrap.offsetWidth+div.offsetWidth)) right=wrap.offsetWidth-(div.offsetWidth+10);
				div.style.left=right+"px";
			}
			div.style.top = (nowScrollTop+float_Top+allAd*float_Heigth)+"px";
			hasAd = true;
			allAd++;
		}
		div = null;
	}
	
	if (!hasAd) {
		window.clearInterval(intervalC);
	}
	
}
var intervalC = setInterval('resetFloatAdTop()', 30);
if (parseInt(screen.width)<1024) {
	for(var i=0,len=leftFollowAdChild.length;i<len;i++){
		var div = leftFollowAdChild[i];
		if(div.nodeType != 1) { continue; }
		closeBanner(div.id);
	}
	for(var i=0,len=rightFollowAdChild.length;i<len;i++){
		var div = rightFollowAdChild[i];
		if(div.nodeType != 1) { continue; }
		closeBanner(div.id);
	}
}

function makeMyFloat(){
	window.clearInterval(intervalC);
	intervalC = setInterval('resetFloatAdTop()', 30);
}
