// JavaScript Document to Display Photos on Knackert Door & Glass

// Declare Variables
var path = "newPhotos/";
var imgTxt = "image";
var imgExt = ".jpg";
var thExt = "thumb.jpg";

var groups = new Array( "big5", "busbank", "goldvill", "hemetpd", "lazyboy", "lenscrafters", "napa", "pizzahut", "cityhall", "sanjacintopd", "skycan", "starbucks", "walhemet", "walontario" );

var picCount = new Array( 3, 5, 9, 1, 4, 2, 4, 4, 1, 1, 7, 5, 4, 3 );

var title = new Array( "Big 5 Sporting Goods", "Business Bank of California", "Golden Village Resort", "Hemet Police Department", "La-Z-Boy Furniture Galleries", "LensCrafters", "Napa: The Auto Parts Store", "Pizza Hut", "San Jacinto City Hall", "San Jacinto Police Department", "Sky Canyon Plaza", "Starbucks-Subway Center", "Walgreens Pharmacy", "Walgreens Pharmacy" );

var city = new Array( "Hemet, Ca", "Hemet, Ca", "Hemet, CA", "Hemet, Ca", "Hemet, Ca", "Hemet, Ca", "Hemet, Ca", "San Jacinto, Ca", "San Jacinto, Ca", "San Jacinto, Ca", "Murrieta, CA", "Hemet, CA", "Hemet, Ca", "Ontario, Ca" );

// declare button image variables
var btnNames = new Array( "prevDown", "prevUp", "prevSelect", "nextDown", "nextUp", "nextSelect" );
var btnVars = new Array();

for ( var y = 0; y < btnNames.length; y++ )
{
	btnVars[y] = new Image( 32, 32 );
	btnVars[y].src = "art/buttons/" + btnNames[y] + ".gif";
}

// declare image src variables for all full pictures
var photoSrc = new Array();
var b = 0;
var indexArray = new Array();
var thisIndex;

for ( var z = 0; z < picCount.length; z++ )
{	
	if ( picCount[z]==1 )
	{
		indexArray[z] = b;
		
		photoSrc[b] = path + groups[z] + imgTxt + imgExt;
		
		++b;
	}
	
	else
	{
		indexArray[z] = b;
		
		for ( var a = 1; a <= picCount[z]; a++ )
		{
			photoSrc[b] = path + groups[z] + imgTxt + a + imgExt;
			
			++b;
		}
	}
}

// determine group displaying
var theGroup = 0;

function setGroup(grp)
{
	theGroup = grp;
}

function getGroup()
{
	return theGroup;
}

// determine photo # of group displaying
var subGroup = 0;

function setSubGroup(subGrp)
{
	subGroup = subGrp;
}

function getSubGroup()
{
	return subGroup;
}

// general image-swapping function
var theNext = "";
function swapImg(imgType,newSrc,nextImg)
{
	// imgType 1 = previous button; btnVars[0,1].src
	if ( imgType==1 )
	{
		pButton.src = newSrc.src;
	}
	
	// imgType 2 = next button; btnVars[2,3].src
	else if ( imgType==2 )
	{
		nButton.src = newSrc.src;
	}

	if ( nextImg!=0 )
	{
		// swap photo with PREVIOUS photo
		if ( nextImg==1 )
		{
			if ( thisIndex==0 )
			{
				setGroup(groups.length-1);
				setSubGroup(picCount[getGroup()]);
			}
			
			else
			{
				if ( getSubGroup()==1 )
				{
					setGroup(getGroup()-1);
					setSubGroup(picCount[getGroup()]);
				}
				
				else
					setSubGroup(getSubGroup()-1);
			}
		}
		// swap photo with NEXT photo
		if ( nextImg==2 )
		{
			if ( thisIndex==(photoSrc.length-1) )
			{
				setGroup(0);
				setSubGroup(1);
			}
			
			else
			{
				if ( getSubGroup()==picCount[getGroup()] )
				{
					setGroup(getGroup()+1);
					setSubGroup(1);
				}
				
				else
					setSubGroup(getSubGroup()+1);
			}
		}
	
		setAll();
	
		document.getElementById( "phCaption" ).innerHTML = caption;
		document.getElementById( "imgCount" ).innerHTML = theCountA;
		document.getElementById( "grpCount" ).innerHTML = theCountB;
		document.getElementById( "photograph" ).innerHTML = thePhoto;
	}
}

// declare HTML code variables for cells in display table
// previous button
var prevBtn = '<a href=# onMouseOver="swapImg(1,btnVars[1],0)" onMouseOut="swapImg(1,btnVars[0],0)" onClick="swapImg(1,btnVars[2],1)"><img src="art/buttons/prevDown.gif" width="32px" border="0" alt="previous" name="pButton" /></a>';;
// next button
var nextBtn = '<a href=# onMouseOver="swapImg(2,btnVars[4],0)" onMouseOut="swapImg(2,btnVars[3],0)" onClick="swapImg(2,btnVars[5],2)"><img src="art/buttons/nextDown.gif" width="32px" border="0" alt="next" name="nButton" /></a>';
var chosenPic = "";
var caption = "";
var theCountA = "";
var theCountB = "";
var thePhoto = "";

// function to repopulate HTML code variables
function setAll()
{
	// photo caption
	caption = title[getGroup()] + ' - ' + city[getGroup()];

	// image counts
	if ( getSubGroup()==0 )
		theCountA = '&nbsp;<br />';
	else
		theCountA = 'Image ' + getSubGroup() + ' of ' + picCount[getGroup()];
	
	// group counts
	if ( getGroup()>=0 && getGroup()<groups.length )
		theCountB = 'Group ' + (getGroup() + 1) + ' of ' + groups.length;
	else
		theCountB = '&nbsp;<br />';
	
	// the photo!!
	if ( picCount[getGroup()]==1 )
		chosenPic = path + groups[getGroup()] + imgTxt + imgExt;
	else
		chosenPic = path + groups[getGroup()] + imgTxt + getSubGroup() + imgExt;
	
	thePhoto = '<img src="' + chosenPic + '" style="border-width: 0px;" width="300px" height="300px" name="showPhoto" alt="';
	
	if ( picCount[getGroup()]==1 )
		thePhoto += title[getGroup()] + '" />';
	else
		thePhoto += title[getGroup()] + ': Image ' + getSubGroup() + ' of ' + picCount[getGroup()] + '" />';
	
	thisIndex = indexArray[getGroup()] + getSubGroup() - 1;
}