/**
 * Object Panel
 *
 * License:
 * Coalmarch Productions, LLC
 * All rights to source code and implementation files reserved.
 * http://www.coalmarch.com | info@coalmarch.com
 * (919) 481-2895
 *
 */
Panel.prototype = new PageObject(document);
Panel.prototype.constructor = Panel;
Panel.prototype.baseClass = PageObject.prototype.constructor;
var panelObjRegistration = new Array();

/**
 * Panel CSS view mode controls
 */
Panel.prototype.setViewMode = function( viewMode )
{
	//alert("Setting view mode for "+this.srcElement.id+" to "+viewMode);
	this.lastViewMode = this.srcElement.className;
	this.srcElement.className = viewMode;
	if(typeof(this.saveViewmode) != "undefined" && this.saveViewmode != false)
	{
		Set_Cookie(this.saveViewmode,viewMode,10,'/','','');
	}
}
Panel.prototype.undoSetViewMode = function()
{
	tmpLastMode = this.lastViewMode;
	this.lastViewMode = this.srcElement.className;
	this.srcElement.className = tmpLastMode;
}
/**
 * Panel Rotating CSS view mode controls
 */
Panel.prototype.setViewModes = function ( viewModesString )
{
	this.viewModes = viewModesString.split(",");
	if (this.viewModeLoop > this.viewModes.length-1) this.lastViewMode = 0;
	//alert("View modes set for "+this.srcElement.id+" to "+this.viewModes);
}
Panel.prototype.toggleViewMode = function ()
{
	//alert(this);
	//alert(this.id);
	//alert("this.viewModeLoop > this.viewModes.length-1\nCurrent Loop "+this.viewModeLoop+" of total "+(this.viewModes.length-1)+" loops.");
	if (this.viewModeLoop == this.viewModes.length-1)
	{
		//alert("Setting viewModeLoop to 0 because this.viewModeLoop("+this.viewModeLoop+") is equal to this.viewModes.length-1("+(this.viewModes.length-1)+")");
		this.viewModeLoop = 0;
	}
	else
	{
		//alert("Setting viewModeLoop to ("+(this.viewModeLoop+1)+") because this.viewModeLoop("+this.viewModeLoop+") is NOT greater than this.viewModes.length-1("+(this.viewModes.length-1)+")");
		this.viewModeLoop += 1;
	}
	//alert("Toggling view mode for "+this.srcElement.id+" from "+this.viewModeLoop+" "+this.viewModes[this.viewModeLoop]+" to "+this.viewModes[this.viewModeLoop+1]);
	this.setViewMode(this.viewModes[this.viewModeLoop]);
}

/**
 * Content controls
 */
Panel.prototype.addContent = function ( newContent )
{
	if ((typeof(newContent.isA) != "undefined") && (newContent.isA("Panel")))
	{
		var contentName = newContent.srcElement.id;
		this.contents[contentName] = newContent;
	}
}
Panel.prototype.removeContent = function ( oldContent )
{
	if ((typeof(oldContent.isA) != "undefined") && (oldContent.isA("Panel")))
	{
		var contentName = oldContent.srcElement.id;
		if (typeof(this.contents[contentName]) != "undefined")
		{
			this.contents[contentName] = null;
			delete this.contents[contentName];
		}
	}
}
Panel.prototype.hideContent = function()
{
	for (content in this.contents)
	{
		var contentObj = this.contents[content];
		if ((typeof(contentObj.isA) != "undefined") && (contentObj.isA("Panel")))
		{
			contentObj.hide();
		}
	}
}
Panel.prototype.showContent = function()
{
	for (content in this.contents)
	{
		var contentObj = this.contents[content];
		if ((typeof(contentObj.isA) != "undefined") && (contentObj.isA("Panel")))
		{
			contentObj.show();
		}
	}
}
Panel.prototype.toggleContent = function()
{
	var visibility = false;
	for (content in this.contents)
	{
		var contentObj = this.contents[content];
		if ((typeof(contentObj.isA) != "undefined") && (contentObj.isA("Panel")) && (contentObj.srcElement.style.display != "none"))
		{
			visibility = true;
			break;
		}
	}
	visibility ? this.hideContent() : this.showContent();
	this.contentVisibility = !visibility;
}
Panel.prototype.setSaveViewmode = function( cookieName )
{
	this.saveViewmode = cookieName;
	var viewMode = Get_Cookie(cookieName);
	if(viewMode != '' && viewMode != this.srcElement.className)
	{
		this.setViewMode(viewMode);
		var modeNumber = 0;
		var i;
		for (i = 0; i < this.viewModes.length; i++)
		{
			if(this.viewModes[i] == viewMode)
			{
				modeNumber = i;
			}
		}
		this.viewModeLoop = modeNumber;
	}
}
function Panel( src, initialViewMode )
{	
	this.srcElement = src;
	this.dataType += " Panel";
	this.lastViewMode = "";
	this.viewModes = new Array();
	this.viewModeLoop = 0;
	this.saveViewmode = false;
	this.setViewMode(initialViewMode);
	this.contentVisibility = true;
	this.contents = {};
}

function getPanelByName( name )
{
	return panelObjRegistration[name];
}