window._swfName = "ApArchive";
window.p_auto = true;
window.p_mode = "progressive";
window.p_rtmp = null;
window.p_flv = null;

function controller(path, params) {
	//alert(path + "\n" + params);
	//When Flash calls this method, params == id we passed in earlier
	switch (path) {
		// the SWF calls this JS function when AC_RunActiveContent loads SWF, so that JS can call SWF functions (ie play, seek, etc), without this acknowledgement JS can throw error trying to access functions that are not ready.  
		case 'VideoSwfReady':
			controller.initilized = true;
			//alert([window.p_flv, window.p_mode, window.p_rtmp, window.p_auto]);
			//controller('PlayVideo', [window.p_flv, window.p_mode, window.p_rtmp, window.p_auto]);
			break;
		// JS call to play video on SWF, params are p1 = p_flv (Video Source String), p2 = p_mode (Stream or Progressive Mode String), p3 = p_rtmp, p4 = p_auto (AutoPlay Mode Boolean)      
		case 'PlayVideo':
			swf(window._swfName).PlayVideo(params[0], params[1], params[2], params[3]);
			break;
		// JS call to seek video to specified seconds     
		case 'SeekToVideoAt':
			swf(window._swfName).SeekToVideoAt(params);
			break;
		//		case 'NetStreamPlayStreamNotFound':      
		//		    alert('Video was not found.');      
		//		break;      
		//		default:      
		//		    alert('Unknown command: ' + path);      
			break;
	}
}
controller.initilized = false;

function swf(swf) {
	if (window.document[swf]) { return window.document[swf]; }
	else if (document.embeds && document.embeds[swf]) { return document.embeds[swf]; }
	else { return document.getElementById(swf); }
}

var VideoPlayerProxy = Class.create({
	initialize: function(holderId) {
		this.holderId = holderId;
		this.args = Object.extend({
			'codebase': 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0',
			'name': window._swfName,
			'id': window._swfName,
			'width': '320',
			'height': '288',
			'align': 'middle',
			'quality': 'high',
			'bgcolor': '#FFFFFF',
			'play': 'true',
			'loop': 'true',
			'devicefont': 'false',
			'scale': 'showall',
			'wmode': 'transparent',
			'menu': 'false',
			'allowfullscreen': 'false',
			'allowscriptaccess': 'always',
			'pluginspage': 'http://www.macromedia.com/go/getflashplayer',
			'src': '/images/flash/210/oneup',
			'mode': 'progressive'
		}, arguments[1] || {});
		this.args["movie"] = this.args.src;

		this.playerArgs = Object.extend({
			auto: 'true'
		}, arguments[2] || {});

		window.p_mode = this.args.mode;
		window.p_auto = this.args.auto;
		if (this.playerArgs.videourl)
			window.p_flv = this.playerArgs.videourl;

		this.swfName = this.args.name;
		this.generateHtml();
	},

	generateHtml: function() {
		this.args["flashvars"] = Object.toQueryString(this.playerArgs);
		this.html = AC_FL_RunContent.apply(this, $H(this.args).toArray().flatten());
	},

	renderPlayer: function(url, caption) {
		if (url) {
			this.playerArgs.videourl = url;
			this.playerArgs.caption = caption;
			this.generateHtml();
		}

		if (this.playerArgs.videourl || window.p_flv != "") {
			var hole = $(this.holderId);
			if (document.write == Prototype.emptyFunction || hole)
				$(this.holderId).update(this.html);
			else
				document.write(this.html);

			this.swf = this.getSwf(this.swfName);
		}
	},

	getSwf: function(swf) {
		var obj;
		if (window.document[swf])
			obj = window.document[swf];
		else if (document.embeds && document.embeds[swf])
			obj = document.embeds[swf];
		else
			obj = document.getElementById(swf);
		return obj;
	},

	Seek: function(time) {
		this.swf = this.getSwf(this.swfName);
		if (this.swf) {
			//controller("SeekToVideoAt", time);
			this.swf.SeekToVideoAt(time);
		}
	},

	SetVideo: function(url) {
		this.swf = this.getSwf(this.swfName);
		if (this.swf) {
			//window.p_flv = url;
			//this.playerArgs.videourl = url;
			//controller('VideoSwfReady');
			this.swf.PlayVideo(url, this.args.mode, window.p_rtmp, this.playerArgs.auto);
			return true;
		}
		return false;
	},

	Play: function(url, caption) {
		this.swf = this.getSwf(this.swfName);
		if (this.swf) {
			//window.p_flv = url;
			//this.playerArgs.videourl = url;
			//controller('VideoSwfReady');
			this.swf.PlayVideo(url, this.args.mode, window.p_rtmp, "true", caption || this.playerArgs.caption);
			return true;
		}
		return false;
	}

});