

function init() {
document.getElementById('mainContent').style.opacity = "1"; getLinks(); getFooter();}

window.onload = init;
		var currentLocation;
		var currentLocationRep;
		var locationArray;
		var recieved;
		var links = [];
		var subLinks = [];

function focusButton(location)
{	
	currentLocationRep = location;
	getData("");
	getSubLinks(location);

	for(i = 0; i < links.length; i++)
	document.getElementById('button-'+links[i]).setAttribute('class','links');
	document.getElementById('button-'+location).setAttribute('class','links selectedLinks');

}


function focusSubButton(location)
{
	getData(location);

	for(i = 0; i < subLinks.length; i++)
	document.getElementById('subButton-'+subLinks[i]).setAttribute('class','links linksub');
	document.getElementById('subButton-'+location).setAttribute('class','links linksub selectedLinks');

}

////////////////////////////////////////
function getData(url)
{

	if(url != "")
	url = 'data/'+currentLocationRep.toLowerCase()+'_'+url.toLowerCase();
	else
	url = 'data/'+currentLocationRep.toLowerCase();

	if(url.indexOf(" ") != -1)
	url = url.substring(0, url.indexOf(" "));

	url += '.txt';

	currentLocation = url;


//currentLocationRep = url;

//animateHeading0();
var http = new XMLHttpRequest();

http.open("GET", url, true);

http.setRequestHeader('Cache-Control', 'no-cache');
http.setRequestHeader('Pragma', 'no-cache');


http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {



		 recieved =  http.responseText;

if(document.getElementById('twitterDiv'))
document.getElementById('twitterDiv').style.display = 'none';

	if(url=='data/home.txt')
{
document.getElementById('twitterDiv').style.display = 'block';


}

var s=setTimeout('document.getElementById(\'mainContent\').innerHTML = recieved;',300); 
		}

	else  if(http.readyState == 4 && http.status == 404) {document.getElementById('mainContent').innerHTML = "~";}

	}
	http.send();	
}
/////////////////////////////////////

function getLinks()
{
	var url = 'data/menu/main.txt';
	var http = new XMLHttpRequest();

http.open("GET", url, true);


http.setRequestHeader('Cache-Control', 'no-cache');
http.setRequestHeader('Pragma', 'no-cache');

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {

		document.getElementById('mainMenuLinks').innerHTML = "";
		var data;
		 data =  http.responseText;
		locationArray = data;
		data = data.split('\n');
		//for(i = 0; i < data.length; i++)
		//d//ata[i] = data[i].split('\n');
		//getData(data[0][2]); Get main link sub links
	
		for(i = 0; i < data.length; i++)
		{
			var link = document.createElement('a');
			link.setAttribute('class','links linksub');
			link.setAttribute('id','button-'+data[i]);
			link.setAttribute('style','display:inline; padding-right:15px;padding-left:15px;');
			link.setAttribute('onclick',"focusButton('"+data[i]+"');");
			
			link.innerHTML = data[i];
			links.push(data[i]);
//<div align='center'  style='display:inline; padding-right:15px; padding-left:15px;'><a  class='$class' href=\"?location=
			document.getElementById('mainMenuLinks').appendChild(link);
			//document.getElementById('linkContainer').innerHTML += " </br>";
		//alert(data[i][1]);

		}
	focusButton(data[0])
//var s=setTimeout('document.getElementById(\'mainContent\').innerHTML = recieved; animateHeading1();',300); 
	}	

	}
	http.send();	



}


function getSubLinks(url)
{

subLinks = [];
	url = 'data/menu/'+url.toLowerCase()+'_menu.txt';
	//var url = 'data/menu/main.txt';
	var http = new XMLHttpRequest();

http.open("GET", url, true);


http.setRequestHeader('Cache-Control', 'no-cache');
http.setRequestHeader('Pragma', 'no-cache');

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {

		document.getElementById('subMenuLinks').innerHTML = "";
		var data;
		 data =  http.responseText;
		locationArray = data;
		data = data.split('\n');
		//for(i = 0; i < data.length; i++)
		//d//ata[i] = data[i].split('\n');
		//getData(data[0][2]); Get main link sub links
	
		for(i = 0; i < data.length; i++)
		{
			var link = document.createElement('a');
			link.setAttribute('class','links linksub');
			link.setAttribute('id','subButton-'+data[i]);
			link.setAttribute('style','display:inline; padding-right:15px;padding-left:15px;');
			link.setAttribute('onclick',"focusSubButton('"+data[i]+"');");
			
			link.innerHTML = data[i];
			subLinks.push(data[i]);
//<div align='center'  style='display:inline; padding-right:15px; padding-left:15px;'><a  class='$class' href=\"?location=
			document.getElementById('subMenuLinks').appendChild(link);
			//document.getElementById('linkContainer').innerHTML += " </br>";
		//alert(data[i][1]);

		}
//focusSubButton(data[0]);
	//focusButton(data[0])
//var s=setTimeout('document.getElementById(\'mainContent\').innerHTML = recieved; animateHeading1();',300); 
	}	

	}
	http.send();	



}

function animateHeading0()
{
document.getElementById('content').style.opacity = '0';
}

function animateHeading1()
{
document.getElementById('content').style.opacity = '1';
}


function getFooter()
{



//currentLocationRep = url;

//animateHeading0();
var http = new XMLHttpRequest();

http.open("GET", "data/other/footer.txt", false);


http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {

		 document.getElementById('footerContent').innerHTML  =  http.responseText;


//var s=setTimeout('document.getElementById(\'footerContent\').innerHTML = recieved;',300); 
		}

	}
	http.send();	
}

