/* Copyright 2007-2010 Maurice Ferguson */

function switchin(folder, series, imgnum){
	document.getElementById(folder+series+"large").src=folder+"/"+imgnum+".jpg";
	document.getElementById(folder+series+"caption").innerHTML=document.getElementById(imgnum+"_caption").innerHTML;
}

function switchin_new(src){
	var src_split=src.split("/");
	var img=src_split[1];
	var folder=src_split[0];
	var album=img.split("", 2);
	if(album[0]==0){album=album[1];}else{album=album[0]+album[1];}

	document.getElementById(folder+album+"large").src=folder+"/"+img;
	document.getElementById(folder+album+"caption").innerHTML=document.getElementById(img+"_caption").innerHTML;
}

var loading_string="<img src=\"images/loading.png\" alt=\"\" style=\"display:inline;\" /> Loading page content...";
var current_page="home.html"

function loadDoc(the_page){
	if(the_page!=current_page){
		try{xmlhttp=new XMLHttpRequest();}
		catch(error){xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		xmlhttp.open("GET",the_page,true);
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4){
				document.getElementById('content').innerHTML=xmlhttp.responseText;}
			else{document.getElementById('content').innerHTML=loading_string+" Step "+xmlhttp.readyState+" of 4 complete.";}
		}
		xmlhttp.send(null);
		current_page=the_page;
	}
}

function showLoadingOverlay(){
	document.getElementById('loading_overlay').className="active";

	animateLoadingGraphic(1);
}

var global_num;//since setTimeOut is an externally defined function, internal function variable num must be passed through a global variable.
function animateLoadingGraphic(num){
	if(num<5 && document.getElementById('loading_overlay').className.indexOf('active')==0){global_num=num;
		h=setTimeout("document.getElementById('loading_overlay').className='active, loading_state'+global_num; global_num++; animateLoadingGraphic(global_num);", 500);
	}else if(num=5 && document.getElementById('loading_overlay').className.indexOf('active')==0){
		h=setTimeout("global_num=1; animateLoadingGraphic(global_num);", 200);}
//somehow the script tends to move slower at the end of the loop, so I compensate by shortening the wait time.
//function actively checks loading_overlay's class state, & breaks the loop when it is not active, so it doesn't silently keep running in the background
}
