
// A slide to show.
function Slide(pSrc, pAlt, pWidth, pHeight) {

    this.mSrc    = pSrc;
    this.mAlt    = pAlt;
    this.mWidth  = pWidth;
    this.mHeight = pHeight;

    this.mImage = new Image(pWidth, pHeight);
    this.mImage.src = pSrc;

} // class Slide


// A show-er of slides:
function SlideShow() {

    // The array of slides.
    this.mSlides = new Array();

    // The id of the element containing the images to show:
    this.mScreenId = "slideScreen";

    // The id of the element containing the slide legend:
    this.mLegendId = "slideLegend";

    // The id of the element containing the slide title:
    this.mTitleId = "slideTitle";

    // Current slide number (0-based):
    this.mSlideNum = 0;



    // Adds a new slide to the end of the show.
    this.addSlide = function(pSlide) {
	this.mSlides.push(pSlide);
    }

    // Adds a new slide to the end of the show.
    this.addImage = function(pSrc, pAlt, pWidth, pHeight) {
	this.addSlide(new Slide(pSrc, pAlt, pWidth, pHeight));
    }

    // Sets the element where the slides will be rendered.
    this.setScreenId = function(pElemId) {
	this.mScreen = document.getElementById(pElemId);
    }

    // Returns the number of slides:
    this.numSlides = function() {
	return this.mSlides.length;
    }

    // Display the nth (0-based) slide:
    this.showSlide = function(pNum) {

	// Adjust:
	var vTotal = this.numSlides();
	pNum = ((vTotal+pNum) % vTotal);

	// Show:
	var vSlide = this.mSlides[pNum];
	document.getElementById(this.mLegendId).innerHTML =
	    "(Slide " + (pNum + 1) + " of " + vTotal + ")"
	    ;
	document.getElementById(this.mScreenId).innerHTML =
	    "<img src=\"" + vSlide.mSrc + "\" "
	    +    "alt=\"" + vSlide.mAlt + "\" "
	    +    "width=\"" + vSlide.mWidth + "\" "
	    +    "height=\"" + vSlide.mHeight + "\" "
	    + "/>"
	    ;
	document.getElementById(this.mTitleId).innerHTML =
	    vSlide.mAlt;
	    ;

	// Set current:
	this.mSlideNum = pNum;
    }

    // Navigate:
    this.showFirst = function() {
	this.showSlide(0);
    }

    this.showPrev = function() {
	this.showSlide(this.mSlideNum - 1);
    }

    this.showNext = function() {
	this.showSlide(this.mSlideNum + 1);
    }



} // class SlideShow


// Create an inverted index into the site pages:
var gSitePagez = new Array();
for (var i = 0; i < gSitePages.length; i++) {
    var vURI = gSitePages[i];
    gSitePagez[vURI] = i;
    gSitePagez[vURI + "/"] = i;
}

// Go to the previous page of the site:
function EryqFirst(pURI) {
    this.location.href = gSitePages[0];
}

// Go to the last page of the site:
function EryqLast(pURI) {
    this.location.href = gSitePages[gSitePages.length - 1];
}

// Go to the previous page of the site:
function EryqPrev(pURI) {
    var vIndex = gSitePagez[pURI];
    if (vIndex == null) {
	return false;
    }
    var vPrevIndex = (gSitePages.length + vIndex - 1) % gSitePages.length;
    var vPrev = gSitePages[vPrevIndex];
    this.location.href = vPrev;
}

// Go to the next page of the site:
function EryqNext(pURI) {
    var vIndex = gSitePagez[pURI];
    if (vIndex == null) {
	return false;
    }
    var vNextIndex = (gSitePages.length + vIndex + 1) % gSitePages.length;
    var vNext = gSitePages[vNextIndex];
    this.location.href = vNext;
}

// Toggle the menu:
function EryqMenuToggle(pName) {
    var vDisplay = document.getElementById(pName).style.display;
    document.getElementById(pName).style.display = 
	((vDisplay == "none") ? "block" : "none");
}

// Hide the menu:
function EryqMenuHide(pName) {
    document.getElementById(pName).style.display = "none";
}


// end of file



