function $(id) {
	return document.getElementById(id);	
}

function ajax() {
	try {
		return new XMLHttpRequest();
	}
	catch (e) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				error('Error','Sorry you need to update your browser to use this site');
				return false;
			}
		}
	}
}

function page(filename) {
	pageTracker._trackPageview(filename);
	$('page').innerHTML = '<img src="/images/loading.gif" alt="loading" />';
	$('page').style.display = 'block';
	$('close').style.display = 'block';
	$('flash').style.top = '-1000px';
	$('title').src = makeTitle(filename);
	$('title').style.display = 'block';
	var xmlHttp = ajax();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				$('page').innerHTML = xmlHttp.responseText;
			} else {
				error('Failed to load file','File: <b>'+filename+'</b><br /><br />Error: <b>'+xmlHttp.status+' '+xmlHttp.statusText+'</b></div>');
			}
		}
	}
	xmlHttp.open("GET",filename,true);
	xmlHttp.send(null);
}

function hide() {
	$('page').style.display = 'none';
	$('title').style.display = 'none';
	$('close').style.display = 'none';
	$('page').innerHTML = '';
	$('flash').style.top = '132px';
	
	//var chunk = top.location.href.split('/');
	//top.location.href = chunk[(chunk.length-2)];
}

function makeTitle(string) {
	return string.toLowerCase().replace('.html','').replace(' ','_')+'.png';
}
function makeAnchor(string) {
	var chunk = string.split('/');
	return chunk[(chunk.length-2)]+'/'+chunk[(chunk.length-1)].replace('.html','');
}

function error(title,string) {
	$('page').innerHTML = "<div style='background:#C00;color:#FFF;padding:10px'><b>"+title+"</b><br /><br />"+string+"</div>";	
}

window.onload = function() {
	var preloadDiv = document.createElement('div');
	preloadDiv.setAttribute('id','preload');
	var imgPreload = new Array(
		"menuItemSelected.gif",
		"bannerMenuItemSelected.gif",
		"close.png",
		"contentPanelPage.png",
		"loading.gif"
	);
	for (var i = 0; i < imgPreload.length; i++) {
		var preloadImg = document.createElement('img');
		preloadImg.setAttribute('src','/images/'+imgPreload[i]);
		preloadImg.setAttribute('alt',imgPreload[i]);
		preloadDiv.appendChild(preloadImg);
	}
	document.getElementsByTagName('body')[0].appendChild(preloadDiv);
}
