// Scripts para redimensionar a barra de rolagem vertical - usar no getURL - javascript:mudarAltura('1500px');, por exemplo.
/*
String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};
*/

function OficinaFlash()
{
    window.addEvent("domready", this.recalcular);
    window.addEvent("resize", this.recalcular);
}

OficinaFlash.prototype =
{
    debug:
    function(objeto, container)
    {
        container = $(container);
        
        var blah = "";
        for(i in objeto)
        {
            blah += i + ": " + this[i] + "<br />";
        }
        
        var divDebug = $("divDebug");
        if(!divDebug)
        {
            divDebug = document.createElement("div");
            divDebug.id = "divDebug";
            container.adopt(divDebug);
        }
        
        divDebug.setHTML(blah);
    }
    ,
    recalcular: 
    function()
    {
        //debugger;
       
        var flashContent = $("flashcontent");
        
        var minWidth = flashContent.style.minWidth;
        if(!flashContent.style.minWidth && flashContent.style.cssText.toLowerCase().indexOf("min-width") > -1)
        {
            var style = flashContent.style.cssText.toLowerCase().split(";");
            for(var i = 0; i < style.length; i++)
            {
                if(style[i].indexOf("min-width") > - 1)
                {
                    minWidth = style[i].substring(style[i].indexOf(":") + 1, style[i].length).trim();
                    break;
                }
            }
        }
        
        var minHeight = flashContent.style.minHeight;
        
        if(!OficinaFlash.prototype.ultimaLargura)
        {
            OficinaFlash.prototype.ultimaLargura = minWidth;
        }
        if(!OficinaFlash.prototype.ultimaAltura)
        {
            OficinaFlash.prototype.ultimaAltura = minHeight;
        }

        if(OficinaFlash.prototype.ultimaLargura)
        {
            OficinaFlash.prototype.mudarLargura(OficinaFlash.prototype.ultimaLargura);
        }
        if(OficinaFlash.prototype.ultimaAltura)
        {
            OficinaFlash.prototype.mudarAltura(OficinaFlash.prototype.ultimaAltura);
        }
    }
    ,
    getAlturaPagina: 
    function()
    {
        var altura = "";
        if (window.innerHeight)
        {
            altura = window.innerHeight;
        }
        else
        {
            altura = document.documentElement.clientHeight;
        }
        altura += "px";
        return altura;
    }
	,
    getLarguraPagina: 
    function()
    {
        var largura = "";
        if (window.innerWidth)
        {
            largura = window.innerWidth;
        }
        else
        {
            largura = document.documentElement.clientWidth;
        }
        largura += "px";
        return largura;
    }
    ,
    mudarAltura:
    function(novaAltura)
    {
        OficinaFlash.prototype.ultimaAltura = novaAltura;
        var div = $("flashcontent");
        var alturaAtual = Number(div.style.height.replace(/px/ig, ""));
        OficinaFlash.prototype.ultimaAlturaPagina = OficinaFlash.prototype.getAlturaPagina();
        var alturaPagina = Number(OficinaFlash.prototype.ultimaAlturaPagina.replace(/px/ig, ""));
        novaAltura = Number(novaAltura.replace(/px/ig, ""));

        if(novaAltura < alturaPagina) 
        {
            novaAltura = alturaPagina;
        }
        
       
        // Embed / object
        var object = div.getElements("object");
        var embed = div.getElements("embed");
        if (object.length > 0)
            object[0].style.height = novaAltura.toString() + "px";
        if (embed.length > 0)
            embed[0].style.height = novaAltura.toString() + "px";
        // Div
        div.setStyle("height", novaAltura.toString() + "px");

        
    }
    ,
    mudarLargura:
    function(novaLargura)
    {
        OficinaFlash.prototype.ultimaLargura = novaLargura;
        var div = $("flashcontent");
        var larguraAtual = Number(div.style.width.replace(/px/ig, ""));
        OficinaFlash.prototype.ultimaLarguraPagina = OficinaFlash.prototype.getLarguraPagina();
        var larguraPagina = Number(OficinaFlash.prototype.ultimaLarguraPagina.replace(/px/ig, ""));
        novaLargura = Number(novaLargura.replace(/px/ig, ""));

        if(novaLargura < larguraPagina) 
        {
            novaLargura = larguraPagina;
        }
        
        // Embed / object
        var object = div.getElements("object");
        var embed = div.getElements("embed");
        if (object.length > 0)
            object[0].style.width = novaLargura.toString() + "px";
        if (embed.length > 0)
            embed[0].style.width = novaLargura.toString() + "px";
        // Div
        div.setStyle("width", novaLargura.toString() + "px");
    }
}

var oficina_flash = new OficinaFlash();

function writeFlash(id, width, height, src, bgcolor, wmode, flashvars, scriptAccess, allowFullscreen, scale, align)
{
	document.write('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="' + height + '" width="' + width + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" viewastext>');
	document.write('<param name="movie" value="' + src + '">');
	document.write('<param name="swliveconnect" value="true">');
	document.write('<param name="bgcolor" value="' + bgcolor + '" />');
	document.write('<param name="flashVars" value="' + flashvars + '" />');
	document.write('<param name="allowFullscreen" value="' + allowFullscreen + '" />');
	if (scale) {
	    document.write('<param name="scale" value="' + scale + '" />');
	}
	if (align) {
	    document.write('<param name="salign" value="' + align + '" />');
	}
	var embed = '<embed src="' + src + '" ';
	
	if (scriptAccess) {
	    document.write('<param name="allowScriptAccess" value="' + scriptAccess + '" />');
	    embed += 'allowScriptAccess="' + scriptAccess + '" ';
    }
	if(wmode != '')
	{
    	document.write('<param name="wmode" value="' + wmode + '">');
	    embed += 'wmode="' + wmode + '" ';
	}
    embed += 'quality="high" bgcolor="' + bgcolor  +  '" width="' + width + '" height="' + height + '" flashvars="' + flashvars + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true"';
	if (scale) {
	    embed+=' scale="' + scale + '"';
	}
	if (align) {
	    embed+=' salign="' + align + '"';
	}
    embed += '></embed>';
	document.write(embed);
	document.write('</object>');
}