
function load_location(loc, cat, sub) {
	redirect = "index.php?loc=" + loc.replace(/ /g, "_");
	if(cat) {
		redirect += "&cat=" + cat.replace(/ /g, "_");
	}
	if(sub) {
		redirect += "&sub=" + sub.replace(/ /g, "_");
	}
	
	window.location = redirect;
}

function go_home () {
	window.location = "index.php";
}

function set_display_image (name) {
	$('display_image').src = current_path + '/_images/' + name + '.png';
	set_display_details(name);
}

function set_display_video(name, type) {
	if(type == "mov")
		set_display_movie(name);
	else
		set_display_flash(name);
}

function set_display_movie (name) {
	$("movie_details").hide();
	$("gallery_main_image_area").show();
	var temp_movie = new Element('object', {'classid': 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B', 'width': '320', 'height': '256', 'codebase': 'http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0'});
	temp_movie.appendChild(new Element('param', {'name': 'src', 'value': current_path + '/_movies/' + name + '.mov'}));
	temp_movie.appendChild(new Element('param', {'name': 'autoplay', 'value': 'true'}));
	temp_movie.appendChild(new Element('param', {'name': 'loop', 'value': 'false'}));
	temp_movie.appendChild(new Element('param', {'name': 'controller', 'value': 'true'}));

	var embed_element = new Element('embed', {'src': current_path + '/_movies/' + name + '.mov', 'width': '320', 'height': '256', 'autoplay': 'true', 'loop': 'false', 'controller': 'true', 'pluginspage': 'http://www.apple.com/quicktime/'});
	
	$('movie_div').innerHTML = '';
	
	if(!Prototype.Browser.IE) {
		temp_movie.appendChild(embed_element);
		$('movie_div').appendChild(temp_movie);
	}
	else {
		$('movie_div').appendChild(embed_element);
	}
	temp_movie = null;
	set_display_details(name);
}

function set_display_flash (name) {
	$("movie_details").hide();
	$("gallery_main_image_area").show();
	var temp_movie = new Element('object', {'classid': 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000', 'width': '320', 'height': '240', 'codebase': 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0'});
	temp_movie.appendChild(new Element('param', {'name': 'src', 'value': current_path + '/_movies/' + name + '.swf'}));
	temp_movie.appendChild(new Element('param', {'name': 'allowScriptAccess', 'value': 'sameDomain'}));
	temp_movie.appendChild(new Element('param', {'name': 'allowFullScreen', 'value': 'false'}));
	temp_movie.appendChild(new Element('param', {'name': 'movie', 'value': current_path + '/_movies/' + name + '.swf'}));
	temp_movie.appendChild(new Element('param', {'name': 'quality', 'value': 'high'}));
	temp_movie.appendChild(new Element('param', {'name': 'bgcolor', 'value': '#000000'}));

	var embed_element = new Element('embed', {'src': current_path + '/_movies/' + name + '.swf', 'width': '320', 'height': '240', 'bgcolor': '#000000', 'name': 'grad_show_preview', 'align': 'middle', 'allowScriptAccess': 'sameDomain', 'allowFullScreen': 'false', 'type': 'application/x-shockwave-flash', 'pluginspage': 'http://www.macromedia.com/go/getflashplayer'});
	
	$('movie_div').innerHTML = '';
	
	if(!Prototype.Browser.IE) {
		temp_movie.appendChild(embed_element);
		$('movie_div').appendChild(temp_movie);
	}
	else {
		$('movie_div').appendChild(embed_element);
	}
	temp_movie = null;
	set_display_details(name);
}
 
function set_display_details (image_name) {
	$('media_name').hide();
	$('media_subtext').hide();
	$('details_surround').hide();
	$('picture_note').hide();
	if(image_meta_data[image_name]) {
		if(image_meta_data[image_name]['title']) {
			$('media_name').innerHTML = image_meta_data[image_name]['title'];
			$('media_name').show();
		}
		if(image_meta_data[image_name]['size'] || image_meta_data[image_name]['material']) {
			mat_size_string = (image_meta_data[image_name]['size'])?'' + image_meta_data[image_name]['size']:'';image_meta_data[image_name]['material'];
			mat_material_string = (image_meta_data[image_name]['material'])?'' + image_meta_data[image_name]['material']:'';
			total_string = mat_size_string;
			if(mat_size_string > '' && mat_material_string > '') {
				total_string += ' - ';
			}
			total_string += mat_material_string;
			$('media_subtext').innerHTML = total_string;
			$('media_subtext').show();
		}
		if(image_meta_data[image_name]['details']) {
			$('details_surround').innerHTML = "";
			image_meta_data[image_name]['details'].each( function (s) {
				var temp_image = new Element('img', {'title': s, 'alt': s, 'src': current_path + '/_details/' + s + '.png'}).observe('click', show_detail);
				$('details_surround').appendChild(temp_image);
				temp_image = null;
			});
			$('details_surround').show();
		}
		if(image_meta_data[image_name]['movie_details']) {
			$("show_details").show();
			$('movie_details_inner').innerHTML = "";
			image_meta_data[image_name]['movie_details'].each( function (s) {
				var temp_image = new Element('img', {'title': s, 'alt': s, 'src': current_path + '/_details/' + s + '.png'});
				$('movie_details_inner').appendChild(temp_image);
				temp_image = null;
			});
		}
		else {
			if($("show_details")) {
				$("show_details").hide();
			}
		}
		if(image_meta_data[image_name]['note']) {
			$('picture_note').innerHTML = image_meta_data[image_name]['note'];
			$('picture_note').show();
		}
	}
}

function initialize() {
	var dark_background = new Element('div', {'id': 'dark_background'}).hide();
	var dark_data = new Element('div', {'className': 'dark_data'});
	dark_data.observe('click', hide_detail);
	var dark_button_bar = new Element('div', {'className': 'button_bar'}).update('close');
	var image_surround = new Element('div', {'className': 'float_image_surround'});
	var float_image = new Element('img', {'id': 'float_image'});
	dark_data.appendChild(dark_button_bar);
	image_surround.appendChild(float_image);
	
	dark_data.appendChild(image_surround);
	dark_background.appendChild(dark_data)
	$('body_protect').appendChild(dark_background);
	dark_float = null;
}

function show_detail(e) {
	if(!e) {
		e = window.event;
	}
	var source_location = (e.src)?e.src:e.element().src;
	$('float_image').src = source_location;
	$('dark_background').show();
}

function hide_detail() {
	$('dark_background').hide();
}

function show_movie_detail () {
	$("gallery_main_image_area").hide();
	$("movie_details").show();
}

function hide_movie_detail () {
	$("movie_details").hide();
	$("gallery_main_image_area").show();
}