X.ns('X.flash.getSWF', function(swfName)
{
	var swf = null;
	
	/*
	window.document[movieName]      // (on Mozilla browsers)
	window[movieName]               // (on Internet Explorer as of ver 5)
	document.embeds[movieName]      // Firefox or Opera
	*/
	if (window.document[swfName])
	{
		//console.log('X.flash.getSWF:: window.document');
		swf = window.document[swfName] || null;
	}
	else if (document.embeds && document.embeds[swfName])
	{
		//console.log('X.flash.getSWF:: document.embeds');
		swf = document.embeds[swfName] || null;
	}
	else
	{
		//console.log('X.flash.getSWF:: window');
		swf = window[swfName] || null;
	}
	
	return swf;
});

// Returns jQuery chain if setting callback (second arg is a function)
// Else returns result of callback
jQuery.fn.flashCallback = function(name, func)
{
	var flashCallbacks = this.data('flashCallbacks');
	if (typeof(name) !== 'string')
	{
		for (var prop in name)
		{
			this.flashCallback(prop, name[prop]);
		}
	}
	else
	{
		if (jQuery.isFunction(func))
		{
			if (!flashCallbacks)
			{
				flashCallbacks = {};
				this.data('flashCallbacks', flashCallbacks);
			}
			flashCallbacks[name] = func;
			return this;
		}
		else
		{
			if (!flashCallbacks || !jQuery.isFunction(flashCallbacks[name])) { return; }
			return flashCallbacks[name](data);
		}
	}
};

// Registers a callback (or calls) for when a swf is loaded
X.ns('X.flash.loadCallback', function(swfId, func)
{
	if (jQuery.isFunction(func))
	{
		X.flash.loadCallback[swfId] = func;
	}
	else if (jQuery.isFunction(X.flash.loadCallback[swfId]))
	{
		X.flash.loadCallback[swfId]();
	}
});

// Calls function in flash
// Returns results of function
// NOTE: args is an associative array (object key value pairs)
X.ns('X.flash.callMethod', function(swfId, ns, methodName)
{
	var swf = X.flash.getSWF(swfId);
	if (!swf)
	{
		console.log('WARNING! X.flash.callMethod(swfId: "' + swfId + '", methodName: "' + methodName + '"):: swf does not exist.');	
		return;
	}
	if (!jQuery.isFunction(swf.jsProxy))
	{
		console.log('WARNING! X.flash.callMethod(swfId: "' + swfId + '", methodName: "' + methodName + '"):: swf.jsProxy is not a function.');
		return;
	}
	if (typeof(ns) !== 'string')
	{
		ns = '';
	}
	return swf.jsProxy(methodName, jQuery.makeArray(arguments).slice(3), ns);
});
jQuery.fn.bindFlash = function(type, handler)
{
	return this.bind('flashEvent_' + type, function(evt, flashEvt)
	{
		handler.call(this, flashEvt);
	});
};
// Triggers a flash event - called from flash player
// returns nothing
X.ns('X.flash.triggerFlash', function(swfId, evt)
{
	jQuery('#' + swfId).triggerHandler('flashEvent_' + evt.type, evt);
});