/**
*@param _bLeft 显示位置: true靠左显示, false靠右显示
*@param _nHeight 显示高度
*@param _nWidth 显示宽度
*@param _sPicUrl 引用的广告图地址
*/

var adTimer;
function showFloatAd(_bLeft,_nWidth,_nHeight,_sPicUrl,_sGoTo){
	var adDiv;
	
	var documentWidth = document.documentElement.scrollWidth;
	var documentHeight = document.documentElement.scrollHeight;
	var windowHeight=0;
	if(window.innerHeight){
		windowHeight = window.innerHeight;
	}else{
		windowHeight = window.document.documentElement.offsetHeight ;
	}
	
	if(_bLeft){
		if(document.getElementById("leftAdDiv")){
			adDiv = document.getElementById("leftAdDiv");
			document.getElementById("leftAdFrame").src = _sSrc;
		}else{
			adDiv = document.createElement("div");
			adDiv.id = "leftAdDiv";
			adDiv.innerHTML = "<div style=\"height:"+_nHeight+"px;width:"+_nWidth+"px;\"><a href=\""+_sGoTo+"\"><img border=\"0\" src=\""+_sPicUrl+"\"/></a></div><div style=\"text-align:right;width:"+_nWidth+"px;height:20px;\"><span onclick=\"closeAdDiv('leftAdDiv')\" style=\"cursor:pointer;\">关&nbsp;闭</span></div>";
		}
		adDiv.style.left = "10px";
	}else{
		if(document.getElementById("rightAdDiv")){
			adDiv = document.getElementById("rightAdDiv");
			document.getElementById("rightAdFrame").src = _sSrc;
		}else{
			adDiv = document.createElement("div");
			adDiv.id = "rightAdDiv";
adDiv.innerHTML = "<div style=\"height:"+_nHeight+"px;width:"+_nWidth+"px;\"><a href=\""+_sGoTo+"\"><img border=\"0\" src=\""+_sPicUrl+"\"/></a></div><div style=\"text-align:left;width:"+_nWidth+"px;height:20px;\"><span onclick=\"closeAdDiv('rightAdDiv')\" style=\"cursor:pointer;\">关&nbsp;闭</span></div>";
		}
	
		adDiv.style.left = documentWidth-_nWidth+window.document.body.scrollLeft-30;
	}
	adDiv.style.position = "absolute";
	adDiv.style.height = _nHeight+20+"px";
	adDiv.style.width = _nWidth+"px";
	
	adDiv.style.top = Math.min(windowHeight,documentHeight)-_nHeight+document.body.scrollTop-10;
	document.body.appendChild(adDiv);
	adDiv.style.display = "block";
	adTimer = window.setInterval(floatAd,666);
}
/**
* close ad div
*/
function closeAdDiv(adDivId){
	document.getElementById(adDivId).style.display = "none";
	var leftAdDiv = document.getElementById("leftAdDiv");
	var rightAdDiv = document.getElementById("rightAdDiv");
	if(leftAdDiv.style.display=="none"&&rightAdDiv.style.display=="none"){
		window.clearInterval(adTimer);
	}
}

/**
*float ad div to the bottom of window
*/
function floatAd(){
	var documentHeight = 0;
	if(document.documentElement.scrollWidth){
		documentHeight = document.documentElement.scrollHeight;
	}else{
		documentHeight = window.document.body.scrollHeight;
	}
	var windowHeight=0;
	if(window.innerHeight){
		windowHeight = window.innerHeight;
	}else{
		windowHeight = window.document.documentElement.offsetHeight ;
	}
	var leftDiv = document.getElementById("leftAdDiv");
	if(leftDiv){
		leftDiv.style.top = Math.min(windowHeight,documentHeight)-parseInt(leftDiv.style.height)+document.body.scrollTop-10;
	}
	var rightDiv = document.getElementById("rightAdDiv");
	if(rightDiv){
		rightDiv.style.top = Math.min(windowHeight,documentHeight)-parseInt(rightDiv.style.height)+document.body.scrollTop-10;
	}
}