﻿// flash detect
function FlashUtil() {};

FlashUtil.REQUIREDVERSION = 9;
FlashUtil.DOWNLOADHTML = "<a href='http://www.macromedia.com/go/getflash/' target='_blank'>Download flash plugin</a>";

FlashUtil.getFlashInfo = function()
{
	if ( !FlashUtil.flashinfo )
	{
		var PlayerVersion = -1;
		if(navigator.plugins && navigator.mimeTypes.length)
		{
			var x = navigator.plugins["Shockwave Flash"];
			if(x && x.description)
			{
				PlayerVersion = x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
			}
		}
		else if (window.ActiveXObject)
		{
			// "try" is reserved word in NS4, use eval to hide
			eval ( 'try { ' +
					'	var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); ' +
					'	PlayerVersion = axo.GetVariable("$version").split(" ")[1].split(","); ' +
					'} ' +
					'catch (e) {}'
				 );
		}
		FlashUtil.flashinfo = new Object();
		FlashUtil.flashinfo.installed = PlayerVersion[0]!=-1;
		FlashUtil.flashinfo.version = PlayerVersion[0];
	}
	return FlashUtil.flashinfo;
}

FlashUtil.checkPlugin = function()
{
	return ( FlashUtil.getFlashInfo().installed &&
			FlashUtil.getFlashInfo().version >= FlashUtil.REQUIREDVERSION );
}

// player functions

function FlashObject(swf, width, height, id)
{
	this.parameters = new Object();
	this.attributes = new Object();
	this.flashvars = new Object();
	this.althtml = FlashUtil.DOWNLOADHTML;
	
	this.attributes["swf"] = swf;
	this.attributes["width"] = width ? width : "100%";	
	this.attributes["height"] = height ? height : "100%";	
	this.attributes["id"] = id ? id : "flashobject";
	this.parameters["play"] = "true";
	this.parameters["loop"] = "true";
	this.parameters["quality"] = "high";
	this.parameters["allowScriptAccess"] = "sameDomain";
	
	this.setAttribute = function ( name,value )
	{
		this.attributes[name] = value;
	}
	
	this.setParameter = function ( name,value )
	{
		this.parameters[name] = value;
	}
	
	this.setFlashvar = function ( name,value )
	{
		this.flashvars[name] = value;
	}
	
	this.setAlthtml = function ( html )
	{
		this.althtml = html;
	}
	
	this.draw = function()
	{
		var h = "";
		if ( FlashUtil.checkPlugin() )
		{
			var flashvarsarr = new Array();
			for(var key in this.flashvars)
				flashvarsarr[flashvarsarr.length]= (key + "=" + escape(this.flashvars[key]));
		
			if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length)
			{
				h = '<embed type="application/x-shockwave-flash" src="'+ this.attributes['swf'] +'" width="'+ this.attributes['width'] +'" height="'+ this.attributes['height'] +'"';
				h += ' id="'+ this.attributes['id'] +'" name="'+ this.attributes['id'] +'" ';
				for (var key in this.parameters)
					h += ( [key] + '="' + this.parameters[key] + '" ' );
				if (flashvarsarr.length > 0)
					h += ( 'flashvars="' + flashvarsarr.join("&") + '"' );
				h += '/>';
			}
			else
			{
				h = '<object id="'+ this.attributes['id'] +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.attributes['width'] +'" height="'+ this.attributes['height'] +'">';
				h += '<param name="movie" value="'+ this.attributes['swf'] +'" />';
				for (var key in this.parameters)
					h += '<param name="'+ key +'" value="'+ this.parameters[key] +'" />';
				if (flashvarsarr.length > 0)
					h += '<param name="flashvars" value="' + flashvarsarr.join("&") + '" />'
				h += "</object>";
			}
		}
		else
		{
			h = this.althtml;
		}
		
//alert(h);
document.write(h);
	}
}
