var Sound = new Object();
var elementPlaying = "";

Sound.play = function Sound_play(src) {
	//http://www.danfergusdesign.com/classfiles/VCA225-digiProduction/exercises/ex-audioEmbed.html

	var elm;
	if (!src) 
		return false;
	this.stop();
	if (navigator.appName=="Microsoft Internet Explorer" ) {

		/*
		var htm = "<html>";
		htm += "<head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />";
		htm += "<meta name='robots' content='index,follow' />";
		htm += "<meta name='classification' content='music, composers, compositions, film music, movie music' />";
		htm += "<title>Music | Ryan Stewart | Composer for Film, TV, and Orchestral Music</title></head>";
		htm += "<body><form><OBJECT id='sound' name='sound' classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' width='0' height='0'>";		htm += "<PARAM name='src' value='" + src + "'>";		htm += "<EMBED id='sound1' name='sound1' width='0' height='0' src='" + src + "' TYPE='audio/x-mpeg' PLUGINSPAGE='www.apple.com/quicktime/download' enablejavascript='true'></EMBED></OBJECT></form></body></html>";
		*/

		if (typeof document.all != "undefined") 
		{
			var htm = "<html>";
			htm += "<head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />";
			htm += "<meta name='robots' content='index,follow' />";
			htm += "<meta name='classification' content='music, composers, compositions, film music, movie music' />";
			htm += "<title>Music | Ryan Stewart | Composer for Film, TV, and Orchestral Music</title></head>";
			htm += "<body><form><bgsound src='" + src + "'></bgsoun></form></body></html>";			//elm = document.createElement("bgsound");			//elm.src = src;		}

		/*
		var htm = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><meta name='robots' content='index,follow' /><meta name='classification' content='music, composers, compositions, film music, movie music' /><title>Music | Ryan 		Stewart | Composer for Film, TV, and Orchestral Music</title></head><body><form><object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab'> ";
		htm += "<param name='src' value='" + src + "' />";
		htm += "<param name='autoplay' value='false' />";
		htm += "<param name='autostart' value='0' />";
		htm += "<param name='controller' value='true' />";
		htm += "<param name='pluginspage' value='http://www.apple.com/quicktime/download/' />";

		htm += "<object id='sound1' type='audio/x-mpeg' data='" + src + "'>";
		htm += "<param name='pluginurl' value='http://www.apple.com/quicktime/download/' />";
		htm += "<param name='controller' value='true' />";
		htm += "<param name='autoplay' value='false' />";
		htm += "<param name='autostart' value='0' />";
		htm += "</object></object></form></body></html>";

		document.body.insertAdjacentHTML('beforeEnd', htm);
		elm = document.getElementById("sound");
		this.elm = elm;
		return true;
		*/		
		var newDoc = window.parent.frames[1].document.open("text/html", "replace");
		newDoc.write(htm);
		newDoc.close();
		return true;
	}
	else {

		elm = document.createElement("object");
		elm.setAttribute("controller","true");
		elm.setAttribute("autoplay","true");
		elm.setAttribute("pluginurl", "http://www.apple.com/quicktime/download/");
		elm.setAttribute("type","audio/x-mpeg");
		elm.setAttribute("data", src);
		elm.setAttribute("src", src); 		//required for explorer 6+ and safari
		document.body.appendChild(elm);
		this.elm = elm;
		return true;
	}
};

Sound.stop = function Sound_stop() {
	if (this.elm) {
		if (navigator.appName != "Microsoft Internet Explorer") {
			this.elm.Stop();	//stop the player programatically
			this.elm.parentNode.removeChild(this.elm);
			this.elm = null;
			return true;
		}
	}
};

Sound.stopIE = function Sound_StopIE() {
	//add defensive code check to control functionality for IE since this code will cause javascript validation errors.
	if (navigator.appName == "Microsoft Internet Explorer") {
		var newDoc = window.parent.frames[1].document.open("text/html", "replace");
		var htm = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />";
		htm += "<meta name='robots' content='index,follow' />";
		htm += "<meta name='classification' content='music, composers, compositions, film music, movie music' />";
		htm += "<title>Music | Ryan Stewart | Composer for Film, TV, and Orchestral Music</title></head><body><form></form></body></html>";
		newDoc.write(htm);
		newDoc.close();
		return true;
	}
}

function ToggleValue(val, song) {

	//alert(navigator.appName);

	if (navigator.appName == "Microsoft Internet Explorer") 
		Sound.stopIE();
	else
		Sound.stop();

	if(elementPlaying.length > 0 && elementPlaying != val.id) {
		document.getElementById(elementPlaying).value = "play";
		//document.getElementById(elementPlaying).style.border='2px solid'+' white';
		document.getElementById(elementPlaying).style.visibility = 'hidden';
		document.getElementById(elementPlaying + "Url").innerHTML = 'play';
		elementPlaying = "";
	}
	if(val.value == "listening") {
		document.getElementById(val.id).value = "play";
		//document.getElementById(val.id).style.border='2px solid'+' white';
		document.getElementById(val.id).style.visibility = 'hidden';
		document.getElementById(val.id + "Url").innerHTML = 'play';
	}
	else {
		Sound.play(song);
		document.getElementById(val.id).value = "listening";
		//document.getElementById(val.id).style.border='2px solid'+' #f1880b';
		document.getElementById(val.id).style.visibility = 'visible';
		document.getElementById(val.id + "Url").innerHTML = 'stop';
		elementPlaying = val.id;
	}
}
