var Topic = new Class(
{
    initialize: function()
    {
		var flashvars;
		var mainElement;
    },
    
    setup: function()
    {
    	flashvars = {};
    	$(document.body).getElements("div[title^={'type':'topic']").each(function(el)
    	{	
			var container = new Element('div', {
				'id': 'container-' + el.get('id'),
				'class' :  el.get('class'),
				'styles': {
					'width':'100px',
					'height':'20px'
				}
			});
			container.wraps($(String(el.get('id'))));
			
			flashvars.id = el.get('id');
			flashvars.mainFormat = el.getProperty('title');
			el.removeProperty('title');
			mainElement = el;
			
			flashvars.p = '[';
			$(String(el.get('id'))).getElements("p").each(function(p)
			{
				var obj = {};
				if(p.getProperty('title'))
				{
					obj = p.getProperty('title');
					obj = JSON.decode(obj);
				}
				
				obj.text = p.get('text');
				obj = JSON.encode(obj);
				obj = obj.split('"').join("'");
				flashvars.p += obj + ',';
			});
			flashvars.p = flashvars.p.substr(0,flashvars.p.length - 1);
			flashvars.p += ']';
    	
	    	var params = {};
	    	params.menu = 'false';
	    	params.allowScriptAccess = 'always';
	    	params.wmode = 'transparent';
	    	swfobject.embedSWF("/swf/topic.swf", mainElement.get('id'), "100%", "100%", "9.0.124",
							   "/swf/expressInstall.swf", flashvars, params);
						   
		});
    },
    
    setScale: function(id, swfWidth, swfHeight)
    {
		var el = $('container-' + id);

    	el.setStyles({
    		width:   swfWidth,
    		height:  swfHeight + 2
    	});
    }
});
