// Copyright(c) 1999/2/22 Leadware Co., Ltd.
// 本程式著作權屬高手軟體有限公司，凡有侵犯，依法追究，絕不寬怠
// JavaScript Classes for Embeded Sound Objects Control
// Version 2.0.0
function sndEnabled() {
	switch(jvsrunway) {
		case 2: return true;
		default:
		case 1:
			var pg= navigator.plugins["LiveAudio"];
			var tp= pg["audio/wav"];
			if(tp && (tp.enabledPlugin== pg)) return true;
		}
	return false;
	}

function objSound(o) {
	this.obj= ((typeof(o)== "string") ? document[o]:o);
	this._loop= 1;
	this._volume= 50;

	this.waitplay= objSndWaitPlay;
	this.clearwaitplay= objSndClearWaitPlay;
	this._timeoutwait= null;
	this._timewait= 0;

	this.play= objSndPlay;
	this.replay= objSndReplay;
	this.pause= objSndPause;
	this.pausekeep= objSndPauseKeep;
	this.stop= objSndStop;
	this.loop= objSndLoop;
	this.volume= objSndVolume;
	this.status= objSndStatus;
	this.checkready= objSndCheckReady;
	this.objready= soundReady(this.obj) && sndEnabled();
	this.checkready();

	return this;
	}

function objSndStatus() {
	if(!this.objready) return -1;
	switch(jvsrunway) {
		case 2: return SndIEPlayState(this.obj);
		default:
		case 1:
			if(this.obj.IsPaused()) return 1;
			if(this.obj.IsPlaying()) return 2;
			if(!this.obj.IsReady()) return -1;
		}

	return 0;
	}

function objSndLoop(n) {
	if(n!= null) {
		if(n<0) n= 0;
		this._loop= n;
		switch(jvsrunway) {
			case 2: this.obj.PlayCount= n;  break;
			default:
			case 1: break;
			}
		}

	return this._loop;
	}

function objSndVolume(v) {
	if(!this.ready) return 0;
	if(v!= null) {
		if(v<0) v= 0; else if(v>100) v= 100;
		this._volume= v;
		switch(jvsrunway) {
			case 2: this.obj.Volume= Math.sqrt(Math.sqrt(Math.sqrt(v)*10)*10)*964-9640;  break;
			default:
			case 1: this.obj.setvol(v);  break;
			}
		}

	return this._volume;
	}

function objSndReplay(n) {
	this.stop();
	this.play(n);
	}

function objSndPlay(n) {
	if(!this.ready) return;
	if(n!=null) this.loop(n);
	switch(jvsrunway) {
		case 2: SndIEPlay(this.obj);	break;
		default:
		case 1: this.obj.play((!this._loop) ? true:this._loop);	break;
		}
	}

function objSndCheckReady() {
	var t;

	this.objready= soundReady(this.obj) && sndEnabled();
	t= this.status();
	this.ready= this.objready && (t>=0) && (t<=2);
	return this.ready;
	}

function objSndClearWaitPlay() {
	if(this._timeoutwait!= null) clearTimeout(this._timeoutwait);
	this._timeoutwait= null;
	}

function objSndWaitPlay(n, vn, wt) {
	var dt= 1000;

	if(this._timeoutwait!= null) {
		clearTimeout(this._timeoutwait);
		this._timeoutwait= null;
		if((this._timewait-= dt)< 0) this._timewait= 0;
		}
	if(!sndEnabled()) return;
	while(1) {
		if(this._timewait) break;
		if(!soundReady(this.obj)) break;
		this.ready= true;
		this.play(n);
		return;
		}
	this._timeoutwait= setTimeout(vn+ ".waitplay("+ n+ ", \""+ vn+ "\", "+ wt+ ")", dt);
	}

function objSndStop() {
	if(!this.ready) return;
	switch(jvsrunway) {
		case 2: this.obj.Stop();  break;
		default:
		case 1: this.obj.stop();  break;
		}
	}

function objSndPauseKeep() {
	if(!this.ready) return;
	if(this.status()==2) this.pause();
	}

function objSndPause() {
	if(!this.ready) return;
	if(this.status()>0) {
		switch(jvsrunway) {
			case 2: if(this.status()==1) SndIEPlay(this.obj); else this.obj.Pause();  break;
			default:
			case 1: this.obj.pause();  break;
			}
		}
	}
