var SWFTopic = new Class(
{
	initialize: function()
	{		                   		
		$$('cite.swftopic').each(function(cite)
		{
			this.setupInstance(cite);
		}.bind(this));
	},
	
	prepareVars: function(element)
	{
		var object = element.getStyles('text-align','direction');
		object.fontSize = element.getStyle('font-size').toInt();
		object.color = element.getStyle('color').hexToRgb().rgbToHex();
		object.text = element.get('text').split('"').join("'");
		
		return object;
	},
	
	setupInstance: function(cite)
	{
		var container = new Element('div', {
			'id': 'swftopic-' + cite.get('id'),
			'styles': {
				'width':'1px',
				'height':'1px'
			}
		});
		if(Browser.Plugins.Flash.version >= 9)
			container.wraps(cite.get('id'));
			
		var topicStyles = new Array();
		
		cite.getElements('cite').each(function(child)
		{
			topicStyles.push( this.prepareVars(child) );
		}.bind(this));
		
		var flashvars = {};
		flashvars.container = container.get('id');
		flashvars.styles = JSON.encode(topicStyles).split('"').join("'");
		
		var params = {};
		params.menu = 'false';
    	params.wmode = 'transparent';
    	
    	swfobject.embedSWF(
    		template_url + "/client/swf/swftopic.swf", cite.get('id'), "100%", "100%", "9.0.124",
    		template_url + "/client/swf/expressInstall.swf", flashvars, params
    	);
	},
	
	setDimentions: function(params)
	{
		var el = $(params.id);
		
    	el.setStyles({
    		width:   params.width + 1,
    		height:  params.height + 2
    	});
	}
});

var swftopic;