// JavaScript Document
function WriteQTAudio()
{
	writeAudioQuickTime({width:1, height:1, id:"mp3", src:"/images/empty.mp3", controller:false, autoplay:false, enablejavascript:true,bgcolor:340002});
}
var lastmp3file = null;
function doPlayStop(mp3file)
{
	if (mp3file == null) mp3file = lastmp3file;
	else lastmp3file = mp3file;
	
	var mp3 = document.mp3;
	var currentStatus = null;
	var currentFile = null;
	var currentEnd = null;
	var currentTime = null;
	var playing = false;
	var samefile = false;
	var host = document.location.protocol + "//" + document.location.host;
	
	if (mp3 == null) mp3 = $("mp3");
	if (mp3 == null) return false;

	try {
		currentStatus = mp3.GetPluginStatus();
		currentStatus = currentStatus.toLowerCase();
		currentFile = mp3.GetURL();
	}
	catch(e) {
		window.setTimeout("doPlayStop(null)",1000);
		return false;
	}
	switch (currentStatus) {
		case "waiting":
		case "loading":
		case "playable":
		case "complete":
			playing = true;
			currentEnd = mp3.GetEndTime();
			currentTime = mp3.GetTime();
			break;
	}
	if (playing) playing = ((currentTime != 0) && (currentTime < currentEnd));
	currentFile = currentFile.substring(host.length);
	samefile = (currentFile == mp3file);
	/*
	alert(	"Host : " + host +
	"\nCurrentFile : " + currentFile +
	"\nStatus\/Time\/End : " + currentStatus + "\/" + currentTime + "\/" + currentEnd +
	"\nPlaying : " + playing +
	"\nRequiredFile : " + mp3file +
	"\nSameFile : " + samefile	);
	*/
	if (playing) {
		mp3.Stop();
		mp3.SetTime(0);
	}
	if ((!playing) || (!samefile)) {
		mp3.SetResetPropertiesOnReload(false);
		mp3.SetURL(mp3file);
		window.setTimeout("playTimer(true)",200);
	}
	return false;
}
function playTimer(fromPlay)
{
	var mp3 = document.mp3;
	if (mp3 == null) mp3 = $("mp3");
	if (mp3 == null) return;
	if (fromPlay) {
		try {
			mp3.Play();
		}
		catch (e) {
		}
		window.setTimeout("playTimer(false)",1000);
	}
	else {
		var currentStatus = mp3.GetPluginStatus();	//"Waiting","Loading","Playable","Complete"
		currentStatus = currentStatus.toLowerCase();
		switch (currentStatus) {
			case "waiting":
			case "loading":
				window.setTimeout("playTimer(false)",1000);
				break;
			case "playable":
			case "complete":
			default:
				mp3.Play();
				break;
		}
	}
}
