var 
	aGallery = new Array(),
	nGalleryIndex = 0, nGalleryViewIndex = -1,
	aGalleryImages = new Array();

function gallery_add( sImg, sTitle ) {
	var aItem = new Array();
	aItem[ 0 ] = sImg;
	aItem[ 1 ] = sTitle;
	aGallery[ aGallery.length ] = aItem;
}

function gallery_image( oImg ) {
	aGalleryImages[ aGalleryImages.length ] = oImg;
}

function _gallery_update() {
	var nIndex, nGIndex;
	for (nIndex=0; nIndex<aGalleryImages.length; nIndex++ ) {
		oImg = aGalleryImages[ nIndex ];
		nGIndex = ( nGalleryIndex + nIndex ) % aGallery.length;
		oImg.src = "gallery/" + aGallery[ nGIndex ][ 0 ] + "s.jpg";
	};

}

function _gallery_view_update() {
	document.getElementById( "Page3GalleryViewIMG" ).src = "gallery/" + aGallery[ nGalleryViewIndex ][ 0 ] + ".jpg";
	document.getElementById( "Page3GalleryViewH2" ).innerHTML = aGallery[ nGalleryViewIndex ][ 1 ];
}

function gallery_open( nIndex ) {

	nGalleryViewIndex = ( nIndex + nGalleryIndex ) % aGallery.length;

	_gallery_view_update();

	document.getElementById( "Page3TABLE" ).style.display = "none";
	document.getElementById( "Page3GalleryViewTABLE" ).style.display = "block";

}

function gallery_view_next() {
	nGalleryViewIndex = ( nGalleryViewIndex + 1 ) % aGallery.length;
	_gallery_view_update();
}


function gallery_close() {

	document.getElementById( "Page3TABLE" ).style.display = "block";
	document.getElementById( "Page3GalleryViewTABLE" ).style.display = "none";

}

function gallery_init() {
	nGalleryIndex = 0;
	_gallery_update();
}

function gallery_next() {
	nGalleryIndex = ( nGalleryIndex + aGalleryImages.length ) % aGallery.length;
	_gallery_update();

}

