<!--

// Slideshow code

var slideShowSpeed = "7000"; // Default slideShowSpeed (milliseconds)

var crossFadeDuration = 3; // Duration of crossfade (seconds)\

var t; // setTimer() result, required to clear the timer thereafter
var j = 0; // Counter of current image in the rotation

var imarr = new Array();  // Array to hold filenames 
var captions = new Array(); // Array to hold captions
var preLoad = new Array(); // Array to hold cache of the picture files

var immh = 400;
var immw = 1024;

// ALL PICTURES ARE ASSUMED TO BE 1024 W x 400 H.  If this changes, so must the above constants
// Load this script file LAST, in the <HEAD> section

var imdir = "Img/";
var i = 0;

imarr[i] = imdir + "Aerial_Panorama_a.jpg"; 
captions[i++] = "The <strong>Borgo Martano</strong>, nestled among 32 rolling hectares of meadows and woodlands, is an extraordinary compound of 13th-century medieval buildings offering extraordinary views of the verdant hills and sapphire skies of Umbria, a land of castles, fortified towns, ancient Roman thoroughfares, and exquisite cuisine in the heart of central Italy.";
imarr[i] = imdir + "Borgo_from_Afar_a.jpg";
captions[i++] = "Approaching the <strong>Borgo Martano</strong>, among the Umbrian hills.";
imarr[i] = imdir + "Borgo_Full_Front_2a.jpg";
captions[i++] = "At the entry to the <strong>Borgo Martano</strong> complex.";
imarr[i] = imdir + "Church_3a.jpg";
captions[i++] = "The medieval-era church, once the center of the village's spiritual life.  It has been desanctified in modern times.";
imarr[i] = imdir + "High_Street_View_a.jpg";
captions[i++] = "Multistory buildings line the ancient High Road.";
imarr[i] = imdir + "Borgo_from_SW_Mill_View-Fall_a.jpg";
captions[i++] = "A southwestern view of the <strong>Borgo Martano</strong>, including the ancient mill where medieval villagers' grain became flour.";
imarr[i] = imdir + "Church_and_Wall_a.jpg";
captions[i++] = "Numerous stone walls separate the village's terraces and levels.";
imarr[i] = imdir + "Coming_Home_a.jpg";
captions[i++] = "Steps lead through a doorway into one of the medieval homes.";
imarr[i] = imdir + "East_Arch_1a.jpg";
captions[i++] = "One of many archways, by day.";
imarr[i] = imdir + "Piazza-Peeking_Around_a.jpg";
captions[i++] = "Broad stone stairs approach the village piazza, surrounded by houses, the Palazzo, and the old church.";
imarr[i] = imdir + "Palazzo-Upper_Exterior.jpg";
captions[i++] = "The grand four-storey Palazzo.";
imarr[i] = imdir + "Palazzo_Doorway_a.jpg";
captions[i++] = "Approaching the entry to the Palazzo.";
imarr[i] = imdir + "Rim_Road_Houses.jpg";
captions[i++] = "Multistorey medieval houses overlook the northwestern rim road and wall of the village.";
imarr[i] = imdir + "Church-Front_from_Below_a.jpg";
captions[i++] = "The old church, now desanctified, a centerpiece of the village and its medieval life.";
imarr[i] = imdir + "Round_Bench_a.jpg";
captions[i++] = "This large yet intimate circular stone bench at the piazza affords stunning views of hills and valleys below.";
imarr[i] = imdir + "Round_Bench_View_a.jpg";
captions[i++] = "The surrounding countryside, as seen from the built-in circular bench at the village piazza.";
imarr[i] = imdir + "View-Todi_2a.jpg";
captions[i++] = "A view of the neighboring medieval-era town of Todi.";
imarr[i] = imdir + "View-Valley_1a.jpg";
captions[i++] = "A view into the lush valley below.";
imarr[i] = imdir + "View-Hills_1a.jpg";
captions[i++] = "A view of the hills and dales of surrounding Umbria.";
imarr[i] = imdir + "Wall_and_Olive_Trees_a.jpg";
captions[i++] = "One of the village walls, lined with olive trees.";
imarr[i] = imdir + "Copia_di_Arch-Fall_a.jpg";
captions[i++] = "One of many archways, at dusk.";
imarr[i] = imdir + "Grey_Alley_a.jpg";
captions[i++] = "Looking out upon one of many alley-ways, grey-lit in twilight.";
imarr[i] = imdir + "Sunset.jpg";
captions[i++] = "Sunset at the <strong>Borgo Martano</strong>.";

var p = imarr.length; // Number of files

preLoad[0] = new Image();
preLoad[0].src = imarr[0];

function gotopic(mv){ 
	// -2 = last, -1 = back, 0 = next, 1+ = nth.  Note j always = the next picture ID #, not the present one
	if (mv == -2) {
		j = p - 1;
	}
	else if (mv == -1) {
		j = (p + j - 2) % p; 
	}	
	else if (mv == 0) {
		j = j; //do nothing
	}
	else { 
		j = (mv + p - 1) % p; 
	}
	
	// Prefetch an image we haven't already cached
    if (preLoad[j] == null){
		preLoad[j] = new Image();
		preLoad[j].src = imarr[j];
	}
		
	document.images.SlideShow.src = preLoad[j].src;
	
	// Auto-resize the picture based on screen size (this has effect only the first time through)
	resizeimm();
	
   if (document.getElementById){
   	  document.getElementById("CaptionBox").innerHTML = captions[j] + '<br><br>';
	  var pagenumstr = '<a href="#" onclick="gotopic(1);"> ';
	  if (j == 0) {
	  	    pagenumstr = pagenumstr + '<strong><font color="#CC9900">1</font></strong>';
			}
	  else {
	  	    pagenumstr = pagenumstr + '1';
			}
	  pagenumstr = pagenumstr + '</a> ';
	  for (var i = 2; i < p; i++) {
	  	  pagenumstr = pagenumstr + '<a href="#" onclick="gotopic(' + i + ');">';
		  if (j == (i-1)) {
				pagenumstr = pagenumstr + '<strong><font color="#CC9900">' + i + '</font></strong>';
				}
		  else {
				pagenumstr = pagenumstr + i;
				}
		  pagenumstr = pagenumstr +  '</a> ';
		  }
	  pagenumstr = pagenumstr + '<a href="#"  onclick="gotopic(' + (p-1) + ');">';	  
      if (j == (p-1)) {
	  	    pagenumstr = pagenumstr + '<strong><font color="#CC9900">' + p + '</font></strong> </a>';
			} 
	  else {
	  	    pagenumstr = pagenumstr + p + ' </a>';
			}
	  
      document.getElementById("Pagenums").innerHTML = pagenumstr;

   }  

   slideShowSpeed = "120000"; // Timer will resume after a very healthy delay this way
   t = clearTimeout(t);
   t = setTimeout('runSlideShow(false)', slideShowSpeed); // Massively slow down the slideshow if user has intervened
   j = (j + 1) % p;
   
   	// Prefetch expected next image if it isn't already cached
    if (preLoad[j] == null){
		preLoad[j] = new Image();
		preLoad[j].src = imarr[j];
	}

}	
  
function runSlideShow(restart){
   var w, h, wmax, hmax;
   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)";
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.SlideShow.filters.blendTrans.Apply();   
   }

	if (restart) {
		j = 0;
		}
		
	// Fetch the image if it isn't already cached		
    if (preLoad[j] == null){
		preLoad[j] = new Image();
		preLoad[j].src = imarr[j];
	}
		
   document.images.SlideShow.src = preLoad[j].src;

// Auto-resize the picture based on screen size (this has effect only the first time through)
	resizeimm();
	
	// Update caption and the visual slide counter
   if (document.getElementById){
   	  document.getElementById("CaptionBox").innerHTML = captions[j] + '<br><br>';
	  var pagenumstr = '<a href="#" onclick="gotopic(1);"> ';
	  if (j == 0) {
	  	    pagenumstr = pagenumstr + '<strong><font color="#CC9900">1</font></strong>';
			}
	  else {
	  	    pagenumstr = pagenumstr + '1';
			}
	  pagenumstr = pagenumstr + '</a> ';
	  for (var i = 2; i < p; i++) {
	  	  pagenumstr = pagenumstr + '<a href="#" onclick="gotopic(' + i + ');">';
		  if (j == (i-1)) {
				pagenumstr = pagenumstr + '<strong><font color="#CC9900">' + i + '</font></strong>';
				}
		  else {
				pagenumstr = pagenumstr + i;
				}
		  pagenumstr = pagenumstr +  '</a> ';
		  }
	  pagenumstr = pagenumstr + '<a href="#"  onclick="gotopic(' + (p-1) + ');">';	  
      if (j == (p-1)) {
	  	    pagenumstr = pagenumstr + '<strong><font color="#CC9900">' + p + '</font></strong> </a>';
			} 
	  else {
	  	    pagenumstr = pagenumstr + p + ' </a>';
			}
	  
      document.getElementById("Pagenums").innerHTML = pagenumstr;

   }  
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play();
   }
   j = (j + 1) % p;
   slideShowSpeed = "7000"; // Reset this here; may have been changed by gotopic()
   t = clearTimeout(t);
   t = setTimeout('runSlideShow(false)', slideShowSpeed);

   	// Prefetch expected next image if it isn't already cached
    if (preLoad[j] == null){
		preLoad[j] = new Image();
		preLoad[j].src = imarr[j];
	}

}

function resizeimm(){

   w = document.images.SlideShow.width < immw ? immw : document.images.SlideShow.width;
   h = document.images.SlideShow.height < immh ? immh : document.images.SlideShow.height;
   
   if (self.innerWidth)
	{
		wmax = self.innerWidth;
		hmax = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		wmax = document.documentElement.clientWidth;
		hmax = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		wmax = document.body.clientWidth;
		wmax = document.body.clientHeight;
	}
	else {
		wmax = screen.width;
		hmax = screen.height;
	}
   
   hmax = (hmax * 3) / 4; // Max height of an image = 3/4 of screen
   wmax = (wmax * 9) / 10; // Max width of an image = 80% of screen

	if (w > wmax) {
	   h = wmax * h / w;
	   w = wmax;
	}
	if (h > hmax) {
	   w = hmax * w / h;
	   h = hmax;
	}	  
	
 	document.images.SlideShow.width = w;
	document.images.SlideShow.height = h;
	
}


-->
