﻿// JScript File
var which=0;
var TOI;
var myimages=new Array();
for (i=0;i<photos.length;i++){
myimages[i]=new Image();
myimages[i].src=photos[i];
}

var prv=document.getElementById("btnprev");
var next=document.getElementById("btnnext");
/*if(which==0){
prv.style.display="none";
}
if(photos.length==1){
next.style.display="none";
}
*/
slideshow();
function backward(){
endSlideshow();
if (which>0){
//window.status='';
which--;

FadeInImage('photoSlide',photos[which],'photoWrap');

document.images.photoSlide.src=photos[which];
document.images.photoSlide.alt=captions[which];
var current=which + 1;
document.getElementById("imageinfo").innerHTML="<p>" + current + " of " + photos.length + "</p>";
next.style.display="";
}
if(which==0){
    which=photos.length;
    backward()
//prv.style.display="none";
}
}

function forward(){
endSlideshow();
if (which<photos.length-1){
which++;

FadeInImage('photoSlide',photos[which],'photoWrap');

document.images.photoSlide.src=photos[which];
document.images.photoSlide.alt=captions[which];
var current=which + 1;
document.getElementById("imageinfo").innerHTML="<p>" + current + " of " + photos.length + "</p>";
//prv.style.display="";
}
else{
//if(which==photos.length-1){
    which=-1;
    forward();
 //next.style.display="none";
}
//else window.status='End of gallery'
}

function startSlideshow(){
  if (which<photos.length-1){
    which++;
    
    FadeInImage('photoSlide',photos[which],'photoWrap');
    
    document.images.photoSlide.src=photos[which];
    document.images.photoSlide.alt=captions[which];
    
       
    var current=which + 1;
    document.getElementById("imageinfo").innerHTML="<p>" + current + " of " + photos.length + "</p>";
    prv.style.display="";
    }
    if(which==photos.length-1){
        which=-1;
     //next.style.display="none";
    }
}

function endSlideshow(){
document.getElementById("slideshowControl").src="/travel/images/play.gif";
    clearInterval (TOI);
TOI=null;
}
function slideshow(){
    
    var image=document.getElementById("slideshowControl");
    var imageName=image.src;
    imageName=imageName.substr(imageName.lastIndexOf("/")+1);
//alert(imageName);
    
    if(imageName=="play.gif"){
        image.src="/travel/images/pause.gif";
        //alert(image.src);
        //forward();
        if(TOI==null){
            TOI=setInterval ("startSlideshow()",4000);
        }
    }
    else{
        //image.src="/travel/images/play.gif";
        endSlideshow();
    }
    
}





function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) 
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}
function FadeIn(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
}
function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      background.style.backgroundImage = 'url(' + foreground.src + ')';
      background.style.backgroundRepeat = 'no-repeat';
    }
  }
  SetOpacity(foreground,0);
  foreground.src = newImage;
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10);
}

