var imageIndex = 0;
var imagePath = 'images/stills/';
var aImages = new Array();
aImages.push('still_1.jpg');
aImages.push('still_2.jpg');
aImages.push('still_3.jpg');
aImages.push('still_4.jpg');
aImages.push('still_5.jpg');
aImages.push('still_6.jpg');
aImages.push('still_7.jpg');
aImages.push('still_8.jpg');
aImages.push('still_9.jpg');
aImages.push('still_10.jpg');
aImages.push('still_11.jpg');
aImages.push('still_12.jpg');
aImages.push('still_13.jpg');
aImages.push('still_14.jpg');
aImages.push('still_15.jpg');
aImages.push('still_16.jpg');
aImages.push('still_17.jpg');
aImages.push('still_18.jpg');
aImages.push('still_19.jpg');
aImages.push('still_20.jpg');
aImages.push('still_21.jpg');
aImages.push('still_22.jpg');
aImages.push('still_23.jpg');
aImages.push('still_24.jpg');
aImages.push('still_25.jpg');
aImages.push('still_26.jpg');
aImages.push('still_27.jpg');

function debug(message){
	$('debug').innerHTML = message;
}

var pagechild = {
	
	init:function(){
		
		if ($('controls')){
			pagechild.prepLinks();
		}
		
	},
	
	prepLinks:function(){
			var aLinks = new Array();
						
			var controllinks = $('controls').getElementsByTagName('a');
			for (var i = 0; i < controllinks.length; i++){
				aLinks.push(controllinks[i]);
			}
			
			for (var i = 0; i < aLinks.length; i++){
				aLinks[i].onclick = pagechild.changeImage;
			}
	},
	
	changeImage:function(){
		
		var image = $('still');
		
		setOpacity(image, 0);

		//forward or back
		var bNext = (this.parentNode.id == 'next');
		var index = (bNext) ? imageIndex + 1: imageIndex - 1;
		//last element in image array, go back to beginning of the array
		index = (index == aImages.length) ? 0 : index;
		//start of image array, go to the end
		index = (index == -1) ? aImages.length - 1 : index;
		
		image.src = imagePath + aImages[index];
		//image.style.visibility = 'visible';		
		image.onload = pagechild.showImage;
		
		
		imageIndex = index;
	},

	showImage:function(){
		this.style.visibility = 'visible';
		fadeIn(this.id, 0);

	}
		
}

