// use frameworks/prototype/prototype.js, dom/swf/DetectFlashVer.js

SwfObj = Class.create();
SwfObj.prototype = {
	/**
	 * @param swfHolder   The object where the swf will be written
	 * @param attributes  An array containing the following key / value pairs:
   *                    * swfFile     The location of the .swf file. Defaults to the id of the swfHolder, 
	 *                                  with ".swf" appended.
	 *                    * swfHref     The location that is passed to the flash player (Framework.as).
   *                                  Defaults to the current location
	 *                    * reqMajorVer, reqMinorVer, reqRevision
	 *                    * alternative If not null, designates the location where the browser is redirected 
	 *                                  when the system doesn't have the required flash player version. Default: null.
	 *
	 * 
	 */
	initialize: function(swfHolder, attributes)
	{
		if (attributes == null)
			attributes = new Object();
		this.swfHolder = $(swfHolder);

		this.swfHref = attributes['swfHref'] || window.location.toString();
		this.swfFile = attributes['swfFile'] || this.swfHolder.id + '.swf';

		this.reqMajorVer = attributes['reqMajorVer'] || 9;
		this.reqMinorVer = attributes['reqMinorVer'] || 0;
		this.reqRevision = attributes['reqRevision'] || 45;

		this.paramStr = attributes['paramStr'];

		// Perform the version check

		if (!DetectFlashVer(this.reqMajorVer, this.reqMinorVer, this.reqRevision))
		{
			if (attributes['alternative'])
			{
				// If the flash player alternative url is set, 
				// navigate to the page where we are instructed on how to download the flash player.
				window.location = attributes['alternative'];
			}
			return; // Simply do not instance the flash player.
		}

		this.width = attributes['width']; 
		this.height = attributes['height'];

		this.getDimensions();
		
		this.swfHolder.swfObj = this;
		this.swfHolder.innerHTML = this.getSwfCode();
	},
	getSwfCode: function()
	{
		$code = '';
		$code += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ';
		$code += 'id="' + this.swfHolder.id + '_swf" ';

		if (this.width)
			$code += 'width="'+this.width+'" ';

		if (this.height)
			$code += 'height="'+this.height+'" ';

		$code += 'align="middle"';
		$code += '>';
			$code += '<param name="allowScriptAccess" value="sameDomain" />';
			$code += '<param name="movie" value="' + this.swfFile + '?' + this.paramStr + '" />';
			$code += '<param name="quality" value="high" />';
			$code += '<embed src="' + this.swfFile + '?' + this.paramStr + '"';
				$code += 'quality="high" ';

				if (this.width)
					$code += 'width="' + this.width + '" ';

				if (this.height)
					$code += 'height="' + this.height + '" ';

				$code += 'name="' + this.swfHolder.id + '_swf" ';
				$code += 'align="middle" ';
				$code += 'allowScriptAccess="sameDomain" ';
				$code += 'type="application/x-shockwave-flash" ';
				$code += 'pluginspage="http://www.macromedia.com/go/getflashplayer" ';
			$code += '/>';
		$code += '</object>'
		return $code;
	},
	getDimensions:function()
	{
		if (this.swfHolder.title)
		{
			title = this.swfHolder.title;
			
			$temp = title.split("(");
			$temp = $temp[$temp.length-1];
			$temp = $temp.substr(0, $temp.length - 1);
			$temp = $temp.split(" x ");
		
			if ($temp[0] && $temp[1])
				this.width = $temp[0], this.height = $temp[1];
		}
	}
}

/**
 * Functie apelata din flash?
 */
function getHref(swfObjectID)
{
	return $(swfObjectID.replace(/_swf$/, '')).swfObj.swfHref;
}


