var myimages=new Array()
function preloadImages() {
	for (i=0;i<preloadImages.arguments.length;i++) {
		myimages[i]=new Image()
		myimages[i].src=preloadImages.arguments[i]
	}
}

preloadImages("./images/loading.png", "./images/triangle.png")



function ajaxNavFunction(page, where, stuff) {
	if (where=="shortcal_content") {
		document.getElementById(where).innerHTML = 'Loading...';
	} else {
		document.getElementById(where).innerHTML = '<img src="./images/loading.png" alt="Loading" />';
	}
	var xmlHttp;
	try {
    	// Firefox, Opera, Safari, anything else that's not dumb
    	xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
    	// Internet Sucksplorer
    	try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Please update your browser.");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById(where).innerHTML = xmlHttp.responseText;
		}
	}
	var goto = "./pages/"+page+".php"+stuff;
	xmlHttp.open("GET", goto, true);
	xmlHttp.send(null);
}
	
	

function resetNav () {
	var home = document.getElementById("home");
	var bands = document.getElementById("bands");
	var calendar = document.getElementById("calendar");
	var boosters = document.getElementById("boosters");
	var media = document.getElementById("media");
	var more = document.getElementById("more");
	var traditions = document.getElementById("traditions");
	home.className = "nav";
	bands.className = "nav";
	calendar.className = "nav";
	boosters.className = "nav";
	media.className = "nav";
	more.className = "nav";
	traditions.className = "nav";
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600');");
}

function shortCal (howmany) {
	ajaxNavFunction("shortcal", "shortcal_content", '?n='+howmany);
}

function miscLinks (what) {
	resetNav();
	document.getElementById("more").className = "nav_current";
	ajaxNavFunction(what, "content", '');
}

function navClick (what) {
	if (what == "charms") {
		window.open("https://www.charmsoffice.com/");
	} else {
		resetNav();
		var cur = document.getElementById(what);
		cur.className = "nav_current";
		ajaxNavFunction(what, "content", '');
	}
}

function bandClick (what) {
	resetNav();
	document.getElementById("bands").className = "nav_current";
	ajaxNavFunction(what, "content", '');
}

function mediaClick (what) {
	resetNav();
	document.getElementById("media").className = "nav_current";
	ajaxNavFunction(what, "content", '');
}

function calClick (what) {
	resetNav();
	document.getElementById("calendar").className = "nav_current";
	ajaxNavFunction(what, "content", '');
}



function moduleClick (what) {
	var head = what+"_head";
	var body = what+"_body";
	var module = what;
	if (document.getElementById(body).style.display == "block") {
		document.getElementById(head).style.backgroundImage = "url('./images/triangle_rotated.png')";
		document.getElementById(body).style.display = "none";
		document.getElementById(module).style.borderBottom = "none";
	} else {
		document.getElementById(head).style.backgroundImage = "url('./images/triangle.png')";
		document.getElementById(body).style.display = "block";
		document.getElementById(module).style.borderBottom = "1px solid #cccccc";
	}
}



function expandAll () {
	
	var head = "contact_head";
	var body = "contact_body";
	var module = "contact";
	
	document.getElementById(head).style.backgroundImage = "url('./images/triangle.png')";
	document.getElementById(body).style.display = "block";
	document.getElementById(module).style.borderBottom = "1px solid #cccccc";
	
	var head2 = "site_statistics_head";
	var body2 = "site_statistics_body";
	var module2 = "site_statistics";
	
	document.getElementById(head2).style.backgroundImage = "url('./images/triangle.png')";
	document.getElementById(body2).style.display = "block";
	document.getElementById(module2).style.borderBottom = "1px solid #cccccc";
	
	var head3 = "shortcal_head";
	var body3 = "shortcal_body";
	var module3 = "shortcal";
	
	document.getElementById(head3).style.backgroundImage = "url('./images/triangle.png')";
	document.getElementById(body3).style.display = "block";
	document.getElementById(module3).style.borderBottom = "1px solid #cccccc";
	
}



function contractAll () {
	
	var head = "contact_head";
	var body = "contact_body";
	var module = "contact";
	
	document.getElementById(head).style.backgroundImage = "url('./images/triangle_rotated.png')";
	document.getElementById(body).style.display = "none";
	document.getElementById(module).style.borderBottom = "none";
		
	var head2 = "site_statistics_head";
	var body2 = "site_statistics_body";
	var module2 = "site_statistics";
	
	document.getElementById(head2).style.backgroundImage = "url('./images/triangle_rotated.png')";
	document.getElementById(body2).style.display = "none";
	document.getElementById(module2).style.borderBottom = "none";
	
	var head3 = "shortcal_head";
	var body3 = "shortcal_body";
	var module3 = "shortcal";
	
	document.getElementById(head3).style.backgroundImage = "url('./images/triangle_rotated.png')";
	document.getElementById(body3).style.display = "none";
	document.getElementById(module3).style.borderBottom = "none";
	
}

function initialize () {
	navClick('home');
	shortCal(5);
	document.getElementById('shortcal_head').style.backgroundImage = "url('./images/triangle.png')";
	document.getElementById('shortcal_body').style.display = "block";
	document.getElementById('shortcal').style.borderBottom = "1px solid #cccccc";
}