// Constant for windowResize
var pageDiv = 'page';

// Constants for content/ajax calls
var contentTitle = 'contentTitle';
var contentFrame = 'contentFrame';

function changeTitle(page) {
	var image = document.getElementById(contentTitle);
	image.innerHTML = '<img src="../media/images/' + page + '.jpg" alt="' + page + '" />';
}

function changeContent(page) {
	if (page != '') {
		try {
			// Mozilla supports XMLHttpRequest. IE uses ActiveX.
			xmlHTTP = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
		} catch (error) {
			// Browser doesn't support ajax.
		}
	
		// The xmlHTTP object triggers an event everytime the status changes
		xmlHTTP.onreadystatechange = contentUpdate;
	
		// Change the title to match the new page
		changeTitle(page);
	
		// open function takes the HTTP method and url.
		xmlHTTP.open('GET', '../allie/content/' + page + '.txt');
	
		// Send the request, for POST: send("name=aleem&gender=male")
		// Mozilla is fine with just send(); but IE expects a value here, hence we do send(null);
		xmlHTTP.send(null);
	}
}

function contentUpdate() {
	// If the readyState code is 4 (Completed)
	// and http status is 200 (OK) we go ahead and process the responseText
	// Other readyState codes: 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
	if ((xmlHTTP.readyState == 4) && (xmlHTTP.status == 200)) {
		// xmlHTTP.responseText object contains the response.
		document.getElementById(contentFrame).innerHTML = xmlHTTP.responseText;
	}
}

// Functions needed by dhtmlHistory.js
function initialize() {
	// Initialize our DHTML history
	dhtmlHistory.initialize();

	// Subscribe to DHTML history change events
	dhtmlHistory.addListener(historyChange);
      
	// First time we have loaded the page...
	// !!! Need to check to see if page is supplied
	if (dhtmlHistory.isFirstLoad()) {
		changeContent('news');
		dhtmlHistory.add('news');
	}
	
	windowResize();
	window.onresize = windowResize;
}
   
// Our callback to receive history change events.
function historyChange(page) {
	changeContent(page);
}

