var http = getHTTPObject(); // We create the HTTP Object for AJAX methods
function getHTTPObject()
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
    try
		{
      xmlhttp = new XMLHttpRequest();
    }
		catch (e)
		{
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
function handleNextPhotoResponse()
{
  if (http.readyState == 4)
	{
 	  // http.responseText will return | and ^ delineated characters from getPhotoDetails.php
		var PhotoResponse = http.responseText;		
//		alert(http.responseText);
				
		var ThisImgCaptionText = "";
		var PrevImagePath = "";
		var NextImagePath = "";
		
		var responseLines = PhotoResponse.split("^");
		for(i=0; i<responseLines.length; i++)
		{
			var responseColumns = responseLines[i].split("|");
			NextOrPrev = responseColumns[0];
			if (NextOrPrev == 'THIS')
			{				
				Height = responseColumns[2];
				Width = responseColumns[3];
				if (responseColumns[4] != "")
				{	Make = responseColumns[4];	}
				else
				{	Make = "N/A";	}
				if (responseColumns[5] != "")
				{	Model = responseColumns[5];	}
				else
				{	Model = "N/A";	}
				DateTime = responseColumns[6];
				if (responseColumns[7] != "")
				{
					var pieces = responseColumns[7].split("/");				
					ExposureTime = (Math.round( (pieces[0]/pieces[1]) * 100 ) / 100) + " sec";
				}
				else
				{	ExposureTime = "N/A";	}
				ExposureProgram = responseColumns[8];
				if (responseColumns[9] != "")
				{	FNumber = responseColumns[9];	}
				else
				{	FNumber = "N/A";	}
				if (responseColumns[10] != "")
				{
					var pieces = responseColumns[10].split("/");				
					FocalLength = (Math.round( (pieces[0]/pieces[1]) * 100 ) / 100) + " mm";
				}
				else
				{	FocalLength = "N/A";	}
				if (responseColumns[11] != "")
				{
					var pieces = responseColumns[11].split("/");				
					Brightness = Math.round( (pieces[0]/pieces[1]) * 100 ) / 100;
				}
				else
				{	Brightness = "N/A";	}
				MeteringMode = responseColumns[12];
				if (responseColumns[13] != "")
				{	ISOSpeedRatings = responseColumns[13];	}
				else
				{	ISOSpeedRatings = "N/A";	}
				Flash = responseColumns[14];
				Display_Order = responseColumns[15];		
				ThisImgCaptionText = responseColumns[16];
				
				// Create EXIF table information
				EXIF_Panel = "<div class=\"12px bold curs_pointer\"><img src=\"rp_resources/orange-check.gif\" border=\"0\" height=\"14\" width=\"14\" style=\"cursor:pointer;\" onClick=\"fadeEXIFout()\" alt=\"Hide EXIF Info Panel\">&nbsp;&nbsp;EXIF Info:</div>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Original Dimensions of the file as it was captured on the digital device\">Original Dimensions:</b>&nbsp;&nbsp;"+Width+"x"+Height+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Date/Time on the camera when the image was taken\">Photo Taken:</b>&nbsp;&nbsp;"+DateTime+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Length of time the shutter was open for this photo (in seconds)\">Exposure Time:</b>&nbsp;&nbsp;"+ExposureTime+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Exposure Program used by the camera for this photo\">Exposure Program:</b>&nbsp;&nbsp;"+ExposureProgram+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Aperture FStop setting for this photo\">FStop:</b>&nbsp;&nbsp;"+FNumber+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Effective focal length of the lense in mm\">Focal Length:</b>&nbsp;&nbsp;"+FocalLength+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Camera-measured brightness of the scene in this photo\">Brightness:</b>&nbsp;&nbsp;"+Brightness+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Light Metering mode used by the camera in detecting flash usage\">Metering Mode:</b>&nbsp;&nbsp;"+MeteringMode+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Light Sensitivity setting used by the digital camera\">ISO Setting:</b>&nbsp;&nbsp;"+ISOSpeedRatings+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Setting used for flash mode\">Flash:</b>&nbsp;&nbsp;"+Flash+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Manufacturer of the image capture device that was used in this shot\">Manufacturer:</b>&nbsp;&nbsp;"+Make+"</div><br>";
				EXIF_Panel += "<div class=\"inline\"><b class=\"curs_help\" title=\"Camera Model/Make used to take this shot\">Camera Model:</b>&nbsp;&nbsp;"+Model+"</div>";	

				// Determine what we fill the EXIF DIV panel with
				if (showEXIFInfo == true)
				{	ShowEXIFPanel();	}
				else
				{	HideEXIFPanel();	}
				document.getElementById('exif_panel').style.display = 'block';
			}
			else if (NextOrPrev == 'PREV')
			{
				PrevImagePath = responseColumns[1].replace("'", "\\'");
			}
			else if (NextOrPrev == 'NEXT')
			{
				NextImagePath = responseColumns[1].replace("'", "\\'");
			}
		}
		var outputHTML = '<table cellpadding="1" cellspacing="1" border="0" style="width:100%;">'+"\n";
		outputHTML += "<tr>\n<td style=\"width:160px;\">&nbsp;</td>\n<td>";
		if (ThisImgCaptionText != "")
		{	outputHTML += '<b>Caption:</b>&nbsp;&nbsp;&nbsp;'+ThisImgCaptionText;	}
		outputHTML += '</td><td style="width:20px;" title="<< Previous Photo">';
		if (PrevImagePath != "")
		{	outputHTML += '<img src="rp_resources/left-arrow-red.gif" height="23" width="18" border="0" onClick="showImageOverlay(\''+PrevImagePath+'\')" style="cursor:pointer;cursor:hand;">';	}
		else
		{	outputHTML += '<img src="rp_resources/stop-square-red.gif" height="23" width="18" border="0">';	}
		outputHTML += '</td><td style="width:20px;" title="Next Photo >>">';
		if (NextImagePath != "")
		{	outputHTML += '<img src="rp_resources/right-arrow-red.gif" height="23" width="18" border="0" onClick="showImageOverlay(\''+NextImagePath+'\')" style="cursor:pointer;cursor:hand;">';	}
		else
		{	outputHTML += '<img src="rp_resources/stop-square-red.gif" height="23" width="18" border="0">';	}
		outputHTML += "</td>\n</tr>\n</table>";
		 
		document.getElementById('objCaption').innerHTML = outputHTML;
  }
}
function getPhotoDetails(Filename)
{	
	document.getElementById('objCaption').innerHTML = '<table cellpadding="1" cellspacing="1" border="0" style="width:100%; height:27px;">\n<tr>\n<td style="width:160px;">&nbsp;</td>\n<td><b>Loading...</b><img src="rp_resources/albumize-progress-bar-sm.gif" height="8" width="8" border="0"></td>\n</tr>\n</table>';
	var url = "includes/getPhotoDetails.php?filename="+escape(Filename);
//	alert (url);
	http.open("GET", url, true);
	http.onreadystatechange = handleNextPhotoResponse;
	http.send(null);
}
