//---------------------------------------------------------------------------
//
//  swfObjectExtend
//	v1.0
//
//  Created by: Bob Corporaal - reefscape.net on 06-02-2008.
//	Contact: bob@reefscape.net - http://reefscape.net
//
//	Extends swfObject by passing on the replaced html & id of the swf
//
//	Requires MooTools and is inspired by MooSiFR
//
//---------------------------------------------------------------------------

var swfObjectExtend = new Class({
	initialize: function(elements, options) {
		//
		//	default options
		//
		this.setOptions({
			swfID: 'swfObject',
			requiredFlashMajor: 8
		}, options);		
		//
		//	check if this is available on this browser (currently only Opera is disabled)
		//
		if( !window.opera && swfobject.hasFlashPlayerVersion(options.requiredFlashMajor)) {
			var availableOnBrowser = true;
		} else {
			var availableOnBrowser = false;
		}
		//
		//	replace element(s) if there are any elements, the browser/plugin can handle it and it is not disabled by hand
		//
		if(availableOnBrowser && $$(elements).length > 0 && window.location.toString().indexOf('#replace=false') == -1) {
			//
			//	check for multiple items so each can be given an unique id
			//
			if ($$(elements).length > 1) { var multipleItems = true}
			var c = 0;
			//
			//	replace each item
			//
			$$(elements).each(function(el) {
				//
				//	set the swfID if there are multiple items
				//
				if (multipleItems) {
					var swfID = options.swfID + c;
					c++;
				} else {
					var swfID = options.swfID;
				}
				//
				//	get the html and make it flashvars-friendly
				//
				var replacedHTML = el.innerHTML.replace(/\+/g, "%2B").replace(/&/g, "%26").replace(/\"/g, "%22");
				//
				//	combine the information to send to the swf
				//
				var w = String(el.offsetWidth);
				var h = String(el.offsetHeight)
				var vars = "txt="+replacedHTML;
				vars += '&w='+w+'&h='+h;
				vars += '&tagname='+el.tagName;
				vars += '&id='+swfID;
				vars += '&swfId='+swfID;
				vars += '&className='+((el.getProperty('class')!="")?el.getProperty('class'):'undefined');
				//
				//	set the attributes required for the embedding
				//
				var att = { data:options.swfURL, width:w, height:h, id:swfID, name:swfID };
				//
				//	set the swf parameters
				//
				var par = {
					menu: "false",
					wmode: "transparent",
					scale: "noscale",
					allowscriptaccess:"always",
					salign:"tl",
					swliveconnect:"true",
					quality:"best",
					flashvars:vars
				};
				//
				//	do the actual embedding using swfObject
				//
				swfobject.createSWF(att, par, el);
			}, this);
		}
	}
});

swfObjectExtend.implement(new Options);