gallery_path = "foto/";
thumbnails_path = "foto_tn/";

ico_next_path = "../../../images/ico/next.gif";
ico_prev_path = "../../../images/ico/prev.gif";
ico_next_dis_path = "../../../images/ico/next_dis.gif";
ico_prev_dis_path = "../../../images/ico/prev_dis.gif";
ico_close_path = "../../../images/ico/close.gif";

/******************************************************************************/

function pictureInfo(name,category,desc,bg_color,width,height) 
  {
  this.name = name;
  this.category = category;
  this.desc = desc;
  this.bg_color = bg_color;
  this.width = width;
  this.height = height;
  }

/******************************************************************************/

function showPicture(idx,close)
  {
  if( img_window != null && close )
    img_window.close();

  picture_idx = idx;
  img_window = window.open("galimage.html","picture_wnd", "width=50,height=50,scrollbars=yes,fullscreen=yes" );

  if( close )
    {
    for( i=300 ; i >= 0 ; i-= 100 )
      img_window.resizeTo( pictures[idx].width+50-i, pictures[idx].height+110-i );
    }
  else
    {
    img_window.resizeTo( pictures[idx].width+50, pictures[idx].height+110 );
    }
  }

/******************************************************************************/

function hidePicture()
  {
  if( img_window == null )
    return;

  for( i=0 ; i <= 5 ; i++ )
    img_window.resizeBy( -100, -100 );

  img_window.close();
  }

/******************************************************************************/

function showNext()
  {
  showPicture( picture_idx + 1, false );
  }

/******************************************************************************/

function showPrev()
  {
  showPicture( picture_idx - 1, false );
  }

/******************************************************************************/

function checkCategories()
  {
  categories = new Object();
  categories_count = 0;

  for( i=0 ; pictures[i] != null ; i++ )
    {
    cat = pictures[i].category;

    for( j=0 ; j < categories_count ; j++ )
      if( categories[j] == cat )
        break;

    if( j == categories_count )
      {
      categories[categories_count] = cat;
      categories_count++;
      }
    }
  }

/******************************************************************************/

function displayIndex()
  {
  var text = "";

  checkCategories();

  for( var j=0 ; j<categories_count ; j++ )
    {
    text += "<h2>"+categories[j]+"</h2>";

    for( var i=0 ; pictures[i] != null ; i++ )
      {
      if( pictures[i].category != categories[j] )
        continue;

      text += "<a href=\"javascript:showPicture("+i+",true)\">";
      text += "  <img width=120 style=\"border: solid "+pictures[i].bg_color+"; border-width: 1\" src=\"" + thumbnails_path + pictures[i].name + "\" title=\"" + pictures[i].desc + "\">";
      text += "</a>&nbsp;&nbsp;\n\n";
      }

    text += "<br>";
    }

  document.write(text);
  }

/******************************************************************************/

function displayImage()
  {
  if( window.opener == null )
    window.close();

  var text = "";
  var idx = window.opener.picture_idx;
  var img = window.opener.pictures[window.opener.picture_idx];

  text += "<title>"+(idx+1)+" >>> "+img.category+" >>> "+img.desc+"</title>";
  text += "</head>";
  text += "<body bgcolor=\""+img.bg_color+"\"><center>";

  // zdjęcie:
  text += "<img src=\"" + gallery_path+img.name + "\" title=\"Zdjęcie nr "+(idx+1)+"\nKategoria: "+img.category+"\nOpis: "+img.desc+"\"><br><br>\n";

  // strzałka w lewo:
  if( idx > 0 )
    {
    text += "<a href=\"javascript:window.opener.showPrev()\">";
    text += "<img border=0 src=\""+ico_prev_path+"\" title=\"Poprzednie\">";
    text += "</a>";
    }
  else
    {
    text += "<img src=\""+ico_prev_dis_path+"\">";
    }

  // ikona zamykania:
  text += "&nbsp;&nbsp;&nbsp;";
  text += "<a href=\"javascript:window.opener.hidePicture()\">";
  text += "<img border=0 src=\""+ico_close_path+"\" title=\"Zamknij\">";
  text += "</a>";
  text += "&nbsp;&nbsp;&nbsp;";

  // strzałka w prawo:
  if( window.opener.pictures[idx+1] != null  )
    {
    text += "<a href=\"javascript:window.opener.showNext()\">";
    text += "<img border=0 src=\""+ico_next_path+"\" title=\"Następne\">";
    text += "</a>";
    }
  else
    {
    text += "<img src=\""+ico_next_dis_path+"\">";
    }

  text += "</center></body>";

  document.write(text);
  }

/******************************************************************************/

