var countPanoramas; 
var curPano = 0;
var showingPanos = 1;
var preloaded = new Array();
var panoImages = new Array();
var panoCaptions = new Array();
function preload_images() {
	countPanoramas = 0;
    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
		panoImages[countPanoramas] = arguments[i];
		i++;
		panoCaptions[countPanoramas] = arguments[i];
		countPanoramas++;
    };
};
// This defines the set of files, each one along with its "caption" that will
// be displayed in the masthead.
preload_images(
    'images/Pano-1024/pano-5078-to-5092-OceanView-15pix-1024x100.jpg', 
		'<i>Ocean View in June</i>, Little Compton, Rhode Island',
    'images/Pano-1024/pano-Boston-theCharles-Zakim-8pix-rotate-1024x100.jpg', 
		'<i>Beacon Hill and Zakim Bridge</i> from the Charles River, Boston, Mass.',
    'images/Pano-1024/pano-EarlyMorningAroundCBC-Pond-20pix-1024x100.jpg', 
		'Clara Barton Center Pond, North Oxford, Mass.',
    'images/Pano-1024/pano-EspressoRoyaleCaffe-at-NEU-6pix-1024x100.jpg', 
		'<i>Espresso Royale Caffe</i>, Northeastern University, Boston, Mass.',
    'images/Pano-1024/pano-FoliageAndCows1cGibbetHillGrotonMa-22pix-1024x100.jpg', 
 		'<i>New England Fall Foliage</i>, Gibbet Hill, Groton, Mass.',
    'images/Pano-1024/pano-HarvardUniversity-HavahaadYaad900-27pix-1024x100.jpg', 
 		'<i>New England Fall</i>&nbsp; in Harvard Yard, Cambridge, Mass.',
    'images/Pano-1024/pano-MDI-SoM-The-Structah-19pix-1024x100.jpg',  
 		'&ldquo;<i>The Structah&rdquo;, a Place for men</i>, Poland, Maine',
    'images/Pano-1024/pano-NewEnglandFallFoliage3a-inVT-17pix-1024x100.jpg', 
 		'<i>New England Fall Foliage</i>, Vermont',
    'images/Pano-1024/pano-not3670-3673-StJacobsMarket2-20pix-1024x100.jpg', 
 		'<i>Mennonite Farmers\' Market</i>, St Jacobs, Ontario',
    'images/Pano-1024/pano-OceanView180-18pix-1024x100.jpg', 
 		'<i>Grassy Meadow Ocean View</i>, Little Compton, RI',
    'images/Pano-1024/pano-InsideTheCafe-Groton-25pix-1024x100.jpg', 
 		'<i>The Caf&eacute;, in an Antique Store</i>, Groton, Mass.',
    'images/Pano-1024/pano-Quad-inFront-of-Maple-23pix-1024x100.jpg', 
 		'<i>Quad in front of Maple</i>, Roger Williams University, RI',
    'images/Pano-1024/pano-RockportStoneQuarry2-6pix-1024x100.jpg', 
 		'<i>Stone Quarry by the Ocean</i>, Rockport, Massachusetts',
    'images/Pano-1024/pano-RogerWilliams-breakfastTent-14pix-1024x100.jpg', 
 		'<i>Convocation Breakfast Tent</i>, Roger Williams University, Bristol, RI',
	'images/Pano-1024/pano-backYard-nearSpring5-11pix-1024x100.jpg', 
		'<i>Waiting for Spring</i>, backyard in Groton, Mass.',
    'images/Pano-1024/pano-Rookery2inWinter-19pix-1024x100.jpg', 
 		'<i>Great Blue Herron Rookery in Winter</i>, Acton, Mass.',
    'images/Pano-1024/pano-RowePond-Sat-am-24pix-1024x100.jpg', 
 		'<i>Pond au Centre Ville</i>, Rowe, Mass.',
    'images/Pano-1024/pano-underTheBigWhiteTent-14pix-1024x100.jpg', 
 		'<i>Celebration Under The Big White Tent</i>, Little Compton, Rhode Island',
    'images/Pano-1024/pano-WaterFirePark-7pix-1024x100.jpg', 
 		'<i>WaterFire Park at Dusk</i>, Providence, RI'
);
var kgpDbg; kgpDbg = 0;
    if( kgpDbg > 0 ) alert("(kgpDebug) kgpDbg=" + kgpDbg);

    function showDataOnLoad() {
		// kk 
		alert("onLoad.showData: got " + countPanoramas + " images");
    }
    function doShowHidePanos() {
		// kk alert("onClick.doShowHidePanos: got " + countPanoramas + " images");
		var holdsPanoImages = document.getElementById('PanoPixDisplayCycle'); 
		var holdsDmmMasthead = document.getElementById('dmmMasthead'); 
		// kk1 alert("onClick.doShowHidePanos: holdsDmmMasthead.style.display = " + holdsDmmMasthead.style.display);
		// This is a str8forward flip/flop
	    if (showingPanos == 1) { 
            showingPanos = 0; 
			holdsPanoImages.style.visibility = "hidden";
			// kk1 holdsDmmMasthead.style.display = "none"; 		// document.body.style.display = 'none';
			var redrawFix = holdsPanoImages.offsetHeight;
			holdsPanoImages.style.display = "none"; 
        }
		else {
			holdsPanoImages.style.visibility = "visible";
			showingPanos = 1;
			holdsPanoImages.style.display = "inline";
		}
    }

    function switchToPano(ix) {
		// kk 
		if( kgpDbg > 0 ) alert("switchToPano: wrt Index = " + ix );
//kgPRE-begin
//kgPRE-        var puke = preloaded[ix].getAttribute('src');
//kgPRE-		if( kgpDbg > 0 ) alert("switchToPano: wrt .src = " + puke );
//kgPRE-end
		var holdsPanoCaption = document.getElementById('PanoCaption');
		// showInCaptionField = "PanoramA &mdash; " + panoCaptions[ix] + "&nbsp;&nbsp;&nbsp; <INPUT TYPE=\"button\" id=\"btnShowHidePanos\" VALUE=\"X\" onClick=\"javascript:doShowHidePanos()\" >&nbsp; &nbsp;";
		var showInCaptionField = "tbs";
	    if (showingPanos == 1) { 
			//kk 67 showInCaptionField = "Panoram &mdash; " + panoCaptions[ix] + "&nbsp;&nbsp;&nbsp; <INPUT TYPE=\"image\" title=\"pano be gone\" id=\"btnShowHidePanos\" src=\"Icons/KillPanoDisplay-21x18.jpg\" width=\"21\" height=\"18\" onClick=\"javascript:doShowHidePanos()\" >&nbsp; &nbsp;";
			showInCaptionField = "Panorama &mdash; " + panoCaptions[ix] + "&nbsp;&nbsp;&nbsp; <INPUT TYPE=\"button\" id=\"btnShowHidePanosNo\" VALUE=\"X\"  title=\"Click to remove Panorama Animation\" onClick=\"javascript:doShowHidePanos()\" > &nbsp;";
        }
		else {
			showInCaptionField = "Enable panorama animation &nbsp;&nbsp; <INPUT TYPE=\"button\" id=\"btnShowHidePanosYes\" VALUE=\"?\"  title=\"Show Panorama Animation in masthead\" onClick=\"javascript:doShowHidePanos()\" >&nbsp; &nbsp;";
		}
		holdsPanoCaption.innerHTML = showInCaptionField;
		//css holdsPanoCaption.style.textAlign="right";
		var holdsPanoImage = document.getElementById('curPanoImage');
		//kgPRE-be4 var	pixURL = "images/Pano-1024/" + panoImages[ix];
		var	pixURL = panoImages[ix];
		// kk holdsPanoImage.innerHTML = pixURL; width="1024" width="1000" 
		holdsPanoImage.innerHTML = '<img src="' + pixURL + '" height="100" />';
    }
    function showData() {
		// kk alert("onClick.showData: curPano = " + curPano );
		container1.innerHTML = "yet2do";
		var container2 = document.getElementById('curPanoIX');
		container2.innerHTML = curPano;
		// kk alert("onLoadDD.showData: got " + countPanoramas + " images");
	    // kk for (var i = 0; i < countPanoramas; i++) {
 		// kk 	alert("showData.Image[ " + i + "] : " + panoImages[i] + " || " + panoCaptions[i]);
	    // kk };
		switchToPano(curPano);
		curPano++;
		// kk alert("onClick.showData: got " + countPanoramas + " Images + Captions.");
	    if (curPano >= countPanoramas) { 
            curPano = 0; // Cycle around; go to the first one.
        }
    }
    function nextPano() {
		// kk alert("onClick.nextPano: curPano = " + curPano );
		var container2 = document.getElementById('curPanoIX'); 
		container2.innerHTML = curPano;
		switchToPano(curPano);
		curPano++;
		// kk alert("onClick.snextPano: got " + countPanoramas + " Images + Captions.");
	    if (curPano >= countPanoramas) { 
            curPano = 0; // Cycle around; go to the first one.
        }
    }
    function prevPano() {
		var container7 = document.getElementById('curPanoIX'); 
		container7.innerHTML = curPano;
		curPano--;
		// kk alert("onClick.prevPano: got " + countPanoramas + " Images + Captions.");
	    if (curPano < 0) { 
            curPano = countPanoramas -1; // Cycle around; go to the last one.
        }
		// kk alert("onClick.prevPano: curPano = " + curPano );
		switchToPano(curPano);
    }
	var panoIntervalMillieSex = 5000; // dkdk 4200
	// We're only supposed to do this once
    function setupAutoMagic() {
		// kk alert("setupAutoMagic curInterval " + curInterval + " ...");
		switchToPano(curPano);
		setInterval("nextPanoGoingForwards()",panoIntervalMillieSex);
    }
	// Make the transition from "the last" Pano to the next one, including wrap-around.
    function nextPanoGoingForwards() {
		// kk alert("nextPanoGoingForwards: curPano " + curPano + " ...");
		curPano++;
	    if (curPano >= countPanoramas) { 
            curPano = 0;
        }
		switchToPano(curPano);
    }
