/**
 * A class to create instances of te RMXWrapper class and to handle events dispatched by a Flash movie.
 * NOTE: All methods are static
 */
function RMXController() {
	;
}
// An Array of RMXWrapper instances
RMXController.wrappers = new Array();
/**
 * Creates and returns an instance of the RMXWrapper class
 * @param id The id of the Flash movie to create a RMXWrapper instance for
 */
RMXController.createWrapper = function(id) {
	//alert("RMXController.createWrapper");
	// Create the instance for the given id
	var rmxWrapper = new RMXWrapper(id);
	// Add the instance to the Array
	RMXController.wrappers.push(rmxWrapper);
	// Return the instance
	return rmxWrapper;
};
/**
 * Called by all Flash movies that dispatch events to JavaScript.
 * Used to forward the event to the correct RMXWrapper instance
 * @param id The id of the Flash movie that is dispatching the event
 * @param eventInfo The String representing the event 
 */
RMXController.onMovieEvent = function(id, eventInfo) {
	//alert("RMXController.onMovieEvent");
	//alert("id: " + id);
	//alert("eventInfo: " + eventInfo);
	for (var i = 0; i < this.wrappers.length; i++) {
		var wrapper = this.wrappers[i];
		//alert("wrapper.id: " + wrapper.id);
		if (wrapper.id == id) {
			//alert("dispatch to wrapper with id: " + wrapper.id);
			wrapper.onMovieEvent(eventInfo);
			break;
		}
	}
};
// Object to hold temporary data that is sent from the Flash movie
// This occurs when the data to be sent from Flash to JavaScript
// exceeds 508 characters in length and is therefore split into
// smaller messages
RMXController.dataStore = new Object();
/**
 * Called by the Flash movie to transfer a packet of data
 * @param id The id of the calling Flash movie
 * @param data The packet of data being sent
 * @param numPackets The total number of packets that need sending
 * @param curPacket The current packet being sent
 */
RMXController.recievePacket = function(id, data, numPackets, curPacket) {
	//alert("recievePacket");
	// If this is the first packet
	if (curPacket == 0) {
		// Define the store we are writing to
		this.dataStore[id] = "";
	}
	// Append the packet to the store
	this.dataStore[id] += data;
	// If this is the last packet
	if (curPacket == numPackets-1) {
		// Call onMovieEvent method
		this.onMovieEvent(id, this.dataStore[id]);
	}
	
};
