  function HighlightPhoto(PhotoID) {
      var Photo = document.getElementById('Photo'+PhotoID);
      Photo.className = "PhotoThumbHighlight";
  }

  function HideHighlight(PhotoID) {
      var Photo = document.getElementById('Photo'+PhotoID);
      //Photo.style.border = "#FFFFFF solid 2px";
      Photo.className = "PhotoThumb";
  }

  function GetImageWidth(Photo) {
	  return Photo.width;
  }

  function ViewPhoto(PhotoID) {
      var NextPhotoID = PhotoID + 1;
      var PrevPhotoID = PhotoID - 1;
      var Photos = GetPhotos();

      if (NextPhotoID < (Photos.length - 1)) {
          var NextControl = " <a href='javascript: ViewPhoto("+NextPhotoID+");'><img src='images/icon-next.gif' border='0' /><\/a>";
      } else {
          var NextControl = " <img src='images/icon-endblock.gif' />";
      }
      if (PrevPhotoID >= 0) {
          var PrevControl = " <a href='javascript: ViewPhoto("+PrevPhotoID+");'><img src='images/icon-previous.gif' border='0' /><\/a>";
      } else {
          var PrevControl = " <img src='images/icon-endblock.gif' />";
      }
	  var Counter = NextPhotoID + "/" + (Photos.length - 1);
      var PhotoDiv = document.getElementById('PhotoDiv');
	  PhotoControls = "<table width='"+Photos[PhotoID][2]+"'><tr><td width='50' class='SmallText'><a href='javascript: ClosePhotoViewer();' /><img src='images/icon-close.gif' border='0' align='left' />Close<\/a><\/td><td align='center'>"+Photos[PhotoID][1]+"<\/td><td width='35' align='center' class='SmallText'>"+Counter+"<br />"+PrevControl+NextControl+"<\/td><\/tr><\/table>";
      PhotoDiv.innerHTML = "<img src='"+Photos[PhotoID][0]+"' alt='"+Photos[PhotoID][1]+"' title='"+Photos[PhotoID][1]+"' "+Photos[PhotoID][4]+" />"+PhotoControls;

      CurrentPos = GetItemTop('Photo'+PhotoID);
      PopupHeight = PhotoDiv.offsetHeight;
      PopupHeight = Photos[PhotoID][3];
      NewTop = CurrentPos - PopupHeight;
      if (NewTop < 100) {NewTop = 100;}

      winW = document.body.offsetWidth;
      PhotoDiv.style.top = NewTop + "px";
      PhotoDiv.style.left = (winW - Photos[PhotoID][2]) / 2 + "px";
	  PhotoDiv.style.width = Photos[PhotoID][2] + "px";
	  PhotoDiv.style.visibility = "visible";
  }

  function ClosePhotoViewer() {
      var PhotoDiv = document.getElementById('PhotoDiv');
      PhotoDiv.style.visibility = "hidden";
  }

  function GetItemTop(ItemID) {
      var Item = document.getElementById(ItemID);

      //Get item Coords
      if (Item.offsetParent) {
      curleft = Item.offsetLeft
      curtop = Item.offsetTop
      while (Item = Item.offsetParent) {
          curleft += Item.offsetLeft
          curtop += Item.offsetTop
      }
        curtop = curtop;
      }
      return curtop
  }

