// Sound function
// GLOBAL variables 
	var no_of_children = 0;
	var play_sound = 0;
	var sound_src_name = '';
	var using_embed_tag = 0;
// Load a MIDI or MP3 background file
function loadSound(filename) {
		sound_src_name = filename;
		
	if (!sound_src_name) { return 0; }	
							
	if (navigator.appName == "Microsoft Internet Explorer") {
		document.writeln ('<BGSOUND id="background_music" SRC="' + sound_src_name + ' AUTOSTART="false" LOOP="10">');
		document.writeln ('<a href="javascript:void(0);" onclick="toggleSound(\'background_music\'); return false;" id="background_music_control" class="bmgcontrol">Start Sound</a>');
	} else {
		document.writeln ('<EMBED id="background_music" SRC="' + sound_src_name + '" AUTOSTART="FALSE" WIDTH="100" HEIGHT="16" LOOP="3" enablejavascript="true">');
			using_embed_tag = 1;
	}
								
		play_sound = 0;
}

// Toggle the background sound ON or OFF
// Takes: ID of BGSOUND/EMBED tag
function toggleSound(id) {
		var sound_id = document.getElementById(id);
		var control_id = document.getElementById(id + '_control');

	// if control_id exists, then change the text of it
	// if not, then the sound is coming from an embed tag

	if (play_sound) {
		// Turn sound OFF
		if (!using_embed_tag) {
				sound_id.src = '';

			if (control_id) {
				control_id.innerHTML = 'Start Sound';
			}
		} else {
			sound_id.Stop();	
		}		

			play_sound = 0;
	} else {
		// Turn sound ON
		if (!no_of_children) {
						
			if (!using_embed_tag) {
		 		sound_id.src = sound_src_name;

				if (control_id) {
					control_id.innerHTML = 'Stop Sound';
				}
			} else {
				sound_id.Play();
			}	

				play_sound = 1;
		}
	}
}