function imod_BubblePanel(sPrmClientId, bPrmAutoWidth, bPrmAutoHeight, sPrmPosition, bPrmDraggable, bPrmMaintainNodePosition) {
	var ClientId = sPrmClientId;
	var TitleId = sPrmClientId + "_Title";
	var ContentId = sPrmClientId + "_Content";
	var FooterId = sPrmClientId + "_Footer";
	var AutoWidth = bPrmAutoWidth;
	var AutoHeight = bPrmAutoHeight;
	var Position = sPrmPosition;
	var Loaded = false;
	var Draggable = (bPrmDraggable != null) ? bPrmDraggable : false;
	var Dragging = false;
	var DragOffsetX = 0, DragOffsetY = 0;
	var MaintainNodePosition = bPrmMaintainNodePosition;
		
	var MaxHeight = 0;
	
	if (Position == null)
		Position = "relative";
		
	this.Attributes = {};
	
	this.Show = Show;
	this.Hide = Hide;
	this.ResizePanel = ResizePanel;
	this.Move = Move;
	this.SetPosition = SetPosition;
	this.IsVisible = IsVisible;
	this.GetTitle = GetTitle;
	this.SetTitle = SetTitle;
	this.SetMaxHeight = SetMaxHeight;
	this.GetElement = GetElement;
	this.Center = Center;
	
	_imod_BubblePanel();
	
	function _imod_BubblePanel() {
		imod_AddHandler(window, "load", Load);
		imod_AddHandler(window, "unload", Unload);
		/*
		if (window.addEventListener != null)
			window.addEventListener("load", Load, false);
		else if (window.attachEvent != null)
			window.attachEvent("onload", Load);
		else
			window.onload = Load;
		*/
	}
	
	function Load() {
		Loaded = true;
		var oPanel = document.getElementById(ClientId);
		oPanel.style.position = Position;		
		//if (window.attachEvent)
		//if (imod.Browser.IE)
		if (! MaintainNodePosition)		
		document.forms[0].appendChild(oPanel);
		ResizeContent();
	
		if (Draggable) {
			var oTitle = document.getElementById(TitleId);
			
			imod_AddHandler(document.body, "mousemove", Track);
			//imod_AddHandler(oTitle, "mousedown", Drag, true);
			imod_AddHandler(oTitle, "mousedown", Drag, false);
			imod_AddHandler(document.body, "mouseup", Drop);
			oTitle.style.MozUserSelect = "none";
			imod_AddHandler(oTitle, "selectstart", PreventTextSelect);
			
			/*
			if (window.addEventListener != null) {
				document.body.addEventListener("mousemove", Track, false);
				oTitle.addEventListener("mousedown", Drag, true);
				document.body.addEventListener("mouseup", Drop, false);
				oTitle.style.MozUserSelect = "none";
			}
			else if (window.attachEvent != null) {
				document.body.attachEvent("onmousemove", Track);
				oTitle.attachEvent("onmousedown", Drag);
				document.body.attachEvent("onmouseup", Drop);
				oTitle.attachEvent("onselectstart", PreventTextSelect);
			}
			else {
				document.body.onload = Track;
				oTitle.onmousedown = Drag;
				document.body.onmouseup = Drop;
			}
			*/
		}
	}
	
	function GetElement() {
		return $(ClientId);
	}
	
	function Unload() {
		this.Attributes = null;
		imod_RemoveHandler(window, "unload", Unload);
	}
	
	function GetTitle() {
		var oTitle = document.getElementById(TitleId);
		return oTitle.innerHTML;
	}
	
	function SetTitle(sPrmTitle) {
		var oTitle = document.getElementById(TitleId);
		oTitle.innerHTML = sPrmTitle;
	}
	
	function IsVisible() {
		var oPanel = document.getElementById(ClientId);
		if (oPanel.style.display == "none")
			return false;
		return true;
	}
	
	function Show(bPrmCheckBoundaries, prmX, prmY, prmZIndex) {
		var oPanel = document.getElementById(ClientId);
		if (prmX != null && prmY != null)
			Move(prmX, prmY);
		if (prmZIndex != null)
			oPanel.style.zIndex = prmZIndex;

		if (MaxHeight > 0) {
			//alert("a");
			oPanel.style.display = "";
			//alert("b");
			
			//document.getElementById(ContentId).style.height = "1";
			//document.getElementById(ContentId).style.display = "none";
			//oPanel.style.height = "1";
			oPanel.style.height = "";
		//	document.getElementById(ContentId).style.display = "";
			document.getElementById(ContentId).style.height = "";
			//alert("c");
		}
		
		/*
		if (bPrmCheckBoundaries) {
			oPanel.style.visibility = "hidden";
			oPanel.style.display = "";
			var x = imod_OffsetLeft(oPanel);
			var y = imod_OffsetTop(oPanel);
			if ((x + oPanel.offsetWidth) > document.body.scrollWidth)
				x -= ((x + oPanel.offsetWidth) - document.body.clientWidth);
				//x -= ((x + oPanel.offsetWidth) - document.body.scrollWidth);
			if (y < document.body.scrollTop)
				y = document.body.scrollTop;
			else if (y + oPanel.offsetHeight > imod_ClientHeight() + document.body.scrollTop)
				y -= (y + oPanel.offsetHeight - imod_ClientHeight() - document.body.scrollTop);
			oPanel.style.left = x;
			oPanel.style.top = y;
			oPanel.style.display = "none";
			oPanel.style.visibility = "visible";
		}
		*/
		oPanel.style.display = "";

		if (MaxHeight == 0)
			ResizeContent();
			
		if (MaxHeight > 0 && oPanel.offsetHeight > MaxHeight) {
			ResizePanel(null, MaxHeight);
	
			/*
			if (bPrmCheckBoundaries) {
				//oPanel.style.visibility = "hidden";
				//oPanel.style.display = "";
				//var x = imod_OffsetLeft(oPanel);
				alert("...");
				var y2 = imod_OffsetTop(oPanel);
				//if ((x + oPanel.offsetWidth) > document.body.scrollWidth)
				//	x -= ((x + oPanel.offsetWidth) - document.body.clientWidth);
					//x -= ((x + oPanel.offsetWidth) - document.body.scrollWidth);
				if (y2 < document.body.scrollTop)
					y2 = document.body.scrollTop;
				else if (y2 + oPanel.offsetHeight > imod_ClientHeight() + document.body.scrollTop)
					y2 -= (y2 + oPanel.offsetHeight - imod_ClientHeight() - document.body.scrollTop);
				//oPanel.style.left = x;
				oPanel.style.top = y2;
				//oPanel.style.display = "none";
				//oPanel.style.visibility = "visible";
			}
			*/

		}
		
		if (bPrmCheckBoundaries) {
			//oPanel.style.visibility = "hidden";
			//oPanel.style.display = "";
			imod.dom.PositionElement(oPanel, imod.dom.OffsetLeft(oPanel), imod.dom.OffsetTop(oPanel));
			/*
						var x = imod_OffsetLeft(oPanel);
			var y = imod_OffsetTop(oPanel);
			if ((x + oPanel.offsetWidth) > document.body.scrollWidth)
				x -= ((x + oPanel.offsetWidth) - imod_ClientWidth());
				//x -= ((x + oPanel.offsetWidth) - document.body.scrollWidth);
			if (y < imod_DocumentScrollTop())
				y = imod_DocumentScrollTop();
			else if (y + oPanel.offsetHeight > imod_ClientHeight() + imod_DocumentScrollTop())
				y -= (y + oPanel.offsetHeight - imod_ClientHeight() - imod_DocumentScrollTop());
			oPanel.style.left = x + "px";
			oPanel.style.top = y + "px";
			*/
			//oPanel.style.display = "none";
			//oPanel.style.visibility = "visible";
		}

		//else
		//	ResizeContent();
		
			
		/*
		
		if (MaxHeight > 0) {
			if (oPanel.offsetHeight > MaxHeight) {
				ResizePanel(null, MaxHeight);
			}	
			else {
				ResizePanel(null, 0);
			}	
		}
		else {
			ResizeContent();
		}
		*/
	}
	
	function Hide() {
		var oPanel = document.getElementById(ClientId);
		oPanel.style.display = "none";
		if (MaxHeight > 0) {
			//document.getElementById(ContentId).style.height = "";
			//ResizePanel(null, 0);
		}
	}
	
	function Drag(e) {
		Dragging = true;
		/*
		if (e.pageX == null) {
			e.pageX = e.clientX + document.body.scrollLeft;
			e.pageY = e.clientY + document.body.scrollTop;
		}
		*/
		var x = e.clientX + imod_DocumentScrollLeft();
		var y = e.clientY + imod_DocumentScrollTop();

		var oPanel = document.getElementById(ClientId);
		//DragOffsetX = imod_OffsetLeft(oPanel) - e.pageX;
		//DragOffsetY = imod_OffsetTop(oPanel) - e.pageY;
		DragOffsetX = oPanel.offsetLeft - x;
		DragOffsetY = oPanel.offsetTop - y;
		return false;

	}
	
	function Drop(e) {
		Dragging = false;
	}
	
	function PreventTextSelect(e) {
		if (Dragging)
			return false;
	}


	function Track(e) {
		if (Dragging) {
			/*
			if (e.pageX == null) {
				e.pageX = e.clientX + document.body.scrollLeft;
				e.pageY = e.clientY + document.body.scrollTop;
			}
			Move(e.pageX + DragOffsetX, e.pageY + DragOffsetY);
			*/
			var x = e.clientX + imod_DocumentScrollLeft();
			var y = e.clientY + imod_DocumentScrollTop();
			Move(x + DragOffsetX, y + DragOffsetY);
		}
	}
		
	function Move(prmX, prmY) {
		var oPanel = document.getElementById(ClientId);
		//var x = prmX;
		//var y = prmY;
		oPanel.style.left = prmX + "px";
		oPanel.style.top = prmY + "px";
	}
	
	function SetPosition(sPrmPosition) {
		Position = sPrmPosition;
		oPanel.style.position = Position;
	}
	
	function Center()
	{
		imod.dom.CenterElement(GetElement());
	}

	function ResizePanel(prmWidth, prmHeight) {
		var oPanel = document.getElementById(ClientId);
		var oContent = document.getElementById(ContentId);

		oContent.style.display = "none";
		if (prmWidth != null) {
			if (prmWidth == 0) {
				oPanel.style.width = "";
				AutoWidth = true;
			}
			else {
				AutoWidth = false;
				oPanel.style.width = prmWidth + "px";
			}
		}
		if (prmHeight != null) {
			if (prmHeight == 0) {
				oPanel.style.height = "";
				AutoHeight = true;
			}
			else {
				oPanel.style.height = prmHeight + "px";
				AutoHeight = false;
			}	
		}
		ResizeContent();
	}

	function ResizeContent() {
		if (IsVisible()) {
			var oPanel = document.getElementById(ClientId);
			var oTitle = document.getElementById(TitleId);
			var oContent = document.getElementById(ContentId);
			var oFooter = document.getElementById(FooterId);

			if (AutoWidth) {
				oContent.style.width = "";
			}
			else {
				oContent.style.width = (oPanel.offsetWidth - 20) + "px";
			}
			if (AutoHeight) {
				oContent.style.height = "";
			}
			else {
				var iHeightOffset = 20;
				if (oTitle != null)
					iHeightOffset += oTitle.offsetHeight;
				iHeightOffset += oFooter.offsetHeight;
				oContent.style.height = (oPanel.offsetHeight - iHeightOffset) + "px";
			}
				oContent.style.display = "";
		}
	}
	
	function SetMaxHeight(iPrmMaxHeight) {
		MaxHeight = iPrmMaxHeight;
	}
}
