var current_screenshot = 0;
var max_screenshots = 0;
var current_gallery_name = '';
var current_gallery_array;
// screenshot gallery functions
function show_screenshot_gallery(gallery) {
	document.getElementById('screen_opacity_filter').style.display = 'block';
	document.getElementById('screenshot_gallery_window').style.display = 'block';
	current_gallery_name = gallery;
	target_gallery = gallery.replace(/-/g, '_');
	eval('current_gallery_array = '+ target_gallery + ';');
	current_screenshot = 0;
	max_screenshots = current_gallery_array.length;
	change_screenshot(0);
}

function hide_screenshot_gallery() {
	document.getElementById('screenshot_gallery_window').style.display = 'none';
	document.getElementById('screen_opacity_filter').style.display = 'none';
}

function change_screenshot(increment) {
	var new_screenshot_index = current_screenshot + increment;
	if (new_screenshot_index >= 0 && new_screenshot_index < max_screenshots) { // only perform action if we are not already at the beginning or end of screenshot array
		current_screenshot = new_screenshot_index; // change the screenshot index
		if (current_screenshot == 0) { // we have reached the first screenshot
			// change left nav arrow to disabled
			document.getElementById('screenshot_window_left_nav').className = 'nav_disabled';
		} else { // we new need to enable the left nav arrow
			document.getElementById('screenshot_window_left_nav').className = null;
		}
		if (new_screenshot_index == max_screenshots - 1) { // we have reached the last screenshot
			// change the right nav arrow to disabled
			document.getElementById('screenshot_window_right_nav').className = 'nav_disabled'; 
		} else { // we need to enable the right nav arrow
			document.getElementById('screenshot_window_right_nav').className = null;
		}
		// change the image source
		document.getElementById('screenshot_image').src = current_gallery_array[current_screenshot];
	}
}

function verify_gallery(gallery) {
	var target_gallery = 'gallery_'+gallery.replace(/-/g, '_');
	var gallery_test;
	eval ('gallery_test = typeof '+target_gallery+';');
	if (gallery_test == 'undefined') {
		return false;
	} else {
		return true;
	}
}

function show_gallery_link(gallery) {
	if (verify_gallery(gallery)) {
		document.getElementById('screenshots_' + gallery).style.display = 'block';
	}
}