
// This array will be filled upon init()
var pics = new Array();
	
var thumbs;
var index;
var view;

// fills thumbnails, with repetition if not enough pics
function fillthumbs(index) {

	/*
	
		SOMETHING IS WRONG HERE, IT DOESN'T WRAP AND IT DOESN'T START RIGHT!
	
	*/


	// 5 thumbnails
	thumbs = new Array(5);
	var th;
	
	for(i=0; i<thumbs.length; i++) {
		if ( index == pics.length ) { index = 0; }
		else if ( index == 0 ) { index = pics.length - 1; }

		thumbs[i] = pics[index++];
		th = document.getElementById("th"+i);
		th.src = "../images/pictures/" + thumbs[i];
	}
	
}

// changes the viewing image corresponding to the thumbnail chosen
function change(thumb) {
	view = document.getElementById("view");
	view.src = "../images/pictures/" + thumbs[thumb];

}

// refills thumbnail gallery with different images (move to left, move to right)
function arrow(direct) {

	if( direct != null ) {

		// left means decrement, right means increment
		// 5 is picked because that's the number of thumbnails in the table
		if ( direct == 'left' ) {
			index -= 5;
		} else if ( direct == 'right' ) {
			index += 5;
		}
		
		fillthumbs(index);
		
	} else
		return null;

}

// transparency hover effect
function fade(img, inout) {
	if ( inout == null ) {
		return null;
	} else if ( inout == 1 ) {
		img.style.opacity = '0.75';
		img.style.filter = 'alpha(opacity=75);';
	} else if ( inout == 0 ) {
		img.style.opacity = '1.0';
		img.style.filter = 'alpha(opacity=100);';
	}
}

/**
	fills pics array
	this uses the PHP-created <param> tags in photo/index.php
	it's a hack to get around JavaScript's inability to access the serverside
	filenames of all images under ../images/pictures/
*/
function fillpics() {
	var params = document.getElementsByTagName("param");
	for (i=0; i<params.length; i++) {
		pics[i] = params.item(i).value;
	}
}

// initialize
function init() {
	fillpics();
	index = 0;
	fillthumbs(index);
	change(0);
	document.getElementById("left").src = "../images/Left.jpg";
	document.getElementById("right").src = "../images/Right.jpg";
}

