// March 10, 2007
// Daniel M. Flax
// Written for www.flax.org
// based on teachings from Lee Babin "Beginning Ajax with PHP"

	//Create a boolean variable to check for a valid IE instance.
	var xmlhttp = false;
	
	//Check if we are using IE.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	
	//If we are using a non-IE browser, create a JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	function changeImage() {

		homeImageArray = new MakeArray(8);

		homeImageArray[1] = "homeImage1";
		homeImageArray[2] = "homeImage2";
		homeImageArray[3] = "homeImage3";
		homeImageArray[4] = "homeImage4";
		homeImageArray[5] = "homeImage6";
		homeImageArray[6] = "homeImage7";
		homeImageArray[7] = "homeImage8";
		homeImageArray[8] = "homeImage9";

		// Get the object from the page
		var objID = homeImageArray[Math.floor(Math.random()*10)];
		var obj = document.getElementById(objID);

		// Set the Loading Image
		obj.innerHTML = '<img class="homeLoading" alt="loading..." src="images/loadingAnimation2.gif" />';

		//The location we are loading the page into.
		var serverPage = "home_image.php";
			
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}

	function changeSlide(directory) {

		// Get the object from the page
		var objID = "slideshow";
		var obj = document.getElementById(objID);

		var slideObjID = "slideShowImage";
		var slideObjID = document.getElementById(slideObjID);

		// Set the Loading Image
		slideObjID.innerHTML = '<img class="slideShowLoading" alt="loading..." src="images/loadingAnimation2.gif" />';

		//The location we are loading the page into.
		if(typeof(directory)=="undefined") { 
			var serverPage = "slide_image.php";
		}else{ 
			var serverPage = "slide_image.php?gdir="+directory;
		}

		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}

	function MakeArray(size) {
		this.length = size;
		for(var i = 1; i <= size; i++) {
			this[i] = 0;
		}
		return this;
	}

	function toggle(id){
		ul = "ul_" + id;
		img = "img_" + id;
		ulElement = document.getElementById(ul);
		imgElement = document.getElementById(img);
		if (ulElement){
			if (ulElement.className == 'closed'){
				ulElement.className = "open";
				imgElement.src = "/images/open.png";
			} else {
				ulElement.className = "closed";
				imgElement.src = "/images/closed.png";
			}
		}
	}