// (c) Xatcom.net
function cmrBallooner(ID) {
	this.IsMoz = ((navigator.appName).search("Microsoft")==-1) ? true : false;
	this.Texts = new Array();
	this.ID = ID;
	this.oB;
	this.tmpObj;
	this.timeout=0;
	this.timeoutON=false;
	this.fadeval = 0;
	this.fadeIncr = 0;
	this.fadeLimit = 100;
	this.fadeTh;
	this.AutoClose = true;
	this.Create = function() {
		this.oB = document.createElement("DIV");
		var oBt = document.createElement("DIV");
		var oBm = document.createElement("DIV");
		var oBb = document.createElement("DIV");
		this.oB.setAttribute('id', "d"+this.ID);
		this.oB.style.position = "absolute";
		if (this.IsMoz) {
		this.oB.style.top = "0px";
		this.oB.style.left = "0px";
		} else {
		this.oB.style.pixelTop = "0px";
		this.oB.style.pixelLeft = "0px";
		}
		this.oB.style.visibility = "hidden";
		this.oB.className = "cmrBalloon";
		this.oB.style.display = "block";
		oBt.setAttribute('id', "d"+this.ID+"_t");
		oBt.style.position = "relative";
		oBt.style.display = "block";
		oBt.className = "cmrBalloon_t";
		oBm.setAttribute('id', "d"+this.ID+"_txt0");
		oBm.style.position = "relative";
		oBm.style.display = "block";
		oBm.style.cursor = "pointer";
		oBm.className = "cmrBalloon_m";
		eval("oBm.onclick = function() {" + this.ID + ".Close();}");
		eval("oBm.onmouseover = function() {" + this.ID + ".timeout=3000;" + this.ID + ".timeoutON=false;}");
		eval("oBm.onmouseout = function() {" + this.ID + ".timeoutON=true;}");
		oBb.setAttribute('id', "d"+this.ID+"_b");
		oBb.style.position = "relative";
		oBb.style.display = "block";
		oBb.className = "cmrBalloon_b_arrow";
		this.oB.appendChild(oBt);
		this.oB.appendChild(oBm);
		this.oB.appendChild(oBb);
		document.body.appendChild(this.oB);
	} //End:Create
	this.FadeIn = function() {
		if (this.fadeval>=this.fadeLimit) return;
		this.fadeval = 0;
		if (this.IsMoz) {
			this.fadeIncr = 0.1;
			this.fadeLimit = 1;
		} else {
			this.fadeIncr = 10;
			this.fadeLimit = 100;
		}
		this.Fade();
	} //End:FadeIn
	this.Fade = function() {
		this.fadeval+=this.fadeIncr;
		if (this.IsMoz) { eval(this.ID+".oB.style.opacity=" + this.fadeval.toString()); } else { eval(this.ID+".oB.style.filter = 'alpha(opacity=" + this.fadeval.toString() + ")'"); }
		if (this.fadeval<this.fadeLimit) {
			this.fadeTh = setTimeout(this.ID+".Fade()",33);
		}
	} //End:Fade
	this.Show = function() {
		if ( arguments.length>2 ) { this.AutoClose=arguments[2]; }
		document.getElementById("d"+this.ID+"_txt0").innerHTML = arguments[1];
		this.ResizeAndShow(arguments[0]);
		this.FadeIn();
		//eval("obj.onmouseout = function() {"+this.ID+".DelayedClose();}");
		this.DelayedClose();
	} //End:Show
	this.LoadURL = function(obj, url) {
		this.tmpObj = obj;
		this.Show(obj, "<div id=\"d"+this.ID+"_txt0\"><div class=\"cmrBalloon_loading\"></div></div>");
		this.FadeIn();
		Ajax_Open(url, "AJAXLoading_result(0,'d"+this.ID+"_txt', '" + this.ID + ".LoadURL_resp()')", 0);
	} //End:LoadURL
	this.LoadURL_resp = function() {
		//if (status) {
			this.ResizeAndShow(this.tmpObj);
			this.DelayedClose();
		/*} else {
			this.Close();
		}*/
	} //End:LoadURL_resp
	this.ResizeAndShow = function(obj) {
		var ex, ey;
		var bw, bh;
		var ox, oy;
		var oh;
		var p=0;
		var yscroll;
		var WinSize = GetInnerSize(); //Get window size
		if (this.IsMoz) { yscroll = window.scrollY; } else { yscroll = document.body.scrollTop; }

		this.oB.style.display = "block";
		
		bh = GetLayerHeight("d"+this.ID);
		bw = GetLayerWidth("d"+this.ID);
		ox = findPosX(obj);
		oy = findPosY(obj);
		oh = obj.offsetHeight;
		//Posiciona X
		p = ox + obj.offsetWidth/2 - bw/2;
		if (p<0) p=0;
		if ( (p+bw)>=(WinSize[0]-18) ) p=WinSize[0]-bw-18;
		if (this.IsMoz) { this.oB.style.left = p.toString() + "px"; } else { this.oB.style.pixelLeft = p; }
		//Posiciona Y
		if ( (oy-(bh*2)-5)<=yscroll ) {
			if (this.IsMoz) { this.oB.style.top = (oy+oh+5).toString()+ "px"; } else { this.oB.style.pixelTop = oy+oh+5; }
			this.ChClass("d"+this.ID+"_t", "cmrBalloon_t_arrow");
			this.ChClass("d"+this.ID+"_b", "cmrBalloon_b");
		} else {
			if (this.IsMoz) { this.oB.style.top = (oy-bh).toString() + "px"; } else { this.oB.style.pixelTop = oy-bh-5; }
			this.ChClass("d"+this.ID+"_t", "cmrBalloon_t");
			this.ChClass("d"+this.ID+"_b", "cmrBalloon_b_arrow");
		}
		
		if (this.fadeval==0) if (this.IsMoz) { this.oB.style.opacity=0; } else { this.oB.style.filter = 'alpha(opacity=0)'; }
		this.oB.style.visibility = "visible";
	} //End:Resize
	this.ChClass = function(div, cname) {
		document.getElementById(div).className = cname;
	} //End:ChClass
	this.Close = function(div, cname) {
		if (this.fadeval<this.fadeLimit) clearTimeout(this.fadeTh);
		this.oB.style.visibility = "hidden";
		this.oB.style.display = "none";
		this.fadeval = 0;
	} //End:Close
	this.DelayedClose = function() {
		this.timeout=3500;
		if( (!this.timeoutON) && this.AutoClose ) { this.timeoutON=true; this.TimeoutClose(); }
	} //End:TimeoutClose
	this.TimeoutClose = function() {
		if (this.timeoutON) this.timeout-=250;
		if (this.timeout<=0) {
			this.Close();
			this.timeoutON=false;
			return;
		} else {
			eval("setTimeout('"+this.ID+".TimeoutClose()',250);");
		}
	} //End:TimeoutClose
	this.Create();
} //End:cmrBallooner
var Balloon;
function cmrBalloonerLoad() {
	var b = document.body;
	if (b!=null) {
		Balloon = new cmrBallooner("Balloon");
	} else {
		setTimeout("cmrBalloonerLoad()",30);
	}
}
cmrBalloonerLoad();
