$.namespace("trapeze.SWFObject");

trapeze.SWFObject = $.Class.extend({

	selector : null,
	swf : null,
	altContent : null,
	width : null,
	height : null,
	options : null,
	
	onSWFObjectComplete : function(status) {
		
		if (!status.success) {
			
			$(this.options.selector).load(this.options.altContent);
		}
		if (this.options.onSWFObjectComplete) this.options.onSWFObjectComplete(status);
	},
	
	init : function(selector, swf, altContent, options) {
		
		if (selector.indexOf("#") == -1) throw new Error("trapeze.SWFObject Selector must start with \"#\"");
		this.selector = selector;
		this.swf = swf;
		this.altContent = altContent;
		this.options = options;
		
		this.width = $(selector).width();
		this.height = $(selector).height();
		
		if (this.width == 0) throw new Error("trapeze.SWFObject Selector has no width defined.");
		if (this.height == 0) throw new Error("trapeze.SWFObject Selector has no height defined.");
				
		if (!this.options.expressInstall) {
			if (trapeze.media_path) {
				this.options.expressInstall = trapeze.media_path + "flash/express-install.swf";
			}
			else {
				this.options.expressInstall = "express-install.swf";
			}
		}
		
		if (!this.options.version) this.options.version = "9.0.115";
		
		if (!this.options.params) this.options.params = {};
		if (!this.options.flashvars) this.options.flashvars = {};
		if (!this.options.attributes) this.options.attributes = {};
		
		if (!this.options.params.allowscriptaccess) this.options.params.allowscriptaccess = "always";
		if (!this.options.params.menu) this.options.params.menu = "false";
		if (!this.options.params.wmode) this.options.params.wmode = "transparent";
		
		if (!this.options.flashvars.debug) this.options.flashvars.debug = trapeze.debug ? '3' : '1';
		
		options.swf = swf;
		options.selector = selector;
		options.altContent = altContent;
		
		swfobject.embedSWF(
			this.swf,
			this.selector.substring(1),
			this.width,
			this.height,
			this.options.version,
			this.options.expressInstall,
			this.options.flashvars,
			this.options.params,
			this.options.attributes,
			this.onSWFObjectComplete
		);
	}
});
