var mbpi_home = {
	namespace:"mbpi_home",
	ready:false,
	registered_swfs:[],
	need_flash:'<div class="no-flash"></div>',
	swf_details:[	{
					parentId:"house-roof",
					objectName:"bedroom-flash",
					swfUrl:baseUri+"common/swf/home-01.swf",
					width:"403",
					height:"276"
					},
					{
					parentId:"house-third-floor",
					objectName:"hallway-flash",
					swfUrl:baseUri+"common/swf/home-02.swf",
					width:"305",
					height:"313"
					},
					{
					parentId:"house-second-floor",
					objectName:"room-flash",
					swfUrl:baseUri+"common/swf/home-03.swf",
					width:"369",
					height:"274"
					},
					{
					parentId:"house-first-floor",
					objectName:"kitchen-flash",
					swfUrl:baseUri+"common/swf/home-04.swf",
					width:"427",
					height:"249"
					}],
					
	init:function(){
		this.ready = true;
		this.loadWaitingSwf();
	},
	loadWaitingSwf:function(){
		if(this.swf_details.length > 0){
			var details = this.swf_details[0];
			this.loadFlash(details.parentId, details.objectName,details.swfUrl, details.width, details.height);
		}
		else {
			mbpi_home.trace("All swfs loaded");
		}
	},
	loadFlash:function(parentId, objectName, swfUrl, width, height){
		$("#" + objectName).append(this.need_flash);
		mbpi_home.trace("loading swf: " + swfUrl + " into id " +  objectName);
		var flashvars = {};
		var params = {wmode:"transparent"};
		var attributes = {name:objectName, id:objectName};
		swfobject.embedSWF(swfUrl, objectName, width, height, "9.0.0", baseUri+"common/swf/expressInstall.swf", flashvars, params, attributes);
	},
	isReady:function(){
		return this.ready;
	},
	getFlashMovie:function(movieName){
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		return (isIE) ? window[movieName] : document[movieName];
	},
	javascript_to_flash:function(data ,dataType, eventType){
		var fl;
		for(var i = 0; i <  this.registered_swfs.length; i++) {
			fl = this.getFlashMovie(this.registered_swfs[i]);
			
			if(fl){
				fl.dataToFlash(data, dataType, eventType);
			}
			else {
				mbpi_home.trace("No flash object found with id: " + this.registered_swfs[i]);
			}
		}
	},
	swfLoadComplete:function(movieName){
		var parentId = this.swf_details.splice(0, 1)[0].parentId;
		$("#" + parentId + " .flash-image").fadeOut("slow");
		this.loadWaitingSwf();
		
	},
	trace:function(message){
		var msg = mbpi_home.namespace + " :: " + message;
		//console.log(msg);
		return msg;
	}
};

function registerFlashFb(objectId){
	mbpi_home.registered_swfs.push(objectId);
    return mbpi_home.namespace;
}

$(document).ready(function(){
   mbpi_home.init();
   
	//pigeons
	var flashvars = {};
	var params = {wmode:"transparent"};
	var attributes = {name:"pigeon-flash", id:"pigeon-flash"};
	swfobject.embedSWF("/common/swf/pigeon.swf", "pigeon-flash", "75", "80", "9.0.0", "/common/swf/expressInstall.swf", flashvars, params, attributes);
	attributes = {name:"pigeon-flash-2", id:"pigeon-flash-2"};
	swfobject.embedSWF("/common/swf/pigeon-bottom.swf", "pigeon-flash-2", "75", "80", "9.0.0", "/common/swf/expressInstall.swf", flashvars, params, attributes);
	attributes = {name:"neon-sign", id:"neon-sign"};
	swfobject.embedSWF("/common/swf/neon.swf", "neon-sign", "214", "96", "9.0.0", "/common/swf/expressInstall.swf", flashvars, params, attributes);
	
	$('.flash').click(function(){
		var link = $(this).find('.flash-image a').attr('href');
		document.location = link;
	});

	
 
});

