
var startFlashConverter = function() {
	new FlashConverter();
}

//window.addEvent('domready', function() {
swfobject.addDomLoadEvent(startFlashConverter);
//});

document.write('<style type="text/css">.loadFlash {display: none}</style>');


////////////////////////////////////////////////////////////////////////////
//DESIGNERS: do NOT change anything below this line, or you'll be spanked.//
////////////////////////////////////////////////////////////////////////////


/**
 * Convert images of a certain class to flash movie.
 * The image and the swf file should share the same name (apart from the extension).
 * Depends on Mootools 1.2 and SWFObject 2.1.
 * @see mootools
 * @see SWFObject
 */
var FlashConverter = new Class({
	lastIdIndex: 0,
	options: {
		flashPath: 'flash/',
		swfInstallFile: 'swfobject-2.1/expressInstall.swf', //path from flash path
		className: 'loadFlash',
		flashVersion: '9.0.0',
		flashParams: {
			wmode: 'opaque',
			quality: 'high'
		},
		flashVars: {},
		display: 'block'
	},
	initialize: function(options) {
		this.setOptions(options);
		$$('img.' + this.options.className).each(function(e) {
			this.convert(e);
		}, this);
	},
	convert: function(e) {
		var imgSrc = e.get('src');
		var swf = this.getSwfName(e.get('src'));
		if (swf) {
			e.setStyle('display', this.options.display);
			var id = e.get('id');
			if (!id) {
				id = 'flashConverter_' + (++this.lastIdIndex);
				e.set('id', id);
			}
			var sizes = e.getSize();
			this.embedSWF((imgSrc.indexOf('../') == 0 ? '../' : '') + this.options.flashPath + swf, id, sizes.x, sizes.y);
		}
	},
	embedSWF: function(swf, id, width, height) {
		swfobject.embedSWF(swf, id, width, height, this.options.flashVersion, this.options.flashPath + this.options.swfInstallFile, this.options.flashVars, this.options.flashParams);
	},
	getSwfName: function(imgSrc) {
		var imgName = imgSrc.match(/([^\/]+)\.[a-z]+$/i);
		if (imgName.length > 1) {
			return imgName[1] + '.swf';
		}
		return '';
	}
});
FlashConverter.implement(new Options);
