// =======================================================================
// Photoshare by Jorn Lind-Nielsen (C) 2002.
// ----------------------------------------------------------------------
// For POST-NUKE Content Management System
// Copyright (C) 2002 by the PostNuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WIthOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// =======================================================================

// Expect the following variables to be produced in the HTML:
//    array  'photoshareImages' containing the image information.
//    int    'startImageIndex' pointing to the initial image.
//    string 'thumbnailURL' pointing to the thumbnails view

// =======================================================================
// Globals
// =======================================================================
var currentImage = 0;


// =======================================================================
// Event handlers
// =======================================================================

function handleOnLoad()
{
  var img = document.getElementById("imageLocation");

  if (document.all)
    img.style.filter = "progid:DXImageTransform.Microsoft.gradientWipe(duration=2,Motion=reverse)";

  updateCurrentImage();
  updateImage(currentImage);

}


function handleOnClickNext()
{
  nextImage();
}


function handleOnClickPrev()
{
  --currentImage;

  if (currentImage < 0)
    currentImage = photoshareImages.length-1;

  updateImage(currentImage);
  updateCurrentImage();
}


function handleOnClickImage(img)
{
  var url = img.src.replace('viewimage','displayimage');
  url = url.replace('show','user');
  
  var width = photoshareImages[currentImage].width;
  var height = photoshareImages[currentImage].height;
  var imageWindow = window.open(url,'image','width='+width+',height='+height+',toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
  imageWindow.focus();
}


// =======================================================================
// 
// =======================================================================

function updateCurrentImage()
{
  var imageInfoElement = document.getElementById('imageInfoText');
  imageInfoElement.innerHTML = (currentImage+1) + "/" + photoshareImages.length;
}


function nextImage()
{
  ++currentImage;

  if (currentImage > photoshareImages.length-1)
    currentImage = 0;

  updateImage(currentImage);
  updateCurrentImage();
}


function updateImage(index)
{
  var img = document.getElementById("imageLocation");

  if (document.all)
    img.filters[0].apply();
  
  img.src = photoshareImages[index].url;
  img.alt = photoshareImages[index].title;

    // resize image, values from template.php
  img.width = photoshareImages[index].width;
  img.height = photoshareImages[index].height;

  if (document.all)
    img.filters[0].play();

    // Get DOM reference to title and set it
  var titleRef = document.getElementById('imageTitleText');
  titleRef.innerHTML = photoshareImages[index].title;

    // Get DOM reference to description and set it
  var descriptionRef = document.getElementById('imageDescriptionText');
  descriptionRef.innerHTML = photoshareImages[index].description;
}



