// Border colours for hovering and un-hovering over thumbnails
var imgBdrLo = '#e0e0e0';
var imgBdrHi = '#e0e0e0'; // '#b0b0b0';
var capBdrLo = '#f0f0f0';
var capBdrHi = '#f0f0f0'; // '#e0e0e0';

// Dimensions for thumbnail display
var windowWidth;
var windowHeight;
var thumbWidth = 146;
var thumbCols;
var thumbRows;

// Parameters for gallery button arrangement
var numGalleries  = 12;
var galleryPage   = new Array( numGalleries );
var galleryTitle  = new Array( numGalleries );
var buttonBgColor = new Array( numGalleries );

// Extract base name of this html file
var urlQuery = location.href.split( "?" );
var urlTerms = urlQuery[0].split( "/" );
var thisFile = urlTerms[ urlTerms.length - 1 ].split( "." )[ 0 ];

// Set up gallery buttons
galleryPage[  0 ] = 'small05';    galleryTitle[ galleryPage[  0 ] ] = 'Flowers';           buttonBgColor[ galleryPage[  0 ] ] = 'navajowhite';
galleryPage[  1 ] = 'small02';    galleryTitle[ galleryPage[  1 ] ] = 'Animals';           buttonBgColor[ galleryPage[  1 ] ] = 'navajowhite';
galleryPage[  2 ] = 'small04';    galleryTitle[ galleryPage[  2 ] ] = 'Autumn';            buttonBgColor[ galleryPage[  2 ] ] = 'navajowhite';
galleryPage[  3 ] = 'small07';    galleryTitle[ galleryPage[  3 ] ] = 'Sport';             buttonBgColor[ galleryPage[  3 ] ] = 'navajowhite';
galleryPage[  4 ] = 'small09';    galleryTitle[ galleryPage[  4 ] ] = 'Dragonflies';       buttonBgColor[ galleryPage[  4 ] ] = 'navajowhite';
galleryPage[  5 ] = 'triptych';   galleryTitle[ galleryPage[  5 ] ] = 'Triptychs';         buttonBgColor[ galleryPage[  5 ] ] = 'orange';

galleryPage[  6 ] = 'small06';    galleryTitle[ galleryPage[  6 ] ] = 'Floral Studies';    buttonBgColor[ galleryPage[  6 ] ] = 'navajowhite';
galleryPage[  7 ] = 'small08';    galleryTitle[ galleryPage[  7 ] ] = 'Landscapes';        buttonBgColor[ galleryPage[  7 ] ] = 'navajowhite';
galleryPage[  8 ] = 'small03';    galleryTitle[ galleryPage[  8 ] ] = 'Buildings';         buttonBgColor[ galleryPage[  8 ] ] = 'navajowhite';
galleryPage[  9 ] = 'small01';    galleryTitle[ galleryPage[  9 ] ] = 'Abstracts';         buttonBgColor[ galleryPage[  9 ] ] = 'navajowhite';
galleryPage[ 10 ] = 'small10';    galleryTitle[ galleryPage[ 10 ] ] = 'Damselflies';       buttonBgColor[ galleryPage[ 10 ] ] = 'navajowhite';
galleryPage[ 11 ] = 'pano';       galleryTitle[ galleryPage[ 11 ] ] = 'Panoramas';         buttonBgColor[ galleryPage[ 11 ] ] = 'orange';


function thumbHi( id )
{
    eval( "document.getElementById( 'tdi" + id + "').style.borderColor=imgBdrHi" );
}

function thumbLo( id )
{
    eval( "document.getElementById( 'tdi" + id + "').style.borderColor=imgBdrLo" );
}

// Adapted from http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16
function getWindowDimensions()
{
    var myWidth = 0, myHeight = 0;

    if (typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    windowWidth  = myWidth;
    windowHeight = myHeight;
}

function paintThumbnails()
{
    getWindowDimensions();
    thumbCols = Math.max( 1, Math.floor( windowWidth / thumbWidth ) );
    thumbRows = Math.ceil( numImages / thumbCols );

    document.write( '<table class="center" cellpadding="0" cellspacing="3">' );
    for (r = 0, i = 0; r < thumbRows; r++ )
    {
        // Paint the thumbnails
        document.write( '<tr>' );
        for (c = 0; c < thumbCols; c++ )
            if (i + c < numImages)
                document.write( '<td class="img" id="tdi' + (i + c) + '"onClick="location=\'large' + ident + '.htm?' + thisFile + ',' + (i + c) + '\'" onMouseOver="thumbHi(' + (i + c)  + ')" onMouseOut="thumbLo(' + (i + c) + ')"><img src="small/' + img[ i + c ] + '.jpg"></td>' );
        document.write( '</tr>' );

        // Paint the captions
        document.write( '<tr>' );
        for (c = 0; c < thumbCols; c++ )
            if (i + c < numImages)
                document.write( '<td class="cap" id="tdc' + (i + c) + '" onClick="location=\'large' + ident + '.htm?' + thisFile + ',' + (i + c) + '\'" onMouseOver="document.getElementById(\'tdc' + (i + c) +'\').style.backgroundColor=capBdrHi" onMouseOut="document.getElementById(\'tdc' + (i + c) +'\').style.backgroundColor=capBdrLo">' + cap[ i + c ] + '</td>' );
        document.write( '</tr>' );

        i += thumbCols;
    }
    document.write( '</table>' );
}

function contact()
{
  parta='ma';
  partb='to';
  part1='webquery';
  part2='@';
  part3='brightimaging';
  part4='.';
  part5='com';
  location=parta+'il'+partb+':'+part1+part2+part3+part4+part5;
}

function showGalleryLinks()
{
    var colsPerRow = 6;
    var rows       = Math.ceil( numGalleries / colsPerRow );
    var drawGallery;

    document.write( '<table class="center" border="0" cellpadding="0" cellspacing="3">' );

    for (row = 0, i = 0; row < rows; row++ )
    {
        // Draw the gallery buttons
        document.write( '<tr>' );

        for (col = 0; col < colsPerRow; col++ )
        {
            // Set up the page name of the gallery button being drawn
            drawGallery = galleryPage[ i + col ];
            
            // Draw the gallery button
            if (i + col < numGalleries)
                document.write( '<td class="galleryLink"' + ((drawGallery == thisFile) ? 'style="background-color: black"' : 'style="background-color: ' + buttonBgColor[ drawGallery ] +'" onMouseOver="javascript: this.style.backgroundColor=\'#a0a0ff\'; this.style.cursor=\'hand\'" onMouseOut="javascript: this.style.backgroundColor=\'' + buttonBgColor[ drawGallery ] + '\'" onClick="javascript: location=\'' + drawGallery + '.htm\'"') +
                                 '>' + ((drawGallery == thisFile) ? '<span class="galleryInvalid">' : '<a class="galleryValid" href="' + drawGallery + '.htm">') + galleryTitle[ drawGallery ] + ((drawGallery == thisFile) ? '</span>' : '</a>') + '</td>' );

        }
        i += colsPerRow;
    }
    document.write( '</table><br>' );
}

function showGalleryTitle()
{
    document.write( '<p class="galleryTitle">' + galleryTitle[ thisFile ] + '</p>' );
}

