// Copyright (c) 2009 Theis Mackeprang (http://www.purplecow.dk/)
// 
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

/**
 * Function inspired by: http://www.php-help.ro/mootools-12-javascript-examples/sifr-titles-generated-using-mootools-12/
**/
function moosIFRreplace(titles, font) {
	$$(titles).each(function(titletag) {
		if (titletag.hasClass('skip')) return;
		titletag.set('html', '<span style="visibility:hidden">'+titletag.get('html')+'</span>');
		var title = titletag.getFirst();
		var dimension = title.getSize();
		var styles = title.getStyles('text-align','padding-top','padding-bottom','padding-left','padding-right','font-size','color','padding-left','line-height');
		var swf_width = dimension['x'].toInt()-(styles['padding-left'].toInt()+styles['padding-right'].toInt());
		var swf_height = dimension['y'].toInt()-(styles['padding-top'].toInt()+styles['padding-bottom'].toInt());
		var obj = new Swiff(moosIFRdir+font, {
			width: swf_width,
			height: swf_height,
			container: titletag,
			params: {wmode: 'transparent'},
			vars: {
				txt: title.get('html'),
				w: swf_width,
				h: swf_height,
				textalign: styles['text-align'],
				textcolor: styles['color'],
				offsetTop: styles['padding-top']
			},
			properties: {style:'outline-style:none'}
		});
	});
}
function moosIFR(titles, font) {
	if (Browser.Plugins.Flash.version.toInt()) window.addEvent('load', function() {
		moosIFRreplace(titles, font);
	});
}