// =======================================================================
// 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 exist (created by Photoshare)
//  imageData
//  emptyImageURL

  // Index of the currently selected tab
var currentTabIndex = 0;
var currentImageIndex = 0;

  // Called on load to initiate the gallery
function handleOnLoad()
{
  selectTab(0);
}

  // Select one of the tabs
function selectTab(tabIndex)
{
  var oldTabElement = document.getElementById("tab" + currentTabIndex);
  oldTabElement.className = "unselected";

  var tabElement = document.getElementById("tab" + tabIndex);
  tabElement.className = "selected";

  var divElement = document.getElementById("thumbnailsDiv");
  divElement.innerHTML = imageData[tabIndex].rawHTML;

  currentTabIndex = tabIndex;

  selectThumbnail(0);
}


function handleOnClickTab(tabIndex)
{
  selectTab(tabIndex);
}


function selectThumbnail(imageIndex)
{
  var imageInfo = imageData[currentTabIndex].info;

  if (typeof imageInfo[imageIndex] != "undefined")
  {
    var src       = imageInfo[imageIndex].src;
    var mainImage = document.images['mainImage'];
    mainImage.src = src;
    mainImage.alt = imageInfo[imageIndex].title;

    // V4B 26-01-2004 TS start
    // resize image, values from template.php
    mainImage.width = imageInfo[imageIndex].width;
    mainImage.height = imageInfo[imageIndex].height;
    // V4B 26-01-2004 TS end
	
    var title = document.getElementById('mainTitle');
    title.innerHTML = imageInfo[imageIndex].title;

    var description = document.getElementById('mainDescription');
    description.innerHTML = imageInfo[imageIndex].description;

    currentImageIndex = imageIndex;
  }
}


function handleOnClickThumbnail(imageIndex)
{
  selectThumbnail(imageIndex);
}


function handleOnClickImage(img)
{
  var imageInfo = imageData[currentTabIndex].info;

  if (typeof imageInfo[currentImageIndex] != "undefined")
  {
    var url = img.src.replace('viewimage','displayimage');
    url = url.replace('show','user');
    var width = imageInfo[currentImageIndex].width;
    var height = imageInfo[currentImageIndex].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();
  }
}

