/*
*	Jane¸¡¶¯¹ã¸æÀà V1.0.0
*	create 2008-6-20
*	last modified 2008-6-20
*	laoqiming@gmail.com
*	copyright (c) http://camen.cosbeauty.net
*/
if(typeof JaneFloaterManager =='undefined'){
	JaneFloaterManager = {};
	JaneFloaterManager.ads =[];
	JaneFloaterManager.find = function(id){
		for(var i=0;i<this.ads.length;i++){
			if(this.ads[i].id == id)
				return this.ads[i];
		}
		return ;
	}
}
function JaneFloater( width ,height ){
	this.position = [1,1];
	this.float = 1;
	this.offset = [0,0];
	this.index = JaneFloaterManager.ads.length;
	JaneFloaterManager.ads.push(this);
	this.html = "";
	this.width = width || 88;
	this.height = height || 31;
	this.c_width = this.width;
	this.c_height = this.height;
	this.compatMode = false;
	if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		this.compatMode = true;
	this.isIE6 = (navigator.appVersion.indexOf("MSIE 6.0")>-1?1:0);
	this.isIE7 = (navigator.appVersion.indexOf("MSIE 7.0")>-1?1:0);
	this.toString = function(){
		var ps = this.getPosition();
		var domPosition = "fixed";
		if(this.isIE6)domPosition="absolute";
		if(!this.float)domPosition="absolute";
		if(this.isIE7 && !this.compatMode)domPosition="absolute";
		var html = '<div id="JaneFloaterContainer' + this.index + '" style="z-index:9999;position:' + domPosition + ';width:' + this.c_width + 'px;height:' + this.c_height + 'px;top:' + ps.y + 'px;left:' + ps.x + 'px;"></div>';
		return html;
	}
	this.render = function(){
		document.write(this.toString())
		document.getElementById('JaneFloaterContainer' + this.index).innerHTML = this.html;
		var _self = this;
		this.attachEvent(window,"resize",function(){
			JaneFloaterManager.ads[_self.index].setPosition();
		})
		if(this.float){
			if(!this.compatMode){
				this.attachEvent(window,"scroll",function(){
					JaneFloaterManager.ads[_self.index].setPosition();
				})
			}else{
				this.attachEvent(window,"scroll",function(){
					JaneFloaterManager.ads[_self.index].setPosition();
				})
			}
		}
	}
	this.attachEvent = function(a,b,c){
		if(a.attachEvent)
			a.attachEvent("on"+b,c);
		else
			a.addEventListener(b,c,false);
	}

	this.getPosition = function(){
		var ps = {x:0,y:0};
		if(this.position[0] >0){
			var db = this.compatMode ? document.documentElement : document.body;
			if(this.float && (this.isIE6 || (!this.compatMode && this.isIE7) ) ){
				ps.x += db.scrollLeft;
				ps.y += db.scrollTop;
			}
			ps.x += ((this.position[0]-1) % 3) * (db.clientWidth/2);
			ps.y += (Math.ceil(this.position[0] / 3)-1) * (db.clientHeight/2);
			ps.x -= ((this.position[1]-1) % 3) * (this.c_width/2);
			ps.y -= (Math.ceil(this.position[1] / 3)-1) * (this.c_height/2);
			ps.x += this.offset[0];
			ps.y += this.offset[1];
		}
		return ps;
	}
	this.setPosition = function(){
		var ps = this.getPosition();
		document.getElementById("JaneFloaterContainer" + this.index).style.top = ps.y +"px";
		document.getElementById("JaneFloaterContainer" + this.index).style.left = ps.x +"px";
	}
	this.hide = function(){
		document.getElementById("JaneFloaterContainer" + this.index).style.visibility = "hidden";
	}
	this.show = function(){
		document.getElementById("JaneFloaterContainer" + this.index).style.visibility = "visible";
	}
}
