/**
 * Copyright(c) Dreamcode Technology <http://www.dreamcode.net/>
 * 
 * @author Joe Au <joe@dreamcode.net>
 */



function Flash( instance ) {
	if (instance) this.setInstance(instance);
}

Flash.prototype = new Object();

Flash.prototype.setInstance = function( instance ) {
	this.init = false;
	if (instance) {
		this.instance = instance;
		this.id = (typeof(instance.id) != 'undefined') ? instance.id : instance.name;
		this.init = true;
	}
};

Flash.prototype.loadMovie = function( target, url ) {
	if (this.init) this.instance.LoadMovie(target, url);
}

Flash.prototype.set = function( key, value ) {
	if (this.init) this.instance.SetVariable(key, value);
}

Flash.prototype.play = function( ) {
	if (this.init) {
		this.instance.GotoFrame(1);
		this.instance.Play();
	}
}

Flash.prototype.gotoAndPlay = function( target, frame ) {
	if (this.init) {
		if (typeof(frame) == 'string') {
			this.instance.TGotoLabel(target, frame);
			this.instance.TPlay(target);
		} else if (typeof(frame) == 'number') {
			this.instance.TGotoFrame(target, frame);
			this.instance.TPlay(target);
		}
	}
}

Flash.prototype.gotoAndStop = function( target, frame ) {
	if (this.init) {
		if (typeof(frame) == 'string') {
			this.instance.TGotoLabel(target, frame);
		} else if (typeof(frame) == 'number') {
			this.instance.TGotoFrame(target, frame);
		}
	}
}

Flash.getInstance = function( name ) {
	if (top.frames.length) {
		for (var i = 0; i < top.frames.length; i++) {
			var win = top.frames[i];
			if (navigator.appName.toLowerCase() == "netscape") {
				if (win.document[name]) {
					return new Flash(win.document[name]);
				}
			} else {
				if (win[name]) {
					return new Flash(win[name]);
				}
			}
		}
		return null;
	} else {
		var win = top;
		if (navigator.appName.toLowerCase() == "netscape") {
			if (win.document[name]) {
				return new Flash(win.document[name]);
			} else {
				return null;
			}
		} else {
			if (win[name]) {
				return new Flash(win[name]);
			} else {
				return null;
			}
		}
	}
}

