// Javascript Document
// Description: Insert Navigation
// Author: Travis Cunningham
// Date: October 2008
window.onload = initAll;
var xhr = false;

function initAll(){
	if(document.getElementById('xg_head')){
		showPreview();
	}
}
//Show ajax event
function showPreview(evt){
	//Ajax Request
	
	//Set Include ref
	var url = "/includes/navigation.php"
	
	if(window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	}
	else {
		if(window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) { }
		}
	}
	if (xhr) {
		xhr.onreadystatechange = showContents;
		xhr.open("GET", url, true);
		xhr.send(null);
	}
	else {
		alert("Sorry But I could not create an XMLHttpRequest");
	}
}
function showContents() {
	if (xhr.readyState == 4){
		if(xhr.status == 200) {
			var outMsg = xhr.responseText;
		}
		else {
			var outMsg = "There was something wrong with your request " + xhr.status;
		}
		
		//Do something with outMsg
		var head = document.getElementById('xg_head');
		var masthead = document.getElementById('xg_masthead');
		var content = document.createElement('div');
		content.setAttribute('id','mainNavCont');
		content.innerHTML = outMsg;
		insertAfter(head,content,masthead);
	}
}
function insertAfter(parent, node, referenceNode) {
  parent.insertBefore(node, referenceNode.nextSibling);
}

