/*
Example usage:
	// Declare variables object
	var flashvars = {
		handle:'handletest'
		,flashVarText:'testing'
		,anothervar:'testing'
	};
	// Embed Flash object in page
	var so = new swfoWrapper('so_tester.swf','flashcontent',flashvars,300,300);
*/
swfoWrapper.Inherits(SWFObject);

function swfoWrapper (swf, container, vartable, width, height)
{
	// this = new SWFObject();
	
	// default required flash version, background color	
	this.requiredversion = 8;
	this.backcolor = '#000000';
	// if width and height specified then set, otherwise default	
	this.height = typeof(width) == 'number' ? width : 800;
	this.width = typeof(height) == 'number' ? height : 600;

	// parameters provided by default constructor
	this.swf = swf;
	this.container = container;

	// call the SWFObject constructor
	this.Inherits(SWFObject, swf, container + '_swf', this.height, this.width, this.requiredversion, this.backcolor);
	this.addParam("swLiveConnect","true");
	this.addVariable("htmlSwfId",container + "_swf");

	// add all variables
	if((typeof showEdits != 'undefined') && showEdits){
		this.addVariable("author",1);
	}
	for (var varitem in vartable) {
	  if (typeof(vartable[varitem]) != 'function') {
		switch (varitem.substr(0,varitem.indexOf('_')+1)) {
			case 'atr_':
				this.setAttribute(varitem.replace('atr_',''),vartable[varitem]);
				break;
			case 'param_':
				this.addParam(varitem.replace('param_',''),vartable[varitem]);
				break;
			default:
			    this.addVariable(varitem,vartable[varitem]);
				break;
		}
	  }
	}

	this.resize = function (h,w) {
		var mov = document.getElementById(this.container + "_swf");
		var container = document.getElementById(this.container);

		mov.height = h;
		mov.setAttribute("height",h);
		mov.width = w;
		mov.setAttribute("width",w);
		
		container.style.height = h + "px";
		container.style.width = w + "px";
	};

	this.postform = function (action,query) {
		var fe = document.createElement("form");
		fe.id = "flashsearchform";
		fe.action = action;
		fe.enctype = "multipart/form-data";
		fe.encoding = "multipart/form-data";
		fe.method = "post";
		fe.style.display = "none";
		var qv = "";
		var qa = query.split(",");
		for (var i = 0; i < qa.length; i++) {
			qv += String.fromCharCode(qa[i]);
		}
		
		var qps = qv.split("&");
		for (var i = 0; i < qps.length; i++) {
			var qp = qps[i].split("=");
			var qpe = document.createNamedElement("input",qp[0]);
			qpe.type = "hidden";
			var qpev = qp[1];
			qpe.value = qpev;
			fe.appendChild(qpe);
		}

		var qpcs = document.createNamedElement("input","_charset_");
		qpcs.type = "hidden";
		qpcs.value = "utf-8";
		fe.appendChild(qpcs);
		document.body.appendChild(fe);
		fe.submit();
	};

	var basePrefix=(location.href.replace(/https?:\/\/[^\/]+(\/(author|publish))?.*/,'$1'));

	this.addParam('base',basePrefix+'/flash');
	this.addParam('scale','noscale');
	this.addParam('wmode','transparent');
	this.addParam('allowFullScreen','true');
	this.write(this.container);
	return; 
}

swfoWrapper.prototype.Inherits = function( parent )
	{
		if( arguments.length > 1 )
		{
			parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
		}
		else
		{
			parent.call( this );
		}
};
