// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully

// $Id: ListPhotos.js,v 1.3 2007/10/06 22:19:14 boogey Exp $

// Agent sniffer shamelessly 'stolen' from the excellent X library from cross-browser.com
var xOp7=false,xOp5or6=false,xIE4Up=false,xNN4=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if(document.layers) xNN4=true;
else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=6;}

var direction=1;

function preLoadPic(index){
	if (preLoad[index] == undefined && Pic[index] != undefined){
		preLoad[index] = new Image();
		preLoad[index].src = Pic[index].Image;
	}
}

function runSlideShow(newDirection, gotoImage) {
	clearTimeout(t);
	if (newDirection!=0 | gotoImage != undefined) {
		if (gotoImage != undefined) {
			j=gotoImage;
			document.forms['GlobalForm'].PlayPause.value='Play';
			document.forms['GlobalForm'].PlayPause.style.textDecoration='blink';
		}
		
		j = j + newDirection;
		if (j > (Pic.length-1)) j=1;
		if (j < 1) j=Pic.length-1;
		
		location.href='#p'+j;
		
		if (newDirection > 1) direction=1;
		else if (newDirection < -1) direction=-1;
		else if (newDirection != 0) direction=newDirection;

		preLoadPic(j);

		if (xIE4Up){
			document.images.MainImg.style.filter= "blendTrans(duration=crossFadeDuration)"
			document.images.MainImg.filters.blendTrans.Apply()
		}
		
		document.images.MainImg.src = preLoad[j].src
		if (xIE4Up){
			document.images.MainImg.filters.blendTrans.Play()
		}
				
		if (document.forms["GlobalForm"].PlayPause.value=='Pause') {
			t = setTimeout('runSlideShow(direction)', document.forms["GlobalForm"].PreviewTime.value)
		}
		
		k = j + newDirection;
		if (k > (Pic.length-1)) k=1;
		if (k < 1) k=Pic.length-1;
		preLoadPic(k);

	} else {
			clearTimeout(t);
	}
	
	InfoDiv = document.getElementById('PhotoInfo');
	InfoDiv.innerHTML='<table><tr><th style="width:1%; font-size:0.8em;">Image</th><th style="width:49%; font-size:0.8em;">Species</th><th style="width:1%; font-size:0.8em;">Photographer</th><th style="width:1%; font-size:0.8em;">Country</th></tr>'+
	'<td>'+Pic[j].PhotoID+'</td><td>' + Pic[j].CommonSpecies + ' (' + Pic[j].ScientificSpecies + ')</td>'+
	'<td>'+Pic[j].FirstName+'&nbsp;'+Pic[j].LastName+'</td><td>'+Pic[j].Country+'</td></tr></table>';
	document.forms["GlobalForm"].TaxonID.value=Pic[j].TaxonID;
	
}
