//*******************************************************************
// Kappa Solutions Sidebar Display (Image) Manager 
//						JavaScript Class Def. & Variable Declaration.
//	
//			// (c) 2007-2008 Kappa Solutions Ltd.
//*******************************************************************

// Constructor ******************************************************
function DisplayMgr() {
	
	this._sidebarTemplate = "<div id=\"sidebar1\" style=\"background-image: url(%s01);\" title=\"%s02\"></div>";
	
	this._sidebarImages = [
		{url: "res/sidebg06.gif", title: "Spitfire over Lancing College"}
		,{url: "res/sidebg01.gif", title: "Chichester Cross"}
		,{url: "res/sidebg07.gif", title: "Brighton Pavilion"}
		,{url: "res/sidebg08.gif", title: "Worthing Pier"}
	];
	
		// Cache images
	if (document.images)
	{
		this._pics=[];
		for (var i =0; i<this._sidebarImages.length; i++)
	  	{
			this._pics[i] = new Image(); 
			this._pics[i].src = this._sidebarImages[i].url;
		}
	}

}

// Get Rand *********************************************************
DisplayMgr.prototype._rand = function(maxVal) 
{
	var r = Math.floor(maxVal*(Math.min(Math.random(), .9999)));
	return r;
}
// Get Image ********************************************************
DisplayMgr.prototype.getSidebar = function() {
	// Return the HTML for the sidebar DIV
	var newImage = this._sidebarImages[this._rand(this._sidebarImages.length)]
	var t = this._sidebarTemplate;
	t=t.replace(/%s01/g, new String(newImage.url));
	t=t.replace(/%s02/g, new String(newImage.title));
	
	return t;
}

DisplayMgr.prototype.resetSidebar = function() 
{
	// Reset sidebar background
	var e = document.getElementById("sidebar1");
	if (e)
	{
		var newImage = this._sidebarImages[this._rand(this._sidebarImages.length)]
		alert(newImage.url + " / " + newImage.title);
		e.style.backgroundImage = newImage.url;
		alert(e.id);
		//e.title = newImage.title;
	}
}

// Declaration ******************************************************
// Create menu manager...
var displayMgr = new DisplayMgr();

//*******************************************************************
