//drjs.ui.floatbox.js - Dependencies: ui
//FloatBox

var FloatBox = Class.Create();
FloatBox.AddMethods({
	Box: null,
	BoxContent: null,
	Id: null,
	Style: null,
	PosX: null,
	PosY: null,
	_constructor: function() {
	},
	Center: function() {
		var posx = ((window.document.body.offsetWidth/2)-this.Box.offsetWidth/2);
		var posy = (((window.document.body.offsetHeight/2)-this.Box.offsetHeight/2) + window.document.body.scrollTop) - 10;
		this.Box.style.top = posy;
		this.Box.style.left = posx;
		this.PosX = posx;
		this.PosY = posy;
	},
	Close: function() {
		FloatBoxFunctions.ExecOnClose(this);
		FloatBoxFunctions.RemoveBox(this.Id);
		UI.Document.RemoveFromBody(this.Id);
	},
	Create: function(id, style, width, height, posX, posY) {
		if($(id)!=false) {
			UI.Document.RemoveFromBody(id);
		}
		this.Id = id;
		this.Style = style;
		style = (style==null) ? "" : style;
		this.Box = UI.Document.AddToBody("div", id);
		this.Box.style.position = "absolute";
		this.Box.style.display = "none";
		this.Box.style.border = "5px solid #FF0000";
		this.Box.className = style+"_box";
		if(width!=null) {
			this.Box.style.width = width;
		}
		if(height!=null) {
			this.Box.style.height = height;
		}
		if(posX!=null) {
			this.Box.style.left = posX;
		}
		if(posY!=null) {
			this.Box.style.top = posY;
		}
		this.Box.innerHTML = "<div id=\""+id+"_content\" class=\""+style+"_content\"></div>";
		this.BoxContent = $(id+"_content");
		FloatBoxFunctions.AddBox(id, this);
	},
	DropShadow: function(border, color) {
		border = (border==null) ? "3" : color;
		color = (color==null) ? "#DDDDDD" : color;		
		this.Box.style.height = this.Box.offsetHeight;
		this.Box.style.width = this.Box.offsetWidth;
		this.Box.style.borderRight = border + "px solid "+color;
		this.Box.style.borderBottom = border + "px solid "+color;
	},
	Hide: function() {
		this.Box.style.display = "none";
		FloatBoxFunctions.ExecOnClose(this);
	},
	Move: function(posX, posY) {
		if(posX!=null) {
			this.Box.style.left = posX;
		}
		if(posY!=null) {
			this.Box.style.top = posY;
		}
	},
	MoveToFront: function() {
		this.Box.style.zIndex = UI.GetZIndex();
	},
	Resize: function(width, height) {
		if(width!=null) {
			this.Box.style.width = width;
		}
		if(height!=null) {
			this.Box.style.height = height;
		}
	},
	Show: function() {
		FloatBoxFunctions.ExecOnOpen(this);
		this.Box.style.display = "";
		this.Box.style.zIndex = UI.GetZIndex();
	},
	SetContent: function(text) {
		this.BoxContent.innerHTML = text;
	}
});

var FloatBoxFunctions = {
	currentBoxes: [],
	OnOpen: null,
	OnClose: null,
	AddBox: function(id, obj) {
		this.currentBoxes[id] = obj;
	},
	GetBox: function(id) {
		return this.currentBoxes[id];
	},
	ExecOnClose: function(obj) {
		if(this.OnClose!=null) {
			this.OnClose();
		}
	},
	ExecOnOpen: function(obj) {
		if(this.OnOpen!=null) {
			this.OnOpen();
		}
	},
	RemoveBox: function(id) {
		this.currentBoxes[id] = null;
	}
};

drjs.loadComplete(drjs.files.uiFloatBox);
