var xmlHttp1;
var xmlHttp2;

function getPic(index, destination)
{ 

	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp1==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 //return;
	 }
	var url="getPic.php";
	url=url+"?index="+index;
	url=url+"&destination=" + destination;
	url=url+"&sid="+Math.random();
	xmlHttp1.onreadystatechange=stateChanged ;
	xmlHttp1.open("GET",url,true);
	xmlHttp1.send(null);

}

function stateChanged() 
{ 
if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete")
 { 

 	var results = xmlHttp1.responseText.split(",");
 	var displayBox = "<img src='" + results[0] + "/Images/" + results[1] + ".jpg' alt='" + results[1] + "' align='top' width='700' height='500'>";

	 document.getElementById("displayBox").innerHTML=displayBox;
	 document.getElementById("caption").innerHTML=results[4];
	 document.indexValues.curr.value = results[1];
	 document.indexValues.prev.value = results[2];
	 document.indexValues.next.value = results[3];
	 document.indexValues.destination.value = results[0];
 } 
}



function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();

	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
	  {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }

	return xmlHttp;
}

function navIndex(direction)
{
    var idx;
	
	if (direction == "prev")
	{
		idx = document.indexValues.prev.value;
	}
	else if(direction == "next")
	{
		idx = document.indexValues.next.value;
	}
	else
	{
		idx = document.indexValues.curr.value;
	}
	
  var dest = document.indexValues.destination.value;
  getPic(idx, dest);
}  
