var xmlThumbHttp;
var currentStartIndex;
var listEnd = 18;

function initializeSlider(){
	currentStartIndex = 0;
	getFourThumbs(currentStartIndex);
	return;
}

function slideToStart(){
	currentStartIndex = 0;
	getFourThumbs(currentStartIndex);
	return;
}

function slideRightByOne(){
	if(currentStartIndex < listEnd - 3){
		currentStartIndex++;
		getFourThumbs(currentStartIndex);
	}
	return;
}

function slideLeftByOne(){
	if(currentStartIndex > 0){
		currentStartIndex--;
		getFourThumbs(currentStartIndex);
	}
	return;
}

function slideRightByFour(){
	if(currentStartIndex < listEnd - 7){
		currentStartIndex += 4;
		getFourThumbs(currentStartIndex);
	}else{
		currentStartIndex = listEnd - 3;
		getFourThumbs(currentStartIndex);
	}
	return;
}

function slideLeftByFour(){
	if(currentStartIndex > 3){
		currentStartIndex -= 4;
		getFourThumbs(currentStartIndex);
	}else{
		currentStartIndex = 0;
		getFourThumbs(currentStartIndex);
	}
	return;
}

function slideToEnd(){
	currentStartIndex = listEnd - 3;
	getFourThumbs(currentStartIndex);
	return;
}

function getFourThumbs(startingAt){
	xmlThumbHttp = GetXmlHttpThumbObject();
	if(xmlThumbHttp == null){
 		//alert ("Browser does not support HTTP Request");
 		window.location = "tour_simple.shtml";
 		return;
 	} 
	
	var url = "tour/tourthumbs.php";
	url = url + "?q=" + startingAt;
	url = url + "&sid=" + Math.random();
	xmlThumbHttp.onreadystatechange = stateHasChanged ;
	xmlThumbHttp.open("GET", url, true);
	xmlThumbHttp.send(null);

	document.getElementById("thumb_status").innerHTML = (currentStartIndex + 1) + " - " + (currentStartIndex + 4) + " of " + (listEnd + 1);

	return;
}

function stateHasChanged() { 
	if(xmlThumbHttp.readyState == 4 || xmlThumbHttp.readyState=="complete"){ 
		document.getElementById("thumb_container").innerHTML = xmlThumbHttp.responseText;
	}
	return;
}

function GetXmlHttpThumbObject(){
	var xmlThumbHttp = null;

	try{
		// Firefox, Opera 8.0+, Safari
		xmlThumbHttp = new XMLHttpRequest();
	}catch(E){
		// Internet Explorer
		try{
			xmlThumbHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(E){
			xmlThumbHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlThumbHttp;
}
