
function SWF ( habitat ) {
	this.habitat = habitat;
	this.html_div = null;
	return this;
}

SWF.prototype.alert = function ( text ) {
	window.alert( text );
};

/** Adapted from Adobe Tag injector **/
SWF.prototype.build_output = function () {
	var client = this.habitat.client_type;
	var browser = client.b_type;
	var os = client.os_type;
	this.output = '';
	if (browser == "ie" && os == "win") {
		this.output += '<object ';
		for (var i in this.object_tag) {
			if (i != "name") {
				this.output += i + '="' + this.object_tag[i] + '" ';
			}
		}
		this.output += '>';
		for (var i in this.params) {
			this.output += '<param name="' + i + '" value="' + this.params[i] + '" /> ';
		}
		this.output += '</object>';
	}
	else {
		this.output += '<embed ';
		for (var i in this.embed_tag) {
			this.output += i + '="' + this.embed_tag[i] + '" ';
		}
		this.output += '> </embed>';
	}
}

/** Adapted from Adobe Tag injector **/
SWF.prototype.build_tags = function () {
	if ((navigator.plugins["Shockwave Flash"] != null) || (new ActiveXObject("ShockwaveFlash.ShockwaveFlash") != null)) {
		this.embed_tag = new Object();
		this.params = new Object();
		this.object_tag = new Object();
		for (var i=0; i < arguments.length; i=i+2){
			switch (arguments[i].toLowerCase()){	
				case "accesskey":
				case "align":
				case "class":
				case "height":
				case "hspace":
				case "name":
				case "tabindex":
				case "title":
				case "vspace": 
				case "width":
				this.embed_tag[arguments[i]] = this.object_tag[arguments[i]] = arguments[i+1];
				break;
				case "classid":
				break;
				case "codebase":
				case "id":
				case "onactivate":
				case "onafterupdate":
				case "onbeforedeactivate":
				case "onbeforeeditfocus":
				case "onbeforeupdate":
				case "onblur":
				case "oncellchange":
				case "onclick":
				case "ondblclick":
				case "ondeactivate":
				case "ondrag":
				case "ondragend":
				case "ondragenter":
				case "ondragleave":
				case "ondragover":
				case "ondrop":
				case "onfinish":
				case "onfocus":
				case "onhelp":
				case "onkeypress":
				case "onkeydown":
				case "onkeyup":
				case "onload":
				case "onlosecapture":
				case "onmousedown":
				case "onmousemove":
				case "onmouseout":
				case "onmouseover":
				case "onmouseup":
				case "onpropertychange":
				case "onreadystatechange":
				case "onrowenter":
				case "onrowexit":
				case "onrowsdelete":
				case "onrowsinserted":
				case "onscroll":
				case "onstart":
				case "type":
				this.object_tag[arguments[i]] = arguments[i+1];
				break;
				case "pluginspage":
				this.embed_tag[arguments[i]] = arguments[i+1];
				break;
				case "movie":	
				case "src":
				this.embed_tag["src"] = arguments[i+1];
				this.params["movie"] = arguments[i+1];
				break;
				default:
				this.embed_tag[arguments[i]] = this.params[arguments[i]] = arguments[i+1];
			}
		}
		this.object_tag["classid"] = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";
		this.embed_tag["type"] = "application/x-shockwave-flash";
		this.build_output();
		var element = document.getElementById( "main_div" );
		if( !element ) {
			return false;
		}
		element.innerHTML = this.output;
	}
}

/** Change Body Background **/
SWF.prototype.colorize = function ( color ) {
	if( document.getElementById ) {
		var element = document.getElementById( "main_body" );
		if( element ) {
			element.style.backgroundColor = color;
		}
	}
};

/** Adapted from Adobe Tag injector **/
SWF.prototype.fix_extention = function (url, ext) {
  if (url.indexOf('?') != -1)
    return url.replace(/\?/, ext+'?'); 
  else
    return url + ext;
}

/** Start Flash Version of Habitat **/
SWF.prototype.init_habitat = function () {
	this.habitat.use_flash = true;
	var html_divs = this.habitat.set_vis( "html_divs", "hidden" );
}

/** Update scrollbar offSet in Habitat flash object **/
SWF.prototype.update_scrollbars = function (pos_x, pos_y) {
	var element = document.getElementById("habitat_toolbar");
	if (!element) {
		var html_div = document.getElementById("main_div");
		element = html_div.firstChild;
	}
	if (element) {
		var callBack = element.update_scroll(pos_x,pos_y);
	}
}