try 
{
document.execCommand("BackgroundImageCache", false, true);
} 
catch(err) {}

// set random header image
var NUMBER_OF_HEADER_IMAGES = 7;

// create class to load random header image
var strCss =	'#logo {' +
					'width: 778px;' +
					'height: 483px;' +
					'margin: 0 auto;' +
					'background: url(/images/header_' + rnd(NUMBER_OF_HEADER_IMAGES) + '.jpg) no-repeat left top;' +
					'text-align: right;' +
					'background-color: #000;' +
				'}';

// preload random image
image1 = new Image();
image1.src = "/images/header_" + rnd(NUMBER_OF_HEADER_IMAGES) + ".jpg";

// add css class to page directly before page finished loading
// this is intended to reduce flicker for random imagery
document.write('<style type="text/css">' + strCss + '</style>');


window.onload=function()
{
	

	// load random header image (disabled as it causes flickr due to being fires once page has loaded)
	//swapPic();

	// enable menu highlighting for current section
	setPageNavHighlight();
}


/*
// set random header image
function swapPic()
{
	if(document.getElementById)
	{
		var thePicture=document.getElementById("logo");
		var picPath="/images/header_" + rnd(4) + ".jpg";
		thePicture.style.background="url(" + picPath + ")";
	}
}
*/

	 
// return a random number within the supplied boundries
function rnd(n)
{
	return Math.floor(Math.random() * n) + 1;
}


// return string containing current page name
function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length < 2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}


// highlight page in navigation menu
function setPageNavHighlight()
{
	hrefString = document.location.href ? document.location.href : document.location;
 
	if (document.getElementById("menu") !=null )
	var blnFoundMenuItem = setActiveMenu(document.getElementById("menu").getElementsByTagName("a"), extractPageName(hrefString));
	
	if (!blnFoundMenuItem)
	{
		if (document.getElementById("sidebar2") !=null )
		blnFoundMenuItem = setActiveMenu(document.getElementById("sidebar2").getElementsByTagName("a"), extractPageName(hrefString));
	}	
}


// add contains method to string object (easier to use in setActiveMenu)
String.prototype.contains = function(it) { return this.indexOf(it) != -1; }


// highlight page in navigation menu
function setActiveMenu(arr, crtPage)
{
	for (var i=0; i < arr.length; i++)
	{
		// if the url does not contain a page then ensure the index link is selected
		if (!crtPage.contains("shtm") && extractPageName(arr[i].href).contains("index.shtml"))
		{
			arr[i].className = "selected";
			arr[i].parentNode.className = "selected";
			return true;
		}
		// if the url contains forsale and the page also contains forsale
		else if (crtPage.contains("forsale") && arr[i].href.contains("forsale"))
		{			
			arr[i].className = "selected";
			arr[i].parentNode.className = "selected";
			return true;			
		}
		else		
		{
			if(crtPage.contains(extractPageName(arr[i].href)))
			{
				if (arr[i].parentNode.tagName != "div")
				{
					arr[i].className = "selected";
					arr[i].parentNode.className = "selected";
					return true;
				}
			}
		}
	}

	return false;
}
 
