
var productID;
var imageArray = new Array();

function $(x) { return document.getElementById(x); }

function init()
{
  // Get image IDs
  productID = $('productID').value;
  imageArray = $('images').value.split( ',' );
}

function viewImage( index )
{
  $('productImage').src = 'images/item/' + productID + '-' + imageArray[ index ] + '-s.jpg';
  
  for ( var i = 0; i < 3; i++ )
    if ( $( 'imgLink' + i ) )
      $( 'imgLink' + i ).className = '';
      
  $( 'imgLink' + index ).className = 'selected';
  
  return false;
}


// Popup functions
function popup( img )
{
  var ScrollTop = document.body.scrollTop;
  var height = window.innerHeight;
  
  if( !height )
    height = document.body.clientHeight;

  if (ScrollTop == 0)
  {
    if (window.pageYOffset)
      ScrollTop = window.pageYOffset;
    else
      ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
  }
  
  $('popupImageContent').innerHTML = '<img src="'+img+'" alt="" onload="popupImageLoaded(this)" /><p onclick="closePopup()" class="pointer">Close</p>';
  
  if( $('container').offsetHeight > height )
    $('backTrans').style.height = $('container').offsetHeight+'px';
  
  if( ScrollTop > 0 )
  {
    $('popupImage').style.top = (ScrollTop) + 'px';
  }
  
  $('backTrans').style.display = 'block';
  $('popupImage').style.display = 'block';
}


function closePopup(  )
{
  $('popupImage').style.display = 'none';
  $('backTrans').style.display = 'none';
  $('popupImageContent').innerHTML = '';
  $('popupImageContent').style.wioth = '0px';
}

function popupImageLoaded( e )
{
  $('popupImageContent').style.width = e.offsetWidth + 'px';
}
