//
//	PANEL
//

var mDefaultBgndColor = "#ddddee";		//ddddee	cccccc	


//---------------------------------------------------------
function Panel(panelID, top, left, height, width, thick, type, color, backColor, parentElem)
	{
	this.panelID = panelID;
	this.bkColor = backColor;	
	this.borderThick = thick;
	this.borderType = type;
	this.borderColor = color;
	this.SetBounds(top, left, height, width);
	this.objects = new Array();
	this.loaded = new Array();
	this.objCount = 0;
	this.isDraggable = false;
	this.bkImg = "";	//this.GetBkgndPath(16);
	this.parentElem = parentElem;
	this.hasTitleBar = true;
	this.Build();
	}
//-----------------------------------------------------
function DoNothingWithElem(elem) 
	{	
	}

//-----------------------------------------------------
Panel.prototype.SetBounds = function(top, left, height, width)
	{
	this.top = top;
	this.left = left;
	this.height = height;
	this.width = width;
	}
//-----------------------------------------------------
Panel.prototype.SetBkgndImage = function(imgPath)
	{
	this.div.style.background='url('+imgPath+')';
	}
	
//-----------------------------------------------------
Panel.prototype.GetTotatlObjects = function()
	{	
	return this.objects.length;
	}
//-----------------------------------------------------
Panel.prototype.GetObject = function(idx)
	{	
	return this.objects[idx];
	}
//-----------------------------------------------------
Panel.prototype.IsObjectLoaded = function(idx)
	{	
	return this.loaded[idx];
	}
//-----------------------------------------------------
Panel.prototype.SetObjectIsLoaded = function(idx, loaded)
	{	
	this.loaded[idx] = loaded;
	}
//-----------------------------------------------------
Panel.prototype.IsFullyLoaded = function()
	{	
	for (var idx = 0; idx < this.objects.length; ++idx)
		{
		if (!this.loaded[idx]) {
			return false;
		}
		}
	return true;
	}
//-----------------------------------------------------
Panel.prototype.SetHasTitleBar = function(hasTitleBar)
	{	
	this.hasTitleBar = hasTitleBar;
	}

//-----------------------------------------------------
function SetBackgndColor(color) 
	{	
	this.bkColor = color;
	}
//-----------------------------------------------------
Panel.prototype.SetIsDraggable = function(trueOrfalse) 
	{	
	this.isDraggable = trueOrfalse;
	}
//-----------------------------------------------------
Panel.prototype.SetDfltBackgndColor = function(color) 
	{	
	this.bkColor = mDefaultBgndColor;
	}

//-----------------------------------------------------
Panel.prototype.SetBackImage = function(path)
	{
	this.bkImg = path;
	dStyle.backgroundImage = url(this.bkImg);
	}
//-----------------------------------------------------
Panel.prototype.GetBkgndPath = function(idx)
	{
	switch(idx)
		{
		case 1: return "images_ui/backgrounds/marble_59.jpg";
		case 2: return "images_ui/backgrounds/marble_60.jpg";
		case 3: return "images_ui/backgrounds/marble_63.jpg";
		case 4: return "images_ui/backgrounds/marble_66.gif";
		case 5: return "images_ui/backgrounds/marble_91.jpg";
		case 6: return "images_ui/backgrounds/marble_110.gif";
		case 7: return "images_ui/backgrounds/marble_111.gif";
		case 8: return "images_ui/backgrounds/marble_119.gif";
		case 9: return "images_ui/backgrounds/marble_122.gif";
		case 10: return "images_ui/backgrounds/marble_158.jpg";
		case 11: return "images_ui/backgrounds/marble_257.jpg";
		case 12: return "images_ui/backgrounds/marble_265.gif";
		case 13: return "images_ui/backgrounds/surfaces_7.gif";
		case 14: return "images_ui/backgrounds/wood_192.jpg";
		case 15: return "images_ui/backgrounds/cdbk006a.jpg";
		case 16: return "images_ui/backgrounds/bluefab.jpg";
		case 17: return "images_ui/backgrounds/grayveins.jpg";
		}	
	}
//-----------------------------------------------------
Panel.prototype.Build = function()
	{
	var parentElem;
	if (this.parentElem == null) parentElem = document.getElementsByTagName("body")[0];
	else parentElem = this.parentElem;
	div = document.createElement("div");	
	div.className = "panel";
	div.id = this.panelID + "_div";
	var borderInfo = this.borderColor+" "+this.borderThick+" "+this.borderType;
	var dStyle = div.style;
//	dStyle.display = "none";
	dStyle.position = "absolute";
	dStyle.zIndex = 100;
	dStyle.top = this.top;
	dStyle.left = this.left;
	dStyle.width = this.width;
	dStyle.height = this.height;
	dStyle.borderTop = borderInfo;
	dStyle.borderLeft = borderInfo;
	dStyle.borderBottom = borderInfo;
	dStyle.borderRight = borderInfo;
	dStyle.backgroundColor = this.bkColor;
	dStyle.overflow = "hidden"; 
	parentElem.appendChild(div);
	this.div = document.getElementById(div.id);
	this.div.obj = this;
	}
//-----------------------------------------------------
Panel.prototype.AddObject = function(objID, objType, top, left, height, width, text, val, name)
	{
	if (text == undefined) text = "";
	if (val == undefined) val = "";
	if (name == undefined) name = "";
	var obj = new PanelObject(objID, objType, top, left, height, width, text, this, val, name);
	obj.panel = this;
	this.objects[this.objCount] = obj;
	this.loaded[this.objCount] = false;
	++this.objCount;
	return obj;
	}

//-----------------------------------------------------
Panel.prototype.SetElementObjectMembers = function()
	{
	for (var cnt = 0; cnt < this.objCount; cnt++)
		{
		var obj = this.objects[cnt];
		var elem = document.getElementById(obj.objID);
		if (elem != null) elem.obj = obj;
		else 
			{
			elem = document.getElementById(obj.objID + "_frame");
			if (elem != null) 
				elem.obj = obj;
			else {
				elem = document.getElementById(obj.objID + "_div");
				if (elem != null) 
					elem.obj = obj;
			}
			}
		obj.elem = elem;
		}
	}
//-----------------------------------------------------
Panel.prototype.GetHTML = function()
	{
	var s = "";
	var html;
	
	for (var cnt = 0; cnt < this.objCount; cnt++)
		{
		html = this.objects[cnt].GetHTML();
		s = s + html;
		}

	return s;
	}

//-----------------------------------------------------
Panel.prototype.BuildObjects = function()
	{
	var s = "";
	var html;
	
	for (var cnt = 0; cnt < this.objCount; cnt++)
		{
		html = this.objects[cnt].GetHTML();
		s = s + html;
		}

	this.div.innerHTML = s;
	this.SetElementObjectMembers();
	}

//-----------------------------------------------------
Panel.prototype.Show = function()
	{
	this.BuildObjects();
	this.div.style.display = "inline";
	}
//-----------------------------------------------------
Panel.prototype.MoveTop = function(top)
	{
	this.top = top;
	this.div.style.top = top;
	}
