/******************************************************************************
  Crossday Discuz! Board - Floating Advertisements for Discuz!
  Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
*******************************************************************************/

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function lsfloatdiv(id, sx, sy, content) {	

	document.write('<div id=' + id + ' style="z-index: 10; position: absolute; width:' + (document.body.clientWidth - (typeof(sx) == 'string' ? eval(sx) : sx)*2) + 'px; left:' + (typeof(sx) == 'string' ? eval(sx) : sx) + ';top:' + (typeof(sy) == 'string'? eval(sy) : sy) + '">' + content + '</div>');
	var el = document.getElementById(id);//d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style = el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP = function(x, y) { this.style.left=x+px;this.style.top=y+px; };

	el.floatIt = function() {		
		var pX, pY;
		pX = (this.sx >= -4) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	//分辨率小于800*600隐藏浮动广告
	var lengthobj = getPageSize();
	if(lengthobj[0] < 1002) {
		closeBanner(id);
	}	
	return el;
}

function centerfloatdiv(id,sw, sy, content) {	
	document.write('<div id=' + id + ' style="z-index: 10; position: absolute; width:' + sw + 'px;left:' + (document.body.clientWidth - (typeof(sw) == 'string' ? eval(sw) : sw))/2 + 'px;top:' + (typeof(sy) == 'string'? eval(sy) : sy) + '">' + content + '</div>');
	
	var el = document.getElementById(id);//d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style = el;
	
	el.cy = el.sy = sy;
	el.sP = function(y) {this.style.top=y+px; };
	
	el.floatIt = function() {		
		var pY;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	//分辨率小于800*600隐藏浮动广告
	var lengthobj = getPageSize();
	if(lengthobj[0] < sw) {
		closeBanner(id);
	}	
	return el;
}

function closeBanner(id) {
	if(typeof(getbyid(id)) == 'object') { getbyid(id).style.display = 'none'; }
}
function getbyid(id){
	return document.getElementById(id);
}
function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}

//顶边型
//var floatleft_pic_obj=lsfloatdiv("floatleft_pic",0,150,'<img src="http://ajian.com/02.gif"/>');
//	floatleft_pic_obj.floatIt();

//居中型
//	var floatright_pic2_obj=centerfloatdiv("floatright_pic2",1076,150,'<div style="width:45px;float:left;"><img src="http://work.hjian.net/02.gif"/></div><div style="width:45px;float:right;"><img src="http://work.hjian.net/02.gif"/></div>');
//	floatright_pic2_obj.floatIt();