var menu = "main";
var current_location = null;

$(document).ready(function() {
	
	// MENU
	
	var menu_out_opacity = 0.65;
	var menu_over_opacity = 1.0;
	
	var menu_fade_in_speed = menu_fade_out_speed = 375;
	
	$('#' + menu + '_menu > a > img').css('opacity', menu_out_opacity);	
	$('#' + menu + '_menu > a').hover(
		function () {
			$(this).find('img').fadeTo(menu_fade_in_speed, menu_over_opacity);
		}, 
		function () {
			var name = this.id.substr(0, this.id.length - 4);
			if (name != current_location) {
				$(this).find('img').fadeTo(menu_fade_out_speed, menu_out_opacity);
			}
		}
	);
	
	var menu_array = Array('about', 'contact');
	
	// FADE OUT, THEN IN
	
	for (i = 0; i < menu_array.length; i++) {
	
		$('#' + menu_array[i]).hide();
		
		$('#' + menu_array[i] + '_btn').click(function() {
			var name = this.id.substr(0, this.id.length - 4);
			if (current_location != name) {
				if (current_location == null) {
					$('#' + name).fadeIn('slow');
					$('#' + name + '_menu').find('img').css('opacity', 100);
				} else {
					$('#' + current_location).fadeOut('slow', 
						function () {
							$('#' + name).fadeIn('slow');
						}
					);
					$('#' + name + '_btn > a').find('img').css('opacity', 100);
					$('#' + current_location + '_btn').find('img').fadeTo(menu_fade_out_speed, menu_out_opacity);
				}
				current_location = name;
			}
		});
	}
	
	// LOGO
	
	$('#logo').click(function() {
		if (current_location != null) {
			$('#' + current_location).fadeOut('slow');
			$('#' + current_location + '_btn').find('img').fadeTo(menu_fade_out_speed, menu_out_opacity);
			current_location = null;
		}
	});
	
	// UNHIDE
	
	$('#inner').removeClass('hidden');
});
