var _arrPhotos = [];

function OpenPhotoWindow(intPhotoIndex) {
  window.open('/photo.php?n=' + intPhotoIndex, 'photo_window', 'channelmode=0,menubar=0,location=0,directories=0,status=0,titlebar=0,toolbar=0,scrollbars=1,resizable=1,fullscreen=0');
}

function PhotoGallery(arrPhotos, arrPhotoFolderIndexes, blnFolderView) {
  var strPath = strPhotoPath;
  if (blnFolderView) {
    var strPhotoFolderIndexes = '';
    for (var i = 0; i < arrPhotoFolderIndexes.length; i++)
      strPhotoFolderIndexes += '[' + arrPhotoFolderIndexes[i] + '][3]';
    arrPhotos = eval('arrPhotos' + strPhotoFolderIndexes);
  }
  var strLinks = '';
  var arrCurrentFolder = arrPhotoFolders;
  for (var i = 0; i < arrPhotoFolderIndexes.length; i++) {
    var j = arrPhotoFolderIndexes[i];
    if (i == arrPhotoFolderIndexes.length - 1)
      strLinks += ' > <nobr>' + arrCurrentFolder[j][0] + '</nobr>';
    else
      strLinks += ' > <a href="' + strPath + arrCurrentFolder[j][2] + '/"><nobr>' + arrCurrentFolder[j][0] + '</nobr></a>';
    strPath += arrCurrentFolder[j][2] + '/';
    arrCurrentFolder = arrCurrentFolder[j][3];
  }
  if ((arrPhotoFolderIndexes.length > 0) && (strPhotoPathCaption != ''))
    document.write('<a href="' + strPhotoPath + '">' + strPhotoPathCaption + '</a>' + strLinks + '<br><br>');

  var strResult = '', intCount = 0;
  for (var i = 0; i < arrPhotos.length; i++) {
    arrPhotos[i][1] = strPath + (blnFolderView ? arrPhotos[i][2] + '/' : '') + arrPhotos[i][1];
    arrPhotos[i][2] = strPath + arrPhotos[i][2];
    _arrPhotos[i] = [arrPhotos[i][0], arrPhotos[i][2]];
    var strLink = ' href="' + (blnFolderView ? arrPhotos[i][2] + '/' : 'javascript:OpenPhotoWindow(' + i + ')') +
      '" title="' + (blnFolderView ? 'Открыть папку' : 'Увеличить фотографию') + '"';
    intCount++;
    strResult += '<td class="clsPhotoThumb' + (blnFolderView ? ' clsPhotoFolder' : '') + '"><a class=clsPhotoThumbImgLink' + strLink + '><img src="' + arrPhotos[i][1] +
      '"></a><table cellspacing=0 cellpadding=0><tr><td><a' + strLink + '>' + arrPhotos[i][0] + '</a></td></tr></table></td>';
    if (i < arrPhotos.length - 1) {
      if (intCount < 4)
        strResult += '<td class=clsPhotoThumbSpace>&nbsp;</td>';
      else {
        strResult += '</tr><tr><td colspan=7>&nbsp;</td></tr><tr>';
        intCount = 0;
      }
    } else if ((arrPhotos.length > 4) && (intCount < 4))
      strResult += '<td colspan=' + ((4 - intCount) * 2) + '>&nbsp;</td>';
  }
  document.write('<table cellspacing=0 cellpadding=0><tr>' + strResult + '</tr></table>');
}

function PutMailLink(s1, s2) {
  document.write('<a href="mailto:' + s1 + '@' + s2 +  '">' + s1 + '@' + s2 + '</a>');
}
