//  Copyright: Zacke, Berlin 2005, http://www.ufocomes.de
//  Fri Sep 16 23:18:06 2005 

var N;  //  Index Bilder
var R;  //  Index Reihen 
var rows = new Array();
var L;  //  letztes Bild 

function showPreviews(n)
{
  for (var i=0; i<5; i++)
  {
    var preview = eval("document.prev"+i);
    if ( n+i >= 0)
    {
      var buf = bilder[n+i].split(',');
      preview.src = buf[0];
      preview.style.cursor = "pointer";
    }
    else
    {
      preview.src = "../gifs/xspacer.gif"; //"../bilder/wtspacer.jpg";
      document.getElementById('previews').style.backgroundColor = "#f6f6f6";
    }
  }
}

function initRows()
{
  var z = 0;
  var num_of_rows = Math.ceil(L/5); 
  document.getElementById('row').firstChild.nodeValue="#"+num_of_rows;
  for ( i=num_of_rows;  i >=0;  i-- )
  {
    rows[i]= L - 5*z; 
    z++;
  }
  R =  num_of_rows-1;
  showPreviews(rows[R]);
}

function syncRows()
{
  for (var i=0; i<rows.length-1; i++)
  {
    if ( N >= rows[i] ) R = i;
  }
  showPreviews(rows[R]);
  document.getElementById('row').firstChild.nodeValue="#"+eval(R+1); 
}

function cursors()
{
  // forward:
  if ( N <  L-1 ) document.arr_left.style.cursor="pointer";
  else document.arr_left.style.cursor="default";

  // backward:
  if ( N > 0 ) document.arr_right.style.cursor="pointer";
  else document.arr_right.style.cursor="default";

  // up:
  if ( R < rows.length-2) document.arr_up.style.cursor="pointer";
  else document.arr_up.style.cursor="default";

  // down:
  if ( R > 0) document.arr_down.style.cursor="pointer";
  else document.arr_down.style.cursor="default";

  // previews: 
  for (var i = 0; i < 5; i++)
  { 
    var preview = eval("document.prev"+i);
    if (( i == N-rows[R] ) || ( rows[R]+i < 0 )) preview.style.cursor = "default";
    else preview.style.cursor = "pointer";
  }
}

function prevSelect(n)
{
  var buf = rows[R] + n;
  N = buf;
  showLarge(buf);
  cursors();
}

function subtitles()
{
  var buf = bilder[N].split(',');  
  document.getElementById('subtitle').firstChild.nodeValue=buf[2];
}

function showLarge(n)
{
  var buf = bilder[n].split(',');  
  document.large.src=buf[1]; 
  document.getElementById('subtitle').firstChild.nodeValue="Please wait!";
  document.getElementById('pics').firstChild.nodeValue="#"+eval(n+1);
}

function backw()
{
  if ( N > 0 )
 {
   N --;
   showLarge(N);
  }
  else N = N;

  syncRows();
  cursors();
}

function forw()
{
  if ( N <  L-1 )
  {
   N ++;
   showLarge(N);
  }
  else N = N;

  syncRows();
  cursors();
}

function up()
{
  if ( R < rows.length-2)
  {
   R ++;
   document.getElementById('row').firstChild.nodeValue="#"+eval(R+1);
   cursors();
   showPreviews(rows[R]);
  }
}

function down()
{
  if ( R > 0)
  {
   R --;
   document.getElementById('row').firstChild.nodeValue="#"+eval(R+1);
   cursors();
   showPreviews(rows[R]);
  }
}

function initGal()
{ 
  L = bilder.length;
  N = L-1;
  initRows();
  showLarge(N);
  document.arr_right.style.cursor="pointer";
  document.arr_down.style.cursor="pointer";
  document.prev4.style.cursor="default";
}
