var 
	aGallery = new Array(),
	nGalleryIndex = 0, nGalleryViewIndex = -1,
	aGalleryImages = new Array(),
	oGalleryContainer;

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_container( oC ) {
	oGalleryContainer = oC;
}

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( "GalleryViewIMG" ).src = "gallery/" + aGallery[ nGalleryViewIndex ][ 0 ] + ".jpg";
	document.getElementById( "GalleryViewH2" ).innerHTML = aGallery[ nGalleryViewIndex ][ 1 ];
}

function gallery_open( nIndex ) {

	nGalleryViewIndex = ( nIndex + nGalleryIndex ) % aGallery.length;

	try {
		document.getElementById( "PageContentTD" ).filters[0].apply();
	} catch(e) {
	};

	_gallery_view_update();

	document.getElementById( "ContentTABLE" ).style.display = "none";
	document.getElementById( "GalleryViewTABLE" ).style.display = "block";

	try {
		document.getElementById( "PageContentTD" ).filters[0].play();
	} catch(e) {
	};

}

function gallery_view_next() {
	nGalleryViewIndex = ( nGalleryViewIndex + 1 ) % aGallery.length;
	try {
		document.getElementById( "PageContentTD" ).filters[0].apply();
		_gallery_view_update();
		document.getElementById( "PageContentTD" ).filters[0].play();
	} catch(e) {
		_gallery_view_update();
	};
}


function gallery_close() {
	try {
		document.getElementById( "PageContentTD" ).filters[0].apply();
	} catch(e) {
	};

	document.getElementById( "ContentTABLE" ).style.display = "block";
	document.getElementById( "GalleryViewTABLE" ).style.display = "none";

	try {
		document.getElementById( "PageContentTD" ).filters[0].play();
	} catch(e) {
	};

}

function gallery_init() {
	nGalleryIndex = 0;
	_gallery_update();
}

function gallery_next() {
	nGalleryIndex = ( nGalleryIndex + aGalleryImages.length ) % aGallery.length;
	try {
		document.getElementById( "GalleryTD" ).filters[0].apply();
		_gallery_update();
		document.getElementById( "GalleryTD" ).filters[0].play();
	} catch(e) {
		_gallery_update();
	};

}
