//  =============   FLASH   =========================================

swfPath = "../../template/swf/";

function acProcessor()
{
	var all = document.getElementsByTagName("*");
	var mods = new Array();
	var newElem, parentElement;
	var node, l = all.length;
	//alert(a.length);
	for (var k = 0; k < l; k++)
	{
		if ( all[k].tagName.toLowerCase() != "table" && all[k].getAttribute("ac:type") != null )
				mods.push( all[k] );
	}

	for (var k = 0; k < mods.length; k++)
	{
		node = mods[k];
		newElem = document.createElement( "span" );
		newElem.innerHTML = Processors.create( node );//node.innerHTML, node.href, node.getAttribute("bt:tamanho"), node.getAttribute("bt:estilo"), node.getAttribute("bt:seta") );
		parentElement = node.parentNode;
		parentElement.insertBefore( newElem.firstChild, node );
		parentElement.removeChild( node, true ); 

		//parentElement.replaceChild( a[k], newElem );
	}
}

window.onload = acProcessor;

Processors = new Object();

Processors.create = function ( node )
{
	var html = "";
	switch ( node.getAttribute("ac:type").toLowerCase() )
	{
		case "button":
			// ( node, valor, name, comando, tamanho, className )
			html = Processors.criarInputButtom( node );
		break;
		case "link":
			// ( node, texto, href, tamanho, className, seta )
			html = Processors.criarBotao( node, node.innerHTML, node.href, node.getAttribute("ac:width"), node.getAttribute("ac:arrow") );
		break;
		case "header":
			// ( titulo, width, height, estilo, css )
			html = Processors.criarTitulo( node );
		break;
		case "gt":
			// ( titulo, width, height, estilo, css )
			html = Processors.criarTituloGT( node );
		break;
		case "titulo2":
			html = Processors.criarTitulo2( node );
		break;
		case "ecoatitude":
			html = Processors.criarEcoAtitudes( node );
		break;
		case "entremata":
			html = Processors.criarEntreNaMata( node );
		break;
		default:
			html = "<strong>ac: Erro. Tipo n??o definido</strong>";
	}
	return html;
}

// Criar "---.swf"
/*Processors.criarInputButtom = function ( node )
{
	var data = swfPath + "titulo2.swf";
	var dimensions = { width: node.getAttribute("ac:width"), height: 30 };
	var param = { name: "wmode", value:"transparent" };
	var flashvars = { name: "text", value:node.innerHTML };
	var data = swfPath + "botao_02.swf" ;
	var dimensions = { width: node.getAttribute("ac:width"), height: 22 };
	var param = null//{name:"wmode", value:"transparent"};
	var flashvars = [ {name:"text", value:node.value }, {name:"href", value:node.onclick } ];
	//var parametros = [ { name:"", value:name },  ];
	var functionFlash = node.onclick;

	var input = "<span><input type='button' style='display:block' value='" + node.value  + "' onclick='" + node.onclick + "' runat='server' />";
	alert(node.onclick);
	return ( input + createFlash( data, null, dimensions, param, flashvars) + "</span>");
}*/

// Criar "botao_01.swf", "botao_03.swf", "botao_03.swf"
Processors.criarBotao = function ( node, texto, href, tamanho, seta )
{
	var data = ( swfPath + node.getAttribute("ac:src") );
	var dimensions = { width:tamanho, height:22 };
	var param = {name:"wmode", value:"transparent"};
	var flashvars = [ { name:"href", value:encodeURI(href) }, {name:"text", value:texto} ];
	if (seta != null)
		flashvars.push( { name:"seta", value:seta } );
	var a = "<span><a style='display:none' href='" + href + "'>" + texto + "</a>";
	return ( a + createFlash( data, null, dimensions, param, flashvars ) + "</span>");
}

Processors.criarTituloGT = function ( node )
{
	var titulo1 = node.innerHTML;

	var data = swfPath + "TituloGT.swf";
	var dimensions = { width: 536, height: 31 };
	var param = { name: "wmode", value:"transparent" };
	var flashvars = [ { name:"style", value:node.tagName }, { name:"titulo1", value:titulo1 } ];
	var className = node.getAttribute("ac:class");

	return createFlash ( data, null, dimensions, param, flashvars, className );
}

Processors.criarEcoAtitudes = function ( node )
{
	var data = swfPath + "ecoAtitudes.swf";
	var dimensions = { width: 735, height: 320 };
	var param = { name: "wmode", value:"transparent" };
	var className = node.getAttribute("ac:class");

	return createFlash ( data, null, dimensions, param, null, className );
}

Processors.criarTitulo = function( node )
{
	var composto, titulo1, titulo2, newsletter = "0";
	if ( node.tagName.toLowerCase() == "h2" )
	{
		spans = node.getElementsByTagName("span");
		titulo1 = spans[0].innerHTML;
		titulo2 = spans[1] != null ? spans[1].innerHTML : "";
		newsletter = node.getAttribute("ac:newsletter") == "1" ? "1" : "0";
	}
	else
	{
		titulo1 = node.innerHTML;
		titulo2 = "";
	}

	var data = swfPath + "Titulo.swf";
	var flashvars = [ { name:"style", value:node.tagName }, { name:"titulo1", value:titulo1 }, { name:"titulo2", value:titulo2 }, {name:"newsletter", value:newsletter } ];
	var params = { name:"wmode", value:"transparent" };
	var dimension = { width:node.getAttribute("ac:width"), height:node.getAttribute("ac:height") };
	var className = "tituloFlash " + node.getAttribute("ac:class");

	return createFlash( data, null, dimension, params, flashvars, className );
}

Processors.criarEntreNaMata = function ( node )
{
	var data = swfPath + "entrenamata/Default.swf";
	var dimensions = { width: 775, height: 457 };
	var param = { name: "wmode", value:"transparent" };
	var className = node.getAttribute("ac:class");

	return createFlash ( data, null, dimensions, param, null, className );
}