/**
 * JSHistory
 * This object manages a kind of 'history'
 */

/* ---------------------- Constructor ----------------------*/
function JSHistory(id, trg)
{
	// setup attributes
	this.historyContainer = new Array();
	this.id = id || 'siteContent_frame';
	this.target = trg || this;
}

/**
* Return the history container
*/
JSHistory.prototype.getHistory = function()
{
	return this.historyContainer;
}

/**
 * Add an element to the history
 */ 
JSHistory.prototype.addElement = function(url)
{
	//alert('JSHistory addElement called ... url: ' + url);
	
	if(url)
	{
	//	var urlParts = url.split('/');
	//	var rel_url = urlParts.pop();
		
		//alert('JSHistory addElement called ... rel_url: ' + rel_url);
		
	//	this.historyContainer.push(rel_url);
		
	//	alert("JSHistory ... addElement ... url: " + url);
		
		this.historyContainer.push(url);
	}
}

/**
 * Go back one step
 */ 
JSHistory.prototype.goBack = function(id)
{
	//alert("JSHistory goBack ... historyContainer: " + this.historyContainer);
	
	if (this.historyContainer.length > 1)
	{
		
		//alert("JSHistory ... goBack ... popped: " + this.historyContainer.pop());
		this.historyContainer.pop();
		var trg = this.historyContainer.pop();
		
		//alert("JSHistory ... goBack ... trg: " + trg);
		
		this.target.setURLToTarget(id, trg);
	}
}
/**
 * Set URL to a target
 */ 
JSHistory.prototype.setURLToTarget = function(id, url)
{
	//alert("JSHistory setURLToTarget ... this: " + this + " --- id: " + id + " --- url: " + url);
	
	if (url)
	{
		this.setID(id);
		
		//alert("JSHistory goBack ... this.id: " + this.id);
		
		var elem = document.getElementById(this.id);
		
		//alert("JSHistory goBack ... elem: " + elem);
		
		elem.src = url;
	}
}

/**
 * Set an ID
 */ 
JSHistory.prototype.setID = function(id)
{
	//alert("JSHistory setID ... id: " + id);
	
	if (id)
	{
		this.id = id;
	}
}
/**
 * Get target
 */ 
JSHistory.prototype.getID = function()
{
	//alert("JSHistory getID ... ");
	
	return this.id;
}

/**
 * Set a target
 */ 
JSHistory.prototype.setTarget = function(trg)
{
	//alert("JSHistory setTarget ... trg: " + trg);
	
	if (trg)
	{
		this.target = trg;
	}
}
/**
 * Get target
 */ 
JSHistory.prototype.getTarget = function()
{
	//alert("JSHistory getTarget ... ");
	
	return this.target;
}

/**
 * Get an iFrame
 */ 
JSHistory.prototype.getIFrameDocument = function(iframeID)
{
	//alert("JSHistory getIFrameDocument ... ");
	
	if (iframeID)
	{
		var iframe = document.getElementById(iframeID);
		return iframe.contentWindow.document;
	}
	else
	{
		return null;
	}
}


var jshistory = new JSHistory();
