/*
Both required:
	width
	height

Object required:
	classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=$version"
	movie="..." (param)

Embed required:
	src="..."
	pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW"
	type="application/x-shockwave-flash"

Object optional
	id="..." (attribute)

Embed optional
	name="..."

Both optional
	swliveconnect="0/1" (run FSCommand)
	play="1/0"
	loop="1/0"
	menu="1/0"
	quality="low/autolow/autohigh/medium/high/best"
	scale="default/noorder/exactfit"
	align="l/t/r/b" (attribute: l - left, r - right, t - top and b - bottom)
	salign="l/t/r/b/tl/tr/bl/br"
	wmode="window/opaque/transparent"
	bgcolor="#RRGGBB"
	base="..."
	flashvars="..."
	allowscriptaccess="samedomain/never/always"



attributes = 'width,height,id';
attributesEmbed = 'name,src';

params = 'allowscriptaccess,swliveconnect,play,loop,menu,quality,scale,salign,wmode,bgcolor,base,flashvars';
paramsObject = 'movie';

<embed 
	pluginspage="http://www.macromedia.com/go/getflashplayer"
	type="application/x-shockwave-flash"

<embed 
	pluginspage="http://www.macromedia.com/go/getflashplayer"
	type="application/x-shockwave-flash"


*/


function oSWF(obj, outputOnly) {
	var v = oSWF.getVersion(obj.version),
		vars = obj.flashvars || {}, attr = obj.attributes || {};

	if (oSWF.expressInstall
		&& v && v >= oSWF.installed
		&& oSWF.installed >= 6000065
	) {
		obj.src = oSWF.expressInstall +".swf";
		document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		vars.MMdoctitle = document.title;
		vars.MMredirectURL = escape(window.location.href);
		vars.MMplayerType = oSWF.agent == "ns" ? "PlugIn" : "ActiveX";
	} else if (!oSWF.installed || v > oSWF.installed) {
		return oSWF.write(obj.alternative || '<a href="'+ oSWF.pluginspage +'" style="display: block; background: #284d74 url('+ oSWF.expressInstall +'.gif) no-repeat 50% 50%; width: '+ obj.width +'px; height: '+ obj.height +'px;><img src="'+ oSWF.expressInstall +'.gif" style="display: none;" alt="Adobe Flash Player Update: This content requires Adobe Flash Player. Would you like to insrall it now?" /></a>');
	}

	if (outputOnly) return oSWF.getHTML(obj);
	else oSWF.write(obj);
}
oSWF.expressInstall = "js/expressinstall";
oSWF.pluginspage = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW";
(function(obj) { for (var i in obj) oSWF[i] = obj[i] })({
	getVersion: function(str) {
		var a = str && (str + "").replace(/^\D+/, '').split(/\D+/g) || [];
		for (var i = 2, v = 0; i >= 0; i--) v += (parseInt(a[i]) || 0) * Math.pow(1000, 2 - i);
		return v;
	},
	tryActiveX: function(ver) {
		try { return new ActiveXObject("ShockwaveFlash.ShockwaveFlash"+ (ver ? '.'+ ver : "")); }
		catch (e) { return null }
	},
	agent: function() {
		var n = navigator, np = n.plugins, nm = n.mimeTypes, na = n.userAgent;
		return np && nm && nm.length && "ns"
				|| na && na.indexOf("Windows CE") >= 0 && "ce"
				|| "ie";
	}(),
	getHTML: function(obj) {
		var params = 'allowscriptaccess,swliveconnect,play,loop,menu,quality,scale,salign,wmode,bgcolor,base,flashvars',
			attr = 'id,width,height', a = [],
			g = function(a, o, t) {
				t = t.split('%s');
				for (var i = 0, h = ""; i < a.length; i++)
					if (typeof o[a[i]] != "undefined") h += t[0] + a[i] + t[1] + obj[a[i]] + t[2];
				return h;
			};

		for (var i in obj.flashvars)
			a[a.length] = i +'='+ encodeURIComponent(obj.flashvars[i]);
		if (a[0])
			obj.flashvars = a.join('&');

		if (oSWF.agent == "ns") {
			obj.name = obj.id;
			var html = '<embed type="application/x-shockwave-flash"'
				+ g(['src,name',attr,params].join(',').split(','), obj, ' %s="%s"')
				+' />';
		} else {
			obj.movie = obj.src;
			var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
				+ g(attr.split(','), obj, ' %s="%s"')
				+'>'+ g(('movie,'+ params).split(','), obj, '<param name="%s" value="%s" />')
				+'</object>';
		}
		return html;
	},
	write: function(obj) {
		var div = document.createElement('div'), b, c, html = oSWF.getHTML(obj);
		if (obj.before) b = document.getElementById(obj.before);
		else if (obj.append) c = document.getElementById(obj.append);
		else if (obj.replace) return document.getElementById(obj.replace).innerHTML = html;
		else {
			b = document.getElementsByTagName('script');
			b = b[b.length - 1];
		}
		c = c || b.parentNode;
		div.innerHTML = html;
		c.insertBefore(div.firstChild, b);
		// jei wdrug ant IE atsirastu borderis
		// if (oSWF.agent == 'ie')
		// 	c.innerHTML = c.innerHTML;
	}
});

oSWF.installed = function() {
	var version = 0, x, axo;
	if (oSWF.agent == "ns") {
		if (x = navigator.plugins["Shockwave Flash"])
			version = oSWF.getVersion(x.description);
	} else if (oSWF.agent == "ce") {
		for (var i = 3; tryActiveX(i); i++)
			version = oSWF.getVersion(i);
	} else {
		if (!(axo = oSWF.tryActiveX(7)) && (axo = oSWF.tryActiveX(6))) {
			version = oSWF.getVersion('6,0,21');
			try { axo.AllowScriptAccess = "always"; }
			catch (e) { return version; }
		}
		if (axo = oSWF.tryActiveX())
			version = oSWF.getVersion(axo.GetVariable("$version"));
	}
	return version;
}();

if (!oSWF.unload && window.attachEvent) {
	oSWF.unload = true;
	// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
	window.attachEvent("onbeforeunload", function(){
 		var fn = function(){};
		__flash_unloadHandler = __flash_savedUnloadHandler = fn;

		// fix for video streaming bug
		window.attachEvent("onunload", function(){
			var o = document.getElementsByTagName("object");
			for (var i = o.length - 1; i >= 0; i--) {
				o[i].style.display = 'none';
				for (var x in o[i]) if (typeof o[i][x] == 'function')
					o[i][x] = fn;
			}
		});
	});
}

/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) {
	document.getElementById = function(id) {
		return document.all[id];
	}
}

