// set up global variable to hold the images
var imageArray = new Array(9);
// set up global variable to hold the photo attributions
var imageAttribArray = new Array(9);

function fSetImage(strName){
// set the large picture to be the same as the thumbnail

    // get the number of the thumbnail and set the src property of the large image
    // from the array of images preloaded into memory
    var re = /\d$/;  // regular expression
	var thumbIndex = strName.match(re);
	document.getElementById("imgLargeImage").src = imageArray[thumbIndex].src;	
	
	// set the photo attribution	//
	//window.alert(document.getElementById("caption").innerText);
	if (document.all) {
		// IE supports innerText propery
		document.getElementById("caption").innerText = imageAttribArray[thumbIndex];	
	}
	else {
		// Firefox supports textContent property
		document.getElementById("caption").textContent = imageAttribArray[thumbIndex];
	}
}

function fLoadImages(srcElement, intThumbs) {//v1.0
// load images on to the pages
// filename prefix is defined in by the name property of the element with id=srcElement

	var x;
	var strThumb;
	var img;
	var strAttrib;
	
	// get the image name root 
	var root  = document.getElementById(srcElement).name;
	
	// get the number of images on the page (last character of the root)
	// an 'X' at the end signifies no images to load
	var re = /\d$/;  // regular expression
	var imageCount = root.match(re);			
	//strip off the final character of the root
	root = root.substring(0,(root.length-1));
	
	// if final character is 'X' then no thumbs/images to load
	if (imageCount == null) {
		imageCount = -1;		
	}
    //window.alert(imageCount);
	
	// build the filename prefix
    var filePrefix = "images/" + root;
	
	//window.alert(root);
	//window.alert(document.getElementById(root).style.fontWeight);
	// highlight the link for this page to indicate location
	document.getElementById(root).style.color= "#16541A";
	document.getElementById(root).style.fontWeight= "bold";	
	
	// load the banner 
	var fileName = filePrefix + "_banner.jpg";
	document.getElementById("imgBanner").src = fileName;
	//window.alert(fileName);
			
	//set large image
	if (imageCount >= 0) {
		//window.alert(imageCount);
		fileName = filePrefix + imageCount + ".jpg";
		document.getElementById("imgLargeImage").src = fileName; 
	}
		
	// process images & thumbs if there are any
	if (imageCount > 0) {
				
		// load and display the thumbnails
		for ( x = 1; x <= imageCount ; x++ ) { 	    	
       		// add the index on the thumb image to the filename       		       		
       		strThumb = "thumb" + x;
	    	fileName = filePrefix + strThumb;
	    	fileName = fileName + ".jpg";
       		img = document.getElementById(strThumb);
       		
       		if (x <= imageCount) 
       		{
       			// load the thumbnail
	       		img.src=fileName;
			}
			else 
			{	
				// hide any thumbnails which are not used			
				img.width=0;
				img.height=0;
			}
			
	    }
	    // load the rest of the full size images so that they are available for 
	    // mouseover without delay	    
		for ( x = 1; x <= imageCount ; x++ ) { 
			fileName = filePrefix + x + ".jpg";
			imageArray[x]= new Image();
			imageArray[x].src = fileName;
			
			// set the photo attributions			
			switch (root + x) {			
				case "bridalbouquets1" :
					strAttrib = "Visual Chaos";
					break
				case "bridalbouquets2" :
					strAttrib = "Paul Fletcher Photography";
					break	
				case "bridalbouquets3" :
					strAttrib = "IC Photos";
					break	
				case "bridalbouquets5" :
					strAttrib = "Paul Fletcher Photography";
					break	
				case "bridesmaids1" :
					strAttrib = "Paul Fletcher Photography";
					break
				case "bridesmaids2" :
					strAttrib = "IC Photos";
					break	
				case "bridesmaids3" :
					strAttrib = "Paul Fletcher Photography";
					break
				case "bridesmaids4" :
					strAttrib = "Carolyn Wheeler Photography";
					break
				case "bridesmaids6" :
					strAttrib = "Adam James Photography";
					break
				case "ceremony2" :
					strAttrib = "Paul Fletcher Photography";
					break	
				case "ceremony5" :
					strAttrib = "Helen Roscoe Photography";
					break
				case "finishingtouches1" :
					strAttrib = "Hector Photo";
					break					
				case "finishingtouches2" :
					strAttrib = "Amaryllis Events";
					break	
				case "finishingtouches4" :
					strAttrib = "Paul Fletcher Photography";
					break							
				case "weddings1" :
					strAttrib = "IC Photos";
					break	
				case "weddings3" :
					strAttrib = "Artweddings Photography";
					break	
				case "weddings5" :
					strAttrib = "Dave Ashton Photography";
					break	
				case "weddings6" :
					strAttrib = "Steve Kentish Photography";
					break	
				default :			
					strAttrib = "CMD Photography";	
	
			}
			imageAttribArray[x] = "Photo by: " + strAttrib;

	    } 
	    // load the major image
	    fSetImage ("thumb" + imageCount);	
	}
	return null;
}

function fLoadHomeImage() {
	// chooses a random image to display on the home page
	
	var intImageCount = 1;
	var intRandom = Math.round(Math.random() * (intImageCount -1)) +1;
	var strFileName = "images/home" + intRandom + ".jpg"
	document.getElementById("imgLargeImage").src = strFileName;	

}

