/*
gallerynav.js

Use functions in links on Gallery pages to move through gallery.

Usage:
<a href="#" onclick="return galleryPrevious();">Previous</a>
<a href="#" onclick="return galleryNext();">Next</a>

Sylvan Korvus Jan 9 2008

*/


/* 
IMPORTANT: 
Fill this array with the names of all gallery pages in order. Please watch syntax, and ensure the page is in the correct section.
Format is:

'pagename.html',

Last page has no following comma.

Blank lines are OK, and makes easier to split by section for reference.

*/

var arGalleryPages = new Array(9);

// Architectural Presentation Models
arGalleryPages[0] = new Array(
'hollingsworth.html',
'cutawaymodel.html',
'seattletower.html',
'northvantower.html',
'texastowers.html',
'largescalecabin.html',
'larestaurant.html',
'folio.html',
'ucluelet.html',
'gallery02.htm',
'gallery03.htm',
'gallery06.htm',
'gallery08.htm',
'gallery10.htm',
'gallery12.htm',
'gallery14.htm',
'gallery15.htm'
);

//Architectural Massing Models
arGalleryPages[1] = new Array(
'spanishpeaks.html',
'waterfall.html',
'fieldandmartin.html',
'gallery29.htm',
'gallery33.htm',
'gallery30.htm',
'gallery35.htm',
'gallery36.htm'
);

//Real Estate Marketing Center Models
arGalleryPages[2] = new Array(
'gallery16.htm',
'artesia.html',
'gallery17.htm',
'gallery34.htm',
'wildernessclub.html',
'blackmountain.html',
'moonlightbasin.html',
'britannia.html',
'triology.html'
);

//Topographic Models
arGalleryPages[3] = new Array(
'gallery19.htm',
'gallery20.htm',
'gallery21.htm',
'alaskatopo.html',
'northernvisitorscentre.html',
'tourismbc.html'
);

//Dioramas
arGalleryPages[4] = new Array(
'gallery40.htm',
'gallery58.htm',
'ochrebluffs.html',
'yellowknife.html',
'kaskitinawbridge.html',
'nightatthemuseum.html'
);

//Planning & Design Models
arGalleryPages[5] = new Array(
'gallery22.htm',
'whitedesignmodels.html',
'colourdesignmodel.html'
);

//Tradeshow Models
arGalleryPages[6] = new Array(
'atomic.html',
'concreteplant.html',
'octoform.html',
'watertreatment.html'
);

//Exhibits & Prototypes
arGalleryPages[7] = new Array(
'gallery39.htm',
'gallery41.htm',
'gallery42.htm',
'gallery28.htm',
'carronade.html'
);

//Aerospace Models
arGalleryPages[8] = new Array(
'gallery43.htm',
'gallery44.htm',
'gallery45.htm',
'gallery46.htm',
'gallery47.htm',
'gallery50.htm',
'gallery51.htm',
'gallery52.htm',
'shuttle.html',
'dextre.html'
); 

/* NO COMMA ON LAST ONE IN LISTS. */








/* Please don't touch anything below this! */

/* Find the matching filename in the array */
function arraySearch(arArray, sString) {
var iSearchSection = -1;
var iSearchPage = -1;
    for (iSection=0; iSection<arArray.length; iSection++) {
      for (iPage=0; iPage<arArray[iSection].length; iPage++) {
        if (arArray[iSection][iPage].toLowerCase() == sString.toLowerCase()) {
            iSearchSection=iSection;
            iSearchPage=iPage;
            break;
           }
      }
    }
    return [iSearchSection, iSearchPage];
}

/* Go to the chosen page */
function goDestinationPage(iOffset) {
    sCurrentPage = location.pathname.substring(location.pathname.lastIndexOf('/')+1);
    var arCurrentIndex = arraySearch(arGalleryPages, sCurrentPage);                         // Find our the position of the current section and page in the array
    iCurrentSection=arCurrentIndex[0]; 
    iCurrentPage=arCurrentIndex[1];
    if (iCurrentPage != -1) {
        var iLength = arGalleryPages[iCurrentSection].length;
        var iDestinationIndex = ((iLength + iCurrentPage + iOffset) % iLength);            // Calculate next position using modulus to wrap around
        //alert(arGalleryPages[iCurrentSection][iDestinationIndex]);
        document.location.href=arGalleryPages[iCurrentSection][iDestinationIndex];         // Go to the specified page in the array
    } else { 
        return false 
    };
}

/* Go to the previous page */
function galleryPrevious() {
    goDestinationPage(-1);
    return false;
}

/* Go to the next page */
function galleryNext() {
    goDestinationPage(1);
    return false;
}


