/**********************************************
FILETI Front End - Javascript
Name       : thumb_slide.js
Designer   : Ana Ghirello
Developer  : Francisco J. Rey
URL        : www.GhirelloDesign.com
Date       : 10 Sep 2007
Updated by : Francisco J. Rey
***********************************************/

// Show Pop Up in a specific position in the screen
function openPopUp(address, width, height, left, top)
{
  window.open(address,'SlideShow',"menubar=no,toolbar=no,scrollbars=no,width="+width+",height="+height+",left="+left+",top="+top);
}

// Show or Hide the Thumb Section in the Commissioned & Personal Albums
function thumbsShowHide(divname, labelname, showtext, hidetext)
{
  var divelem, labelelem, vis, lab;
  if( document.getElementById ) // this is the way the standards work
  {
    divelem = document.getElementById( divname );
    labelelem = document.getElementById( labelname );
  }
  else if( document.all ) // this is the way old msie versions work
  {
    divelem = document.all[divname];
    labelelem = document.all[labelname];
  }
  else if( document.layers ) // this is the way nn4 works
  {
    divelem = document.layers[divname];
    labelelem = document.layers[labelname];
  }
  vis = divelem.style;
  lab = labelelem;

  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&divelem.offsetWidth!=undefined&&divelem.offsetHeight!=undefined)
    vis.display = (divelem.offsetWidth!=0&&divelem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  lab.innerHTML = (vis.display!='none') ? hidetext : showtext;
}

// Show the next Image
function next_image()
{
  image_index = (image_index<photos.length-1) ? image_index + 1 : 0;

  document.getElementById('main_photo').src = photos[image_index];
  document.getElementById('current_image').innerHTML = image_index + 1;
}

// Show the Previous Image
function back_image()
{
  image_index--;
  image_index = (image_index<0) ? photos.length - 1 : image_index;

  document.getElementById('main_photo').src = photos[image_index];
  document.getElementById('current_image').innerHTML = image_index + 1;
}

// Generate the Thumbs in the Thumb Section and Set the Left & Right Cursors
function fill_thumbs()
{
  thumb_index = 0;

  if(photos.length>7)
  {
    for(j=0 ; j<7 ; j++)
      document.getElementById('photo_'+(j+1)).src = thumbs[j];

    document.getElementById('right_button').style.display = "block";
    document.getElementById('left_button').style.display  = "none";
  }
  else
  {
    for(j=0 ; j<photos.length ; j++)
      document.getElementById('photo_'+(j+1)).src = thumbs[j];
    for(j=photos.length ; j<7 ; j++)
      document.getElementById('photo_'+(j+1)).style.display = "none";

    image_index = (image_index>0) ? image_index - 1 : photos.length-1;

    document.getElementById('left_button').style.display  = "none";
    document.getElementById('right_button').style.display = "none";
  }
}

// Update the Thumb Section showing the next image of the gallery (Visitor click right cursor)
function next_thumb()
{
  thumb_index++;

  if(photos.length<=thumb_index+7)
  {
    for(j=thumb_index, k=1 ; j<7+thumb_index ; j++, k++)
      document.getElementById('photo_'+k).src = thumbs[j];
    document.getElementById('right_button').style.display = "none";
    document.getElementById('left_button').style.display  = "block";
  }
  else
  {
    for(j=thumb_index, k=1 ; j<7+thumb_index ; j++, k++)
      document.getElementById('photo_'+k).src = thumbs[j];
    document.getElementById('right_button').style.display = "block";
    document.getElementById('left_button').style.display  = "block";
  }
}

// Update the Thumb Section showing the previous image of the gallery (Visitor click left cursor)
function back_thumb()
{
  thumb_index--;

  if(thumb_index<1)
  {
    for(j=thumb_index,k=1 ; j<7+thumb_index ; j++, k++)
      document.getElementById('photo_'+k).src = thumbs[j];
    document.getElementById('right_button').style.display = "block";
    document.getElementById('left_button').style.display  = "none";
  }
  else
  {
    for(j=thumb_index, k=1 ; j<7+thumb_index ; j++, k++)
      document.getElementById('photo_'+k).src = thumbs[j];
    document.getElementById('right_button').style.display = "block";
    document.getElementById('left_button').style.display  = "block";
  }
}

// Update the Main Imane with a new one
function show_image(index)
{
  image_index = index + thumb_index;

  document.getElementById('main_photo').src = photos[image_index];
  document.getElementById('current_image').innerHTML = image_index + 1;
}
      