// JavaScript Document
var xmlHttp1
var xmlHttp
var photoCurrent
var photos

function getPhoto(str)
{

document.getElementById("PhotoComment").innerHTML=""
document.getElementById("Photo").innerHTML="<img src='images/indicator.gif'>"
getImage(str);
getComment(str);
photoCurrent = str;
return false;
} 


function getImage(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="includes/getImage.php";
url=url+"?gid="+str;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
return false;
}
function getComment(str)
{
xmlHttp1=GetXmlHttpObject()
if (xmlHttp1==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="includes/getComment.php";
url=url+"?gid="+str;
xmlHttp1.onreadystatechange=stateChanged1;
xmlHttp1.open("GET",url,true);
xmlHttp1.send(null);
return false;
}
function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("Photo").innerHTML=xmlHttp.responseText;
}
}
function stateChanged1() 
{ 
if (xmlHttp1.readyState==4)
{ 
document.getElementById("PhotoComment").innerHTML=xmlHttp1.responseText;
}
}

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 getCurrent()
{
	getPhoto(photoCurrent);
}
function getNext()
{
	var oldcurrent = getPosition()
	if (oldcurrent+1 > photos.length - 1) {
		photoCurrent = photos[0];
	} else {
		photoCurrent = photos[oldcurrent+1];
	}
	getCurrent()
}

function getPrevious()
{
	var oldcurrent = getPosition()
	if (oldcurrent-1 < 0) {
		photoCurrent = photos[photos.length - 1];
	} else {
		photoCurrent = photos[oldcurrent-1];
	}
	getCurrent()
}

function getPosition()
{
	for (var i=0; i<photos.length; i++) {
		if (photos[i] == photoCurrent) {
			return i
		}
	}
	return photos[0];
}

