/** 
 *  Room3D Javascript API
*/
if (typeof $ == 'undefined') {
 function $(id) {
  if (typeof id == 'string') return document.getElementById(id);
  else return id;
 }
}

//FE
//========================================================================================================================
if (typeof FE == 'undefined')var FE = new Object();
FE._flash = null;
FE._flashContainer = null;
FE._baseURL = '';
FE._mapInstances = [];
FE._onMapLoad = function(id) {
	try {
		FE._mapInstances[id]._onLoad();
	} catch(e) {
		alert(e);
		throw e;
	}
}
FE.include = function(url) {
	document.write('<script type="text/javascript" src="' + url + '"></script>');
}
//========================================================================================================================

//FE.Event
//========================================================================================================================
FE.Event = {};
FE.Event.addListener = function(obj, name, closure) {
 obj.addListener(name, closure);
}

FE.Event.removeListener = function(obj, name, closure) {
 obj.removeListener(name, closure);
}
FE.Event.dispatch = function(obj, name) {
 obj.dispatch(name);
}

FE.Event.Dispatcher = function() {
 this._events = {};
}
FE.Event.Dispatcher.prototype.addListener = function(name, closure) {
 this._events[name] = closure;
}
FE.Event.Dispatcher.prototype.removeListener = function(name, closure) {
 delete this._events[name];
}
FE.Event.Dispatcher.prototype.dispatch = function(name) {
 if (this._events[name] != undefined) {
  var args = [this];
  for(var i=0; i<arguments.length; i++) args.push(arguments[i]);
  this._events[name].apply(this, args);
 }
}
//========================================================================================================================

//FE.Map
//========================================================================================================================
FE.Map = function(container, options) {
   options = options || {};
   this._id = Math.floor(Math.random() * 1000);
   this._container = $(container);
   FE.disableSelection(this._container);
   this.onLoad = null;
}
FE.Map.prototype = new FE.Event.Dispatcher(); 
FE.Map.prototype.load = function() {

  var flashObj = document.createElement("div"); 
  flashObj.setAttribute("id","_flash");
  flashObj.style.width = this._container.style.width;
  flashObj.style.height = this._container.style.height;
  this._container.appendChild(flashObj); 

   var flashvars={};
   var params={
	   		name:"_flash",
	   		id:"_flash",
	   		allowFullScreen:"true",
	   		allowScriptAccess:"always",
	   		quality:"low",
	   		menu:"false",
	   		wmode:"opaque",
	   		aa:""
   		};
   var attributes={xiRedirectUrl:window.location};
   swfobject.embedSWF(FE._baseURL + "Room3DProject.swf","_flash",this._container.offsetWidth, this._container.offsetHeight,"9.0.0","expressInstall.swf",flashvars,params,attributes);
   
   this._flash = $('_flash');
   FE._flashContainer = this._container;
   FE._flash = this._flash;
   
   FE.doTakeover(FE._flash);
}
FE.Map.prototype._onLoad = function() {
	if(this.onLoad) this.onLoad();
	this.dispatch('load');
}
//========================================================================================================================

//include
//========================================================================================================================
FE.include(FE._baseURL + 'js/swfobject.js');
FE.include(FE._baseURL + 'js/jscompat.js');
//========================================================================================================================