// Set Language Strings
// WordString = new Array("En","Sp");


// Scan Tags to Replace English Words & Graphics
// Will need to use string.replace()
// Put this below the translation selection
function scanTags() {
	alert(document.links.length);
	for (i=0; i < document.links.length; i++) {
		if (document.links[i].onmouseover) {
			alert(document.links[i].onmouseover);
		}
	}
	alert(document.images.length);
	for (i=0; i < document.images.length; i++) {
		if (document.images[i].alt) {
			alert(document.images[i].alt);
		}
		if (document.images[i].title) {
			alert(document.images[i].title);
		}
		if (document.images[i].src) {
			alert(document.images[i].src);
		}
	}
}

// Select Translation
// LangIndex: [0] = English, [1] = Spanish
var lang = location.href.split("?")[1];
if (!lang) {
	if ((document.referrer && document.referrer.indexOf('/CCSDSP/') != -1) || (window.opener && !window.opener.closed && window.opener.location.href.indexOf('/CCSDSP/') != -1)) {
		location.replace(location.href + "?sp");
	}
	else {
		location.replace(location.href + "?en");
	}
}
else {
	lang = decodeURI(lang);
}

LangIndex = 0;
if (lang == "sp") {
	LangIndex = 1;
}

if (albumTitle[LangIndex].length > 1) {
	albumTitle = albumTitle[LangIndex];
}
// End Select Translation

if (totalThumbs > imgSrc.length) {
	totalThumbs = imgSrc.length;
}
timeOutID = 0;			  
move = 0;

topThumb = p - centerThumb + 1;

beforeText = '<center><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>';
afterText = "</b></font></center>";
textMsg = '"Viewing " + p + " of " + imgSrc.length';

if (document.layers) {
	evaluateString = 'document.picture.src = rootDirectory + slideDirectory + imgSrc[p++];'
}
else if (document.getElementById) {
	evaluateString = 'document.getElementById("picture").src = rootDirectory + slideDirectory + imgSrc[p++];';
}
else if (document.all) {
	evaluateString = 'picture.src = rootDirectory + slideDirectory + imgSrc[p++];';
}

function firstThumbs(){
	for (var i=0; i < totalThumbs; i++) {
		if (i == centerThumb - 1) {
			document.write('<table width="100%" border="0" cellpadding="2" cellspacing="0" bgcolor="#000000"><tr><td><table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF" class="CenterThumb"><tr><td align="center">');
			document.write('<a href="javascript:showPicture(' + i + ');"><img name="thumb' + i + '" id="thumb' + i + '" src="' + rootDirectory + thumbDirectory + imgSrc[i] + '" vspace="4" hspace="4" border="0" onMouseOver="window.status=eval(\'this.alt\');return true"></a>');
			document.write('</td></tr></table></td></tr></table>');
		}
		else {
			document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="UpcomingThumb"><tr><td align="center">');
			document.write('<a href="javascript:showPicture(' + i + ');"><img name="thumb' + i + '" id="thumb' + i + '" src="' + rootDirectory + thumbDirectory + imgSrc[i] + '" vspace="4" hspace="4" border="0" onMouseOver="window.status=eval(\'this.alt\');return true"></a>');
			document.write('</td></tr></table>');
		}
	}
}

function newThumbs(){
	if (topThumb == imgSrc.length) {
		topThumb = 0;
	}
	else if (topThumb < 0) {
		topThumb = imgSrc.length + topThumb;
	}
	thumb = topThumb;
	for (var i=0; i < totalThumbs; i++) {
		if (thumb == imgSrc.length) {
			thumb = 0;
		}
		else if (thumb < 0) {
			thumb = imgSrc.length + thumb;
		}
		eval("document.thumb" + i + ".alt = 'Click here to load picture: " + imgSrc[thumb] + "'");
		eval("document.thumb" + i + ".title = 'Click here to load picture: " + imgSrc[thumb] + "'");
		eval("document.thumb" + i + ".src = '" + rootDirectory + thumbDirectory + imgSrc[thumb++] + "'");
	}
}

function nextImage() {
	topThumb = p - centerThumb + 1;
	if (showDescriptions == 1) {
		document.picture.alt = descSrc[p];
		document.picture.title = descSrc[p];
		window.defaultStatus = descSrc[p];
	}
	else {
		document.picture.alt = imgSrc[p];
		document.picture.title = imgSrc[p];
		window.defaultStatus = 'Currently Viewing: ' + imgSrc[p];
	}
	document.title = albumTitle + ' - Currently Viewing: ' + imgSrc[p];
	eval(evaluateString);
	if (showDescriptions == 1) {
		eval(DescriptionDisplay);
	}
	eval(textToShow);
	newThumbs();
	if (p == imgSrc.length) {
		p = 0;
	}
	if (autoNext == 1) {
		timeOutID = setTimeout("nextImage()", nextImgDelay);
	}
	eval(Status);
	eval(Speed);
}

function getStatus() {
	if (autoNext) {
		return ("Playing");
	}
	return ("Stopped");
}

function getSpeed() {
	seconds = nextImgDelay / 1000;
	if (autoNext) {
		speed = 11 - seconds;
	}
	else {
		speed = 0;
	}
	return ("Speed: " + speed);
}

function goSlower() {
	if (autoNext) {
		nextImgDelay = nextImgDelay + 500;
		if (nextImgDelay > 10000) {
			nextImgDelay = 10000;
		}
		eval(Speed);
	}
}

function goFaster() {
	if (autoNext) {
		nextImgDelay = nextImgDelay - 500;
		if (nextImgDelay < 1000) {
			nextImgDelay = 1000;
		}
		eval(Speed);
	}
}

function stopPlayback() {
	clearTimeout(timeOutID);
	autoNext = 0;
	eval(Status);
	eval(Speed);
}

function startPlayback() {
	stopPlayback();
	autoNext = 1;
	nextImage();
}

function thumbsUp() {
	stopPlayback();
	topThumb = topThumb - 1;
	newThumbs();
}

function thumbsDown() {
	stopPlayback();
	topThumb = topThumb + 1;
	newThumbs();
}

function advancePicture(){
	stopPlayback();
	nextImage();
}

function reversePicture(){
	stopPlayback();
	p = p - 2;
	if (p < 0) {
		p = imgSrc.length + p
	}
	nextImage();
}

function firstPicture(){
	stopPlayback();
	p = 0;
	nextImage();
}

function lastPicture(){
	stopPlayback();
	p = imgSrc.length - 1;
	nextImage();
}

function showPicture(imageNum){
	stopPlayback();
	p = topThumb + imageNum;
	if (p < 0) {
		p = imgSrc.length + p
	}
	else if (p >= imgSrc.length){
		p = p - imgSrc.length
	}
	nextImage();
}

function preloadPicture(){
	if (LoadNext <= imgSrc.length) {
		document.slidesArray[LoadNext] = new Image;
		document.slidesArray[LoadNext].src = rootDirectory + slideDirectory + imgSrc[LoadNext];
		document.thumbsArray[LoadNext] = new Image;
		document.thumbsArray[LoadNext].src = rootDirectory + thumbDirectory + imgSrc[LoadNext];
		LoadNext++;
		setTimeout("preloadPicture()",500);
	}
}

document.slidesArray = new Array(imgSrc.length);
document.thumbsArray = new Array(imgSrc.length);
LoadNext = 0;
setTimeout("preloadPicture()", 1500);

/* Old Functionality:

function preloadPictures(){ 
  document.slidesArray = new Array(imgSrc.length);
  document.thumbsArray = new Array(imgSrc.length);
  for(var i=0; i<imgSrc.length; i++) {
    document.slidesArray[i] = new Image;
    document.slidesArray[i].src = rootDirectory + slideDirectory + imgSrc[i];
    document.thumbsArray[i] = new Image;
    document.thumbsArray[i].src = rootDirectory + thumbDirectory + imgSrc[i];
  }
}

setTimeout("preloadPictures()", 2000);*/