
var perrow = 5;    // Shots per row
var numrows = 2;   // Number of rows

// know your stuff before editing below

totalshots = perrow * numrows;
var lastphoto = totalshots - 1;
startspot = 1;
asect = "portfolio"; 
whiten = "n";
gallery('Products',1); 
display(1); 

function gallery(section,starts) { // main function for thumbnail navigation
submenu(section); // expands & closes submenus
startspot = starts;
gsection = section;  //  g for global variable
lastphoto = eval('num' + gsection);

var ShowThese = new Array(lastphoto);
ShowThese[0] = 0;
for ( i=1; i<=lastphoto; i++ ) { ShowThese[i]= "/portfolio/" + gsection + "/" + gsection + " (" + i + ").jpg"; }

// if ( screen.availWidth > 1024 ) { gsection = gsection + "L"; }

if (typeof graytoggle == 'undefined')
{ graytoggle = ' '; } // for colourswitch function

var n2 = totalshots + startspot;
var totalcode = '<table width="100%"><tr><td width="38" align="center">';
for (var n1 = startspot; n1 < n2 ; n1++) { 
var mainpic = eval('ShowThese[' + n1 + ']');
var imagecall = '<a href="javascript:display('+n1+')"><img src="' + mainpic + '" height="24"'+graytoggle+'></a>';
totalcode += imagecall;
if ( ( n1 % perrow != 0 ) && ( n1 != n2 ) ) 
{ totalcode += '</td><td width="38" align="center">'; }
else if ( ( n1 % perrow == 0 ) && ( n1 != n2 ) )
{ totalcode += '</td></tr><tr><td align="center">'; }
else if ( n1 == n2 )
{ totalcode += '</td></tr></table>'; }
}
document.getElementById("gallery").innerHTML = totalcode;
pregallery(lastphoto); 
} 


function display(n1) {
var mainpic = "/portfolio/" + gsection + "/" + gsection + " (" + n1 + ").jpg";
document.currentimage.src = mainpic;
/*if ( ( gsection == "Maternity" ) && ( n1 == 1 ) ) {
document.getElementById("blurb").innerhtml = "<p>I have always been fascinated with our ability as humans to create another human being.</p><p>The science is one thing but the visual transformation of a woman’s body is one of the most beautiful processes on the planet. </p><p><font color=\"red\">D</font>`Vision Imaging embraces the fact this is a delicate & somewhat private process for any woman & her partner. <font color=\"red\">Studio 203</font> is a secure, heated professional photography studio in Kitchener. It’s the perfect venue to relax, take our time & have fun creating timeless & emotional photos you will cherish forever.</p><p>So if you yourself are expecting a baby, or would like to give my services as a gift to someone expecting a baby, keep <font color=\"red\">D</font>`Vision Imaging in mind. I would love to hear from you and work with you!! </p><p>For more information, such as discounted 2009 & 2010 pricing & availability, please contact me via email or call 519-807-7627. </p><p>Posting maternity images on my site is entirely up to the client. I only post images you’re comfortable with showing. Thank-You to those who see the benefits in allowing me to show my work!! </p><p>Happy To Provide Referrals!! </p><p>Dean</p>";
} 
else document.getElementById("blurb").innerhtml = "";*/
gnumber = n1;
}

// SCROLLING UP & DOWN
function nextfive() {
var extras = lastphoto % 5;
if ( startspot <= lastphoto - totalshots - extras )
{ startspot = startspot + perrow; } 
gallery(gsection,startspot)
}
function lastfive() {
if ( startspot > perrow )
{ startspot = startspot - perrow; } 
gallery(gsection,startspot)
}



// SCROLLING LEFT & RIGHT
function previous() {
gnumber --;
if ( gnumber % 5 == 0 ) { lastfive(); }
if (gnumber == 0 )
{ gnumber = lastphoto; 
var extras = gnumber % 5;
var loopback = gnumber - totalshots - extras + 1;
gallery(gsection,loopback); }
var mainpic = "/portfolio/" + gsection + "/" + gsection + " (" + gnumber + ").jpg";
document.currentimage.src = mainpic;
}

function next() {
gnumber ++;
if ( gnumber % 5 == 1 ) { nextfive(); }
if (gnumber == lastphoto + 1 )
{ gnumber = 1; gallery(gsection,1); }
var mainpic = "/portfolio/" + gsection + "/" + gsection + " (" + gnumber + ").jpg";
document.currentimage.src = mainpic;
}


// PRELOADING GALLERIES
function pregallery(numba) {
if (document.images)
{ 
var preg = new Array(numba);
for(i = 0; i < numba + 1; i++) 
{ preg[i] = new Image(); 
preg[i].src = "portfolio/" + gsection + "/" + gsection + " (" + i + ").jpg"; 
}
}
}


// MENU NAVIGATION FUNCTIONS

function closesubs() {
document.getElementById('wmenu').innerHTML = '';
document.getElementById('prmenu').innerHTML = '';
document.getElementById('famenu').innerHTML = '';
}


function swap(pic,AB) {
if ( ( pic == asect ) && ( whiten == "n" ) ) { AB = "B" }
if ( ( pic == asect ) && ( whiten == "y" ) ) { AB = "A" }
if ( AB == "A" ) { document.getElementById(pic).src = '/images/pf/' + pic + '.gif'; }
if ( AB == "B" ) { document.getElementById(pic).src = '/images/pf/' + pic + 'B.gif';}
}


function submenu(section) { // opens or doesn't open submenu
whiten = "y";
swap(asect,"A");
whiten = "n";
asect = section.toLowerCase(); //active section for swap function (.gif name)
swap(asect,"B");

if ( section == "Weddings" ) {
closesubs();
document.getElementById('wmenu').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="javascript:gallery(\'Albums\',1);display(1);"><img src="images/pf/albums.gif" class="sc" name="albums" id="albums" alt="Albums" onMouseOver="swap(\'albums\',\'B\')"  onMouseOut="swap(\'albums\',\'A\')"></a><br><br class="half">&nbsp;&nbsp;&nbsp;<a href="javascript:gallery(\'Engagements\',1);display(1);"><img src="images/pf/engagements.gif" class="sc" name="engagements" id="engagements" alt="Engagements"  onMouseOver="swap(\'engagements\',\'B\')"  onMouseOut="swap(\'engagements\',\'A\')"></a><br><br>';
}

if ( section == "Portraits" ) {
closesubs();
document.getElementById('prmenu').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="javascript:gallery(\'Maternity\',1);display(1);"><img src="images/pf/maternity.gif" class="sc" name="maternity" id="maternity" alt="Maternity" onMouseOver="swap(\'maternity\',\'B\')"  onMouseOut="swap(\'maternity\',\'A\')"></a><br><br>';
}

if ( section == "Products" ) { closesubs(); }
if ( section == "Fashion" ) { closesubs(); }

if ( section == "FineArt" ) {
closesubs();
document.getElementById('famenu').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="javascript:gallery(\'Travel\',1);display(1);"><img src="images/pf/travel.gif" class="sc" name="travel" id="travel" alt="Travel" onMouseOver="swap(\'travel\',\'B\')"  onMouseOut="swap(\'travel\',\'A\')"></a><br><br><!--&nbsp;&nbsp;&nbsp;<a href="javascript:gallery(\'Infrared\',1);display(1);"><img src="images/pf/infrared.gif" class="sc" name="infrared" id="infrared" alt="Infrared" onMouseOver="swap(\'infrared\',\'B\')" onMouseOut="swap(\'infrared\',\'A\')"></a><br><br>-->';
}

}


// COLOUR SWITCH
function colourswitch() { 
for (var n = 0; n < document.images.length; n++){ 
if (document.images[n].className == '')
{ document.images[n].className = 'colour'; }
if (document.images[n].className == 'colour')
{ document.images[n].className = 'limbo'; }
if (document.images[n].className == 'gray')
 { graytoggle = ' ';
document.images[n].className = 'colour'; }
if (document.images[n].className == 'limbo')
 { graytoggle = ' class="gray"';
document.images[n].className = 'gray'; }
} 
} 


