// Dictionary of sounds by element ID
// This dictionary defines the associations between the
// navigation and sounds to play
//	FORMAT:
//		"element-id0"     : [ "file1", "file2", ..., "fileN" ],
//		"element-id1"     : [ "file1", "file2", ..., "fileN" ],
//		...
//		"element-id(N-1)" : [ "file1", "file2", ..., "fileN" ]
//
var soundAssociations = {
	"nav-home"          : [ "dooropen.mp3" ],
	"nav-specials"      : [ "firefx7.mp3" ],
	"nav-reservations"  : [ "bugle.mp3" ],
	"nav-about"         : [ "reelgo.mp3" ],
	"nav-activity"      : [ "meadow.mp3" ],
	"nav-accomodations" : [ "beep.mp3" ],
	"nav-rentals"       : [ "bikehorn.mp3" ],
	"nav-facilities"    : [ "camera1.mp3" ],
	"nav-gift"          : [ "bird.mp3" ],
	"nav-vacation"      : [ "ribbit.mp3" ],
	"nav-brochure"      : [ "pageturn.mp3" ],
	"nav-contact"       : [ "chiplaff.mp3" ]
};

// Path to MP3 player
var PLAYER_PATH = "jmp3/flash/";	// (relative path from root directory)

// Path to directory where each item in sounds is located
var SOUND_FILE_DIR = "media/";		// (relative path from root directory)


/************** DO NOT CHANGE ANYTHING BEYOND THIS POINT!! **************/

function preloadSounds()
{
	var loadedFiles = new Array();
	
	// Not sure if this is actually preloading the files...	
	// Using the <embed> tag loads the default media player unless we specify the plugin.
	for( var key in soundAssociations )
	{
		jQuery.each( soundAssociations[ key ], function() { 
			if( !loadedFiles[ this ] ) 
			{
				loadedFiles[ this ] = true;
				//'<embed id src="' + ('media/' + this) + '" autostart="false" width="100" height="20" />'
				$("#mp3player").append( '<div>' + this + '</div>' );
			}
		});
	}
	
	// Play sounds in the background to preload them
	$("#mp3player div").jmp3({
		filepath: "media/",
		width: 1,
		height: 1,
		showdownload: "false",
		showfilename: "false",
		volume: 0,
		autoplay: "true"
	});	
}

$(document).ready( function() {
	preloadSounds();
				
	// Enable sounds for all anchor tags in the
	// .menulist where the ID attribute is defined.
	// This ensures that submenus will not play a 
	// sound when the mouse cursor is positioned
	// over them (unless the ID attribute in the 
	// submenues is defined :-s)
	$(".menulist li a[id]").hover(
		// Mouse-over event handler
		function() { 
			var key = jQuery(this).attr( "id" );
			var sndFile = soundAssociations[ key ];
			
			if( sndFile )
			{
				// Set up the MP3 player options
				// Note that a random sound is being played
				var options = { 
					filepath: "media/" + sndFile.random(),
					width: 1,
					height: 1,
					showdownload: "true",
					showfilename: "true",
					autoplay: "true"
				};
				
				// Play the sound
				$("#mp3player")
					.empty()
					.show()
					.jmp3( options );
			}
		},
		
		// Mouse-out event handler
		function() {
			$("#mp3player").hide();
		}
	); 
});
