var curImg = 0;
var timerId = -1;
var secTimerId = -1;
var interval = 6000;
var secInterval = interval / 1000;
var currSec = secInterval;
var copyType = "";
var isPlaying = 1;
function replaceNum()
{
 var input = SHOWINGSTRING;
 var output = input;
 var idx = output.indexOf("%slideNum");
 if (idx > -1) {
 output = input.substring(0, idx);
 output += eval(curImg+1);
 output += input.substr(idx+9);
 }
 return output;
}
function changeSpeed()
{
 var sidx = document.forms[0].speedMenu.selectedIndex;
 var speed = document.forms[0].speedMenu.options[sidx].value;
 interval = speed;
 secInterval = interval / 1000;
 if (timerId != -1) {
 clearTimers();
 }
 play();
}
function imgLoadNotify()
{
 if (isPlaying == 1)
 setTimers();
}
function changeSlide()
{
 var width = a_width[curImg];
 var height = a_height[curImg];
 if (timerId != -1) {
 clearTimers();
 dispLoading();
 }
 var tableWidth = ( width < 400 || height > 400 ) ? 650 : width;
 var html = "<center><table width=" + tableWidth + " cellpadding=3 cellspacing=0 border=0><tr><td valign=top>" +
 "<img src=" + a_src[curImg] + " alt=\"photo\" width=" + width +
 " height=" + height + " border=1 onload=\"imgLoadNotify();\">";
 if ( width < 400 || height > 400 ) {
 html += "</td><td valign=top>";
 } else {
 html += "<br>";
 }
 html += "<font face=arial size=+1>" + a_cap[curImg] + "</font><br><span class=\"ysptimedate\">" + a_credit[curImg] + "</span></td></tr></table></center>";
 var pnumLine = "<font face=arial size=-1>";
 pnumLine += replaceNum();
 pnumLine += "</font>";
 var htmlTs = a_ts[curImg];
 var htmlCopy = (a_copy[curImg] == "ap") ? "Copyright &copy; 2003 The Associated Press. All rights reserved. The information contained in the AP News report may not be published, broadcast, rewritten or redistributed without the prior written authority of The Associated Press.<br>" : "Copyright &copy; 2003 Reuters Limited. All rights reserved. Republication or redistribution of Reuters content is expressly prohibited without the prior written consent of Reuters. Reuters shall not be liable for any errors or delays in the content, or for any actions taken in reliance thereon.";
 switch(navigator.family) {
 case 'gecko':
 document.getElementById("imgDiv").innerHTML = html;
 document.getElementById("pnumDiv").innerHTML = pnumLine;
 document.getElementById("tsDiv").innerHTML = htmlTs;
 break;
 case 'nn4':
 document.layers[2].document.imgDiv.document.open();
 document.layers[2].document.imgDiv.document.write(html);
 document.layers[2].document.imgDiv.document.close();
 document.layers[0].document.pnumDiv.document.open();
 document.layers[0].document.pnumDiv.document.write(pnumLine);
 document.layers[0].document.pnumDiv.document.close();
 document.layers[3].document.tsDiv.document.open();
 document.layers[3].document.tsDiv.document.write(htmlTs);
 document.layers[3].document.tsDiv.document.close();
 break;
 case 'ie4':
 document.all.pem.innerHTML = pnumLine;
 document.all.imgp.innerHTML = html;
 document.all.tstxt.innerHTML = htmlTs;

 break;
 }
 reloadAds();
}
function forward()
{
 curImg++;
 if (curImg == numImgs)
 curImg = 0;
 changeSlide();
}
function rewind()
{
 curImg--;
 if (curImg < 0)
 curImg = numImgs - 1;
 changeSlide();
}
function dispSec()
{
 var dispSec = ( currSec < 0 ) ? 0 : currSec;
 var secText = "<font face=arial color=green size=-2>Siguiente foto en " + dispSec + " seg</font>";
 switch(navigator.family) {
 case 'gecko':
 document.getElementById("timerDiv").innerHTML = secText;
 break;
 case 'nn4':
 document.layers[1].document.timerDiv.document.open();
 document.layers[1].document.timerDiv.document.write(secText);
 document.layers[1].document.timerDiv.document.close();
 break;
 case 'ie4':
 document.all.timer.innerHTML = secText;
 break;
 }
 currSec--;
}
function dispLoading()
{
 var text = "<font face=arial color=green size=-2>Cargando foto...</font>";
 switch(navigator.family) {
 case 'gecko':
 document.getElementById("timerDiv").innerHTML = text;
 break;
 case 'nn4':
 document.layers[1].document.timerDiv.document.open();
 document.layers[1].document.timerDiv.document.write(text);
 document.layers[1].document.timerDiv.document.close();
 break;
 case 'ie4':
 document.all.timer.innerHTML = text;
 break;
 }
}
function stop()
{
 clearTimers();
 isPlaying = 0;
 var secText = "<font face=arial color=red size=-2>Slideshow detenido</font>";
 switch(navigator.family) {
 case 'gecko':
 document.getElementById("timerDiv").innerHTML = secText;
 break;
 case 'nn4':
 document.layers[1].document.timerDiv.document.open();
 document.layers[1].document.timerDiv.document.write(secText);
 document.layers[1].document.timerDiv.document.close();
 break;
 case 'ie4':
 document.all.timer.innerHTML = secText;
 break;
 }
 document.playbtn.src = buttonImgPfx + buttonOffArray[0];
 document.stopbtn.src = buttonImgPfx + buttonOnArray[1];
}
function play()
{
 setTimers();
 startShow();
}
function startShow()
{
 isPlaying = 1;
 document.playbtn.src = buttonImgPfx + buttonOnArray[0];
 document.stopbtn.src = buttonImgPfx + buttonOffArray[1];
}
function setTimers()
{
 currSec = secInterval;
 dispSec();
 if (secTimerId == -1)
 secTimerId = window.setInterval('dispSec();', 1000);
 if (timerId == -1)
 timerId = window.setInterval('forward();', interval);
}
function clearTimers()
{
 window.clearInterval(timerId);
 timerId = -1;
 window.clearInterval(secTimerId);
 secTimerId = -1;
}
function setButton(direction)
{
 if (direction == 0) {
 document.prevbtn.src = buttonImgPfx + buttonOnArray[2];
 window.setTimeout("document.prevbtn.src = buttonImgPfx + buttonOffArray[2];", 300);
 } else {
 document.fowdbtn.src = buttonImgPfx + buttonOnArray[3];
 window.setTimeout("document.fowdbtn.src = buttonImgPfx + buttonOffArray[3];", 300);
 }
}
