/**
* LICENSE 
* Copyright 2008 James Netherton
* http://www.opensource.org/licenses/lgpl-license.php
*
* http://www.jamesnetherton.com
*/

var gallery = new Array();
var imageIndex = 0;

/**
* Initialises the gallery
*/
function galleryInit(){

	loadGallery();
	loadThumbnails();
	showImage(imageIndex);
}



/**
* Loade images into the gallery
*/
function loadGallery(){

	/**
	* 	INSTRUCTIONS FOR ADDING IMAGES TO THE GALLERY
	*
	*	COPY AND PASTE THE FOLLOWING 5 LINES OF CODE
		
		var image = new Object();
		image['thumbnail']   = '';
		image['mainimage']   = '';
		image['description'] = '';
		gallery.push(image);

	* SET THE thumbnail PART TO: images/NAME OF YOUR TUMBNAIL IMAGE
	* SET THE mainimage PART TO: IMAGES/NAME OF YOUR LARGE MAIN IMAGE
	* SET THE description PART TO: THE TEXT YOU WANT TO APPEAR UNDER THE IMAGE
	*/

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_chic_charter.jpg';
	image['mainimage']   = 'images/main/m_chic_charter.jpg';
	image['description'] = 'Chichester Rotaract\'s Charter Night';
	gallery.push(image);
	
	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_bmth_xmas.jpg';
	image['mainimage']   = 'images/main/m_bmth_xmas.jpg';
	image['description'] = 'Raising money in all weathers';
	gallery.push(image);

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_bmth_ringo.jpg';
	image['mainimage']   = 'images/main/m_bmth_ringo.jpg';
	image['description'] = 'Ready, Steady, Ringos!';
	gallery.push(image);

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_district_ringos.jpg';
	image['mainimage']   = 'images/main/m_district_ringos.jpg';
	image['description'] = 'Chilling out after Ski Bobbing';
	gallery.push(image);

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_Bmth_Back_to_Front.jpg';
	image['mainimage']   = 'images/main/m_Bmth_Back_to_Front.jpg';
	image['description'] = 'Bournemouth Rotaract\'s Back to Front Party';
	gallery.push(image);

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_winchester_bar.jpg';
	image['mainimage']   = 'images/main/m_winchester_bar.jpg';
	image['description'] = 'Rotaract always finds a bar!';
	gallery.push(image);
	
	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_bmth_bench.jpg';
	image['mainimage']   = 'images/main/m_bmth_bench.jpg';
	image['description'] = 'Rotaract helps local charities ';
	gallery.push(image);

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_winchester_chinese.jpg';
	image['mainimage']   = 'images/main/m_winchester_chinese.jpg';
	image['description'] = 'Rotaract samples foods from around the world';
	gallery.push(image);

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_bmth_kites.jpg';
	image['mainimage']   = 'images/main/m_bmth_kites.jpg';
	image['description'] = 'Lets go fly 1000 kites!!!';
	gallery.push(image);
	
	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_bmth_row.jpg';
	image['mainimage']   = 'images/main/m_bmth_row.jpg';
	image['description'] = 'Row, row, row the boat...';
	gallery.push(image);
	
	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_bmth_bowling.jpg';
	image['mainimage']   = 'images/main/m_bmth_bowling.jpg';
	image['description'] = '10 Pin Bowling';
	gallery.push(image);

	var image = new Object();
	image['thumbnail']   = 'images/thumb/t_bmth_senior.jpg';
	image['mainimage']   = 'images/main/m_bmth_senior.jpg';
	image['description'] = 'Rotaract puts on a good Party!';
	gallery.push(image);



}


/**
* Loade image thumbnails onto the webpage
*/
function loadThumbnails(){
	
	var thumbnailContainer = document.getElementById('thumbnails');
	
	var thumbnailHTML = '';
	
	for(var i = 0; i < gallery.length; i++){
		
		var image = gallery[i];		

		thumbnailHTML += '<li id="thumb' + i +'"><img src="' + image["thumbnail"] + '" alt="' + image["description"] + '"  onclick="javascript:showImage(' + i + ')" height="70" width="70"/></li>';
		
		if(i % 7 == 0 && i != 0){
			thumbnailHTML += '<br clear="both"/><br/>';
		}
	}
	
	thumbnailContainer.innerHTML = thumbnailHTML;
}


/**
* Displays an image
*/
function showImage(index){
	
	var imageDesc = document.getElementById('imageDescription');
	var mainImage = document.getElementById('largeImage');
	var thumbnail = document.getElementById('thumb' + index);
	var thumbnailOld = document.getElementById('thumb' + imageIndex);

	if(index == imageIndex){
		thumbnailOld = undefined;
	}
	
	var image = gallery[index];
	
	imageIndex = index;
	
	imageDesc.innerHTML = image['description'];		

	mainImage.src = image['mainimage'];
	mainImage.height = 480;
	mainImage.width = 640;
	
	thumbnail.style.borderWidth = 'medium';
	thumbnail.style.borderStyle = 'solid';
	thumbnail.style.borderColor	= '#A80532';
	
	if(thumbnailOld != undefined){
		thumbnailOld.style.borderWidth = '';
		thumbnailOld.style.borderStyle = '';
		thumbnailOld.style.borderColor	= '';
	}
}