var isPlaySound = true;
var relayPlay = true;
var soundInterval = null;
function soundOn() {
	if (parent.soundMode && !parent.isBGM) {
		clearSound();
		if (isPlaySound == true && parent.sounds.length != 0) {
			for (var i=0; i<parent.sounds.length; i++) {
				var temp = parent.sounds[i].split(".");
				var fileIndex = temp[0].split("_");
				if (parent.briefLeftPage == fileIndex[0]) {
					SoundPlayer.Stop();
					var soundSource = parent.soundDir + parent.sounds[i];
					SoundPlayer.Open(soundSource);
					if (relayPlay == true) {
						if (parent.briefLeftPage >= parent.lastPage-1) {
							soundInterval = window.setTimeout("GotoPage(parent.firstPage)",fileIndex[1]*1000);
						} else { 
							soundInterval = window.setTimeout("LeafToNext()",fileIndex[1]*1000);
						}
					}
					return;
				}
			}
		}
		SoundPlayer.Stop();
	}
}

function soundOnForMac() {
	if (parent.soundMode && !parent.isBGM) {
		clearSound();
		if (isPlaySound == true && parent.sounds.length != 0) {
			for (var i=0; i<parent.sounds.length; i++) {
				var temp = parent.sounds[i].split(".");
				var fileIndex = temp[0].split("_");
				if (parent.briefLeftPage == fileIndex[0]) {
//					SoundPlayer.Stop();
					var soundSource = parent.soundDir + parent.sounds[i];
					parent.frames['Frame_Hind'].SoundPlayerForMac.src = soundSource;
//					SoundPlayer.Open(soundSource);

					if (relayPlay == true) {
						if (parent.briefLeftPage >= parent.lastPage-1) {
							soundInterval = window.setTimeout("GotoPage(parent.firstPage)",fileIndex[1]*1000);
						} else { 
							soundInterval = window.setTimeout("LeafToNext()",fileIndex[1]*1000);
						}
					}
					return;
				}
			}
		}
//		SoundPlayer.Stop();
	}
}

function goRelayPlay() {
	if (parent.soundMode && !parent.isBGM) {
		clearSound();
		if (isPlaySound == true && parent.sounds.length != 0) {
			for (var i=0; i<parent.sounds.length; i++) {
				var temp = parent.sounds[i].split(".");
				var fileIndex = temp[0].split("_");
				if (parent.briefLeftPage == fileIndex[0]) {
					if (relayPlay == true) {
						if (parent.briefLeftPage >= parent.lastPage-1) {
							soundInterval = window.setTimeout("GotoPage(parent.firstPage)",fileIndex[1]*1000);
						} else { 
							soundInterval = window.setTimeout("LeafToNext()",fileIndex[1]*1000);
						}
					}
					return;
				}
			}
		}
	}
}

function clearSound() {
	clearTimeout(soundInterval);
}
