var currentGalleryImage = 0;
var imageInterval = new Object();
var selectedSubNav = '';
var currentSubNav = '';

function hideSubNav() {
	document.getElementById( 'subNav_' + currentSubNav ).style.display = 'none';
	if ( selectedSubNav != '' ) {
		document.getElementById( 'subNav_' + selectedSubNav ).style.display = 'block';
	}
}

function showSubNav( id ) {
	if ( currentSubNav != '' ) {
		document.getElementById( 'subNav_' + currentSubNav ).style.display = 'none';
	}
	document.getElementById( 'subNav_' + id ).style.display = 'block';
	currentSubNav = id;
}

function preloadImages( arrImages ) {
	for ( var i in arrImages ) {
		var image = new Image();
		image.src = arrImages[i];
	}
}
function fadeIn() {
	anim2.animate();
}
function fadeOut() {
	anim.animate();
}
function setGalleryImage() {
	document.getElementById( 'gallery' ).style.backgroundImage = 'url(' + images[ currentGalleryImage ] + ')';
	fadeIn();
}
function showGalleryImage( num, stopInterval ) {

	if ( stopInterval ) {
		clearInterval( imageInterval );
	}
	
	if ( num == '+' ) {
		currentGalleryImage++;
	} else if ( num == '-' ) {
		currentGalleryImage--;
	}
	
	if ( currentGalleryImage < 0 ) {
		currentGalleryImage = ( images.length - 1 );
	} else if ( currentGalleryImage > ( images.length - 1 ) ) {
		currentGalleryImage = 0;
	}

	if ( ( num != '+' ) && ( num != '-' ) ) {
		currentGalleryImage = num;
		setGalleryImage();
	} else {
		anim.onComplete.subscribe(setGalleryImage);
		fadeOut();
	}
}
function showNextGalleryImage() {
	showGalleryImage( '+', false );
}
