/*
Interactive Image slideshow with text description
By Christian Carlessi Salvadó (cocolinks@c.net.gt). Keep this notice intact.
Visit http://www.dynamicdrive.com for script

Enhanced by Greg Hartwig (greg at hartwig dot com) 2/2004
*/


var url_play  = "play.gif";
var url_pause = "pause.gif";

var auto_msgs = new Object();
auto_msgs["auto"]   = "(auto)";
auto_msgs["manual"] = "";



var g_fPlayMode = false;
var g_iimg = 0;
var g_imax = 0;
var g_ImageTable   = new Array();
var g_ImagePreload = new Array(new Image(), new Image(), new Image(), new Image());

var url_control = null;


function getobject(obj) {
	if (document.getElementById)
		return document.getElementById(obj);  // Modern browsers
	else if (document.all)
		return document.all[obj];             // Older MSIE
	else return null;
	// Netscape 4 not supported
}


function FixNum(ImgNum) {
	if (ImgNum < 0) ImgNum += g_imax;
	return ImgNum % g_imax;
}


function Initialize() {
	// Get the start of the URL, so we can change the file portion
	var url_start = getobject("btnPlay").src;
	var lastslash = url_start.lastIndexOf("/");
	if (lastslash != -1)
		url_start = url_start.substring(0,lastslash+1);
	else
		url_start = "";
	
	// Add the start of the URL to the file names
	url_play  = url_start + url_play;
	url_pause = url_start + url_pause;
	
	// Pre-load the button images
	var idx;
	idx = g_ImagePreload.length;
	g_ImagePreload[idx] = new Image();
	g_ImagePreload[idx].src = url_play;
	idx = g_ImagePreload.length;
	g_ImagePreload[idx] = new Image();
	g_ImagePreload[idx].src = url_pause;
	
	// Show data for the first image
	Update();
}



function Update() {
	// Load the image to be displayed
	var slide = getobject("Ath_Slide");
	
   if (slide.filters) slide.filters.blendTrans.apply();  // For MSIE transitions
	slide.src = g_ImageTable[g_iimg][0];  // Updat the picture on the screen
   if (slide.filters) slide.filters.blendTrans.play();  // For MSIE transitions
	
	// Pre-load possible future images
	g_ImagePreload[0].src = g_ImageTable[FixNum(g_iimg+1)][0];  // Load next
	g_ImagePreload[1].src = g_ImageTable[FixNum(g_iimg-1)][0];  // Load previous
	g_ImagePreload[2].src = g_ImageTable[FixNum(g_iimg+2)][0];  // Load next+1
	g_ImagePreload[3].src = g_ImageTable[FixNum(g_iimg+3)][0];  // Load next+2
}


function Play() {
	g_fPlayMode = !g_fPlayMode;
	
	if (g_fPlayMode) {
		getobject("btnPlay").src        = url_pause;
		//getobject("btnPrev").disabled   = getobject("btnNext").disabled = true;
		getobject("Ath_Mode").innerHTML = auto_msgs["auto"];
		Next();
	}
	else {
		getobject("btnPlay").src        = url_play;
		getobject("btnPrev").disabled   = getobject("btnNext").disabled = false;
		getobject("Ath_Mode").innerHTML = auto_msgs["manual"];
	}
}


function OnImgLoad() {
	// Image is now displayed.  Now show the data for that image
	getobject("Ath_FileName").innerHTML = g_ImageTable[g_iimg][1];
	getobject("Ath_Img_X").innerHTML    = g_iimg + 1;
	getobject("Ath_Img_N").innerHTML    = " of " + g_imax;
	getobject("Ath_Mode").innerHTML     = g_fPlayMode ? auto_msgs["auto"] : auto_msgs["manual"];
	
	// If we're in auto mode, set a timer to show the next image
	if (g_fPlayMode)
		window.setTimeout("Tick()", g_dwTimeOutSec*1000);
}


function Tick()  {
	if (g_fPlayMode)
		Next();
}


function Prev() {
	g_iimg = FixNum(g_iimg-1);
	Update();
}


function Next() {
	g_iimg = FixNum(g_iimg+1);
	Update();
}



window.onload=Initialize;
