/*

	Flasher

		Wrapper class for an unobtrusive SWFObject

		Instead of embedding Flash movies directly into a page (which does not degrade,
		and can cause a page load error in IE), or adding several lines of Javascript to
		the page (which can be messy and isn't very obtrusive), you can use this to start
		Flash movies by including a hidden input element inside of a div with an id and
		the "flasher" class, using a JSON string for the movie properties.

	Dependencies:
		MooTools 1.2
		SWFObject 2

	Usage:
		Include this file or class into the page.
		Make a div with a unique id, and fill it with alternate content
			(for those without Flash or Javascript)
		Add the hidden input element inside of it, with the class "flasher" and a value
			made up of a JSON string of the options used to load the movie.

	Options:

	Example code:
	
		<html>
			<head>
				<script type="text/javascript" src="/js/swfobject-2.2.js"></script>
				<script type="text/javascript" src="/js/mootools-1.2.2-core-nc.js"></script>
				<script type="text/javascript" src="/js/flasher.js"></script>
			</head>
			<body>
				<div id="mymovie">
					<input class="flasher" type="hidden" value="{
						url: 
					}" />
				</div>
			</body>
		</html>

	License:
		MIT-style license.

*/

window.addEvent('domready', function(){

	$$('.flasher').each( function(el){
		var flasher = new Flasher(el);
	});

});

var Flasher = new Class({
	Implements: [Options],

	options: {
		url: '',
		width: '320',
		height: '240',
		version: '9.0.0',
		flashvars: {},
		params: {
			quality: 'high',
			salign: '',
			allowFullScreen: 'true',
			allowScriptAccess: 'always',
			wmode: 'transparent',
			base: '/'
		},
		attributes: {
			id: ''         // Set automatically from parent id
		},
		target: ''       // Set automatically from parent id
	},

	initialize: function(el, options) {
		if (options) this.setOptions(options);
		if (el.get('value')) this.setOptions(JSON.decode(el.get('value')));
		this.options.target = el.getParent().get('id');
		this.options.attributes.id = this.options.target;
		swfobject.embedSWF(this.options.url, this.options.target, this.options.width, this.options.height, this.options.version, '/swf/swfinstaller.swf', this.options.flashvars, this.options.params, this.options.attributes);
	}

});

