// ShowSlides.js
// Version 1.9 27Dec08
// Copyright M.J.C. Griffin, with grateful acknowledgement to Fitz, from www.CodeLifter.com

// Specify variables

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 10000;

// Duration of crossfade (seconds)
var crossFadeDuration = 3;
var tim; 	
var current = 0;
var preLil = new Array();
var preLoad = new Array();
var preButtons = new Array();
var link = "";
var inplay = 0;
var photoAd = zoom[0];
var prevORnext = 0;
var found = 0;
var str = " ";
var winName = " ";
var FirstCaption="Once a map is visible to the left, you can either click on placenames on it to see each place individually, or click the 'Play' button to run a slideshow of places to visit around the gite. You can pause the show at any time, and use the '|<' and '>|' buttons to go back and forth. To visit a website about the place on view, simply click on the 'Visit website' panel. This will display that website in a new window. Click on the slide if you want to enlarge the picture in a new window. If there is a video available of the place on view, a 'View Video' button will appear below. Clicking this button will show the video, in a new window. There will be a short delay before the video starts to play. Do NOT click the 'View Video' button unless you have high-speed Internet access, though! For Help with this page at any time, click on the '?' button on the control panel below.";


ua = navigator.userAgent.toLowerCase(); // Opera objects to filters and stops parsing any function ... 
opera = (ua.indexOf("opera")     != -1); // ...  referencing filters !

function loadSlides(){
	 preButtons[0]= new Image();
	 preButtons[0].src = './Images/Buttons/SlideshowControls/play_HI.png';
	 preButtons[1]= new Image();
	 preButtons[1].src = './Images/Buttons/SlideshowControls/back_HI.png';
	 preButtons[2]= new Image();
	 preButtons[2].src = './Images/Buttons/SlideshowControls/next_HI.png';
	 preButtons[3]= new Image();
	 preButtons[3].src = './Images/Buttons/SlideshowControls/help_HI.png';
	 	 
   for (i = 0; i < piclength; i++) {preLoad[i] = new Image();preLoad[i].src = pic[i];
   if (document.images.Tiny.complete) {document.images.Tiny.src = preLoad[i].src}; }
   if (Castles == 1) {loadLilSlides();}
//   doSlide(0,'./Slides/Welcome.gif',FirstCaption,"","","");
}

function loadLilSlides(){
   for (i = 0; i < piclength; i++) {preLil[i] = new Image();preLil[i].src = lil[i];}
}

function fromMap(found,pic_src,cap_text,zoom_url,webAd_url,vidAd_url){
//   find(str);
   if (found == 0){window.alert("No information loaded for "+str);}
   else if (inplay) {stop()}
   doSlide(found,pic_src,cap_text,zoom_url,webAd_url,vidAd_url)
   current = found
}

function doSlide(found,pic_src,cap_text,zoom_url,webAd_url,vidAd_url){

// document.write(found,pic_src,cap_text,zoom_url,webAd_url,vidAd_url);

   fadeOut()
   document.images.SlideArea.src = pic_src;
   fadeIn()
   if (document.images.SlideArea.complete) {document.forms[0].CapArea.value = cap_text;}
   photoAd = zoom_url;
   link=webAd_url;
   vid=vidAd_url;
   if (webAd_url==""){document.images.VisitWeb.src ='./Images/Buttons/SlideshowControls/visitWeb_OFF.png';} 
   else {document.images.VisitWeb.src ='./Images/Buttons/SlideshowControls/visitWeb_ON.png';
	 document.images.VisitWeb.alt ='Click here to visit related website';}
	 if (Castles == 1){doLilSlide(found)};
   if (vid!="") doVideoButton(); else doBlankButton();
}

function doVideoButton() {
	 document.images.ShowVideo.src = './Images/Buttons/SlideshowControls/viewVideo_ON.png';
   document.images.ShowVideo.alt = 'Click here to play video in a new window';
}

function doBlankButton() {
	 document.images.ShowVideo.src = './Images/Buttons/SlideshowControls/viewVideo_OFF.png';
   document.images.ShowVideo.alt = '';
}

function viewVideo_OFF() {
	 if (vid!="") { openVarWin(vid,'vidWin','370','320'); }
}

function doLilSlide(x){
   fadeOutLil()
   document.images.LittleSlideArea.src = preLil[x].src;
   fadeInLil()
}

function incCurrent(){
   current = current + 1
   if (current > (piclength-2)) current = 1    
}   

function decCurrent(){
   current = current - 1
   if (current==0) current = piclength-2   
} 

function play(){
   if (inplay==0){
   document.images.stop.src = './Images/Buttons/SlideshowControls/On.png';
   inplay = 1;runSlideShow();}
}   

function stop(){
   inplay = 0
   clearTimeout(tim)
   document.images.stop.src = "./Images/Buttons/SlideshowControls/Off.png";
   document.images.play.src = './Images/Buttons/SlideshowControls/play.png';
}   

function runSlideShow(){
   next();
   tim = setTimeout('runSlideShow()', slideShowSpeed)
}

function visitWeb_OFF(){
   if (link=="") {if ((sn[current]==" ") || (inplay)) {msg="Sorry - I can find no website for that location"} else msg="Sorry - I can find no website for "+sn[current]; window.alert(msg);}
   else window.open(link,"newLink"+current,"width=800, height=550, toolbar=no, status=no,scrollbars=yes, resizable=yes,left=100,top=50,screenX=100,screenY=50");
}

function help(){window.open("SlideHelp.php","hwin","width=680, height=640, toolbar=no, status=no, resizable=yes,left=100,top=50,screenX=100,screenY=50");}

function zoomPhoto(){if (current==0) {window.alert("Normally clicking here will take you to another page in a new window, but there is no enlargement of this title slide! Click on 'Play' to start the slideshow - or on a placename on the map.")}
   else if (photoAd == " ") {window.alert("Sorry! There is no larger version of this picture.")}
   else if (Castles == 1) {winName = "new"+current; window.open(photoAd,winName,'scrollbars=yes,width=830,height=600,resizable=yes,left=100,top=50,screenX=100,screenY=50')}
   else {winName = "new"+current; window.open(photoAd,winName,'scrollbars=yes,width=830,height=600,resizable=yes,left=100,top=50,screenX=100,screenY=50')};
}

function back(){
   if (inplay) {stop();}
   current = current - 1 
	 decCurrent(); 
   if (current >= 1) {doSlide(current,pic[current],cap[current],zoom[current],webAd[current],vidAd[current]);} else {last();}
}

function next(){
   incCurrent();doSlide(current,pic[current],cap[current],zoom[current],webAd[current],vidAd[current]);
}

function first(){current = 1;doSlide(current,pic[current],cap[current],zoom[current],webAd[current],vidAd[current]);}

function last(){current = piclength-1;doSlide(current,pic[current],cap[current],zoom[current],webAd[current],vidAd[current]);}

function find(string){
   found = 0
   for (i = 0; i < piclength; i++) 
   if (string == sn[i]) {found = i;}
}

function doLotMap(){
   if (Castles==1) {document.images.MapArea.src = './Images/LotMapCastles.gif'} 
   else {document.images.MapArea.src = './Images/LotMapPlaces.gif'}
   MapLoaded = 1;
}

function openVarWin(add,name,w,h){window.open(add,name,'width='+w+',height='+h+',directories=no,location=no,menubar=no,titlebar=no,scrollbars=no,toolbar=no,status=no,resizable=no, left=100,top=50,screenX=100,screenY=50');}

function fadeOut(){
   if ( (document.all)&&(!opera) ) {
      document.images.SlideArea.style.filter="blendTrans(duration=2)"
      document.images.SlideArea.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideArea.filters.blendTrans.Apply()}
}

function fadeIn(){
   if ( (document.all)&&(!opera) ) {
      document.images.SlideArea.filters.blendTrans.Play()}
}

function fadeOutLil(){
   if ( (document.all)&&(!opera) ) {
      document.images.LittleSlideArea.style.filter="blendTrans(duration=2)"
      document.images.LittleSlideArea.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.LittleSlideArea.filters.blendTrans.Apply()}
}

function fadeInLil(){
   if ( (document.all)&&(!opera) ) {
      document.images.LittleSlideArea.filters.blendTrans.Play()}
}
