window.onresize = wResize;
nie = (navigator.appName.indexOf("Microsoft") == -1);

function adjust1()
{
    if (el('k0'))
        el('k0').style.display = 'none';
    if (el('k1'))
        el('k1').style.display = 'none';
    if (el('k2'))
        el('k2').style.display = 'none';
    if (el('lr'))
        el('lr').style.display = 'none'
}

function getel(doc, id)
{
    return doc.getElementById(id);
}

function el(id)
{
    return getel(document, id);
}

function wResize(e)
{
    if (el('main'))
    {
        x = el('main').offsetLeft;
        if (el('mainBg').offsetHeight >= 574)
            el('mainBg').style.backgroundPosition = (x) + 'px top';
        else
        {
            y = el('mainBg').offsetHeight - 574;
            y = y + (y % 5);
            el('mainBg').style.backgroundPosition = (x) + 'px ' + (y) + 'px';
        }
        document.body.style.backgroundPosition = (x) + 'px 4px';
        x =(el('links').offsetHeight-41)/2;
        el('rss').style.marginTop = (x) + 'px';
        el('idiomas').style.marginTop = (x+1) + 'px';
        el('indique').style.marginTop = (x+1) + 'px';
    }
}

function escreve(s)
{
	document.write(s);
}

function escreveFlash(id, src, width, height, align, transparent, mozila, onmouseover, onmouseout)
{
    s = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + 
        (width) + '" height="' + (height) + '" id="' + 
        id + '" ' + (align != '' ? 'align="' + align + '"' : '') + 
        (onmouseover != '' ? ' onmouseover="' + onmouseover + '"' : '') +
        (onmouseout != '' ? ' onmouseout="' + onmouseout + '"' : '') +
        '><param name="quality" value="high" />' +
        (src != '' ? '<param name="movie" value="' + src + '" />' : '') +
        (transparent ? '<param name="wmode" value="transparent" />' : '') +
        '<param name="menu" value="false" /><param name="scale" value="noscale" />';
    if (mozila)
        s += '<embed ' + 
            (src != '' ? 'src="' + src + '" ' : '') +
            'loop="false" menu="false" quality="high" scale="noscale" width="' + 
            (width) + '" height="' + (height) + '" name="' + id + '" ' +
            (align != '' ? 'align="' + align + '" ' : '') +
            (onmouseover != '' ? 'onmouseover="' + onmouseover + '" ' : '') +
            (onmouseout != '' ? 'onmouseout="' + onmouseout + '" ' : '') +
            (transparent ? 'wmode="transparent" ' : '') +
            'allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true" scale="noscale" />';
    s += '</object>';
    escreve(s);
}

function arr(n)  {
   this.length=n
   for (var i=0;i<n;i=i+1)  {
     this[i] = ''
   }
}

function mv(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1)
        return document.all[movieName]
    else if (document[movieName])
        return document[movieName]
    else
        return el(movieName)
}

function loadMovie(id, movie, params)
{
	mv(id).LoadMovie(0, movie);
    for (p=0; p<params.length; p+=2)
        mv(id).SetVariable(params[p], params[p+1]);
}

function loadMovieWithDelay(id, movie, paramsStr)
{
    cmd = 'loadMovie(\'' + id + '\', \'' + movie + '\', ' + paramsStr + ')';
    setTimeout(cmd, 500);
}

function movieIsLoaded(theMovie) {
    if (typeof (theMovie) != "undefined") {
        return ((typeof (theMovie.PercentLoaded) != "undefined") && (theMovie.PercentLoaded() == 100));
    } else {
        return false;
    }
}

function movieIsReady (theMovie) {
	return (typeof(theMovie.PercentLoaded) != "undefined");
}

function element_top(el)
{
	var et = 0
	while (el)
	{
		et += el.offsetTop
		el = el.offsetParent
	}
	return et
}

function element_left(el)
{
	var et = 0
	while (el)
	{
		et += el.offsetLeft
		el = el.offsetParent
	}
	return et
}

function ampliar(id, pw, ph, base)
{
	if (pw > 760)
		pw = 760;
	if (ph > 570)
		ph = 570;

	w = (screen.width-30);
	w = pw+10 > w ? w : pw+10;
	h = (screen.height-30);
	h = ph+10 > h ? h : ph+10;
	
	janela = window.open('about:blank','pict_big','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,menubar=no,width='+(w)+',height='+(h)+',top='+(((screen.height-h)/2)-30)+',left='+(((screen.width-w)/2)-10))
	janela.document.write('<HTML><TITLE>Imagem ampliada</TITLE>');
	janela.document.write('<BODY style="margin: 0px; padding: 0px">');
	janela.document.write('<TABLE BORDER=0 cellpadding=0 cellspacing=0 width=100% height=100%><TR><TD width=100% height=100% align=center valign=middle>');
	janela.document.write('<A HREF="" onclick="window.close(); return false"><IMG id=pic ALT="Clique para fechar" SRC="' + base + 'ModuleHandlers/Content/picture.aspx?idContentPicture=' + (id) + '&w='+(janela.document.body.clientWidth-10)+'&h='+(janela.document.body.clientHeight-10)+'" BORDER=0 style="border: 1px solid gray"></a>');
	janela.document.write('</TD></TR></TABLE></BODY></HTML>');	
	
	janela.focus()
	
}

function newImage(arg) {
	if (document.images) {  
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


function imprime()
{
	setTimeout("window.print()", 500);
}

var bannerIndex = -1;
var allBannersCreated = 0;
function loadBanners()
{
    if (banners.length == 0)
        return;
        
    criaBanner(banners[0], 'banner0');
    if (banners.length > 1)
        setTimeout('loadAllBanners()', 500);
    
    el('bannerEsquerda').style.display = banners.length > 1 ? 'block' : 'none';
    el('bannerTopoDireita').style.display = banners.length > 1 ? 'block' : 'none';
    el('bannerBottomDireita').style.display = banners.length > 1 ? 'block' : 'none';
    el('setaDir').style.display = banners.length > 1 ? 'block' : 'none';
    el('setaEsq').style.display = banners.length > 1 ? 'block' : 'none';
    
    trocaBanner(1);
}

function criaBanner(html, id)
{
    el('bannerBanner').innerHTML += html;
}

function loadAllBanners()
{
    if (bannerIsLoaded('banner0') || nie)
    {
        for (i=1; i<banners.length; i++)
            criaBanner(banners[i], 'banner' + (i));
        allBannersCreated = 1;
    }
    else
        setTimeout('loadAllBanners()', 500);
}

function bannerIsLoaded(id)
{
    if ((mv(id).tagName == 'EMBED') || (mv(id).tagName == 'OBJECT'))
        return movieIsLoaded(mv(id));
    else if (mv(id).tagName == 'IMG')
        return el(id).complete;
}

var oldBannerIndex;
function trocaBanner(avanca)
{
    if ((!allBannersCreated) && (bannerIndex != -1))
        return;

    oldBannerIndex = bannerIndex;        

    if (avanca)
        bannerIndex++;
    else
        bannerIndex--;

    if (bannerIndex == -1) 
        bannerIndex = banners.length-1;    
    else if (bannerIndex >= banners.length) 
        bannerIndex = 0;    
        
    if (bannerIndex > -1)
    {
        if (!bannerIsLoaded('banner' + (bannerIndex)) && (oldBannerIndex > -1))
            el('divbanner' + (oldBannerIndex)).style.display = 'none';
    }

    mostraBanner();
}

var timeoutid;
function mostraBanner()
{
    if (bannerIsLoaded('banner' + (bannerIndex)))
    {
        if (!nie)
        {
		    oDiv = el('bannerBanner');
		    oDiv.style.filter="blendTrans(duration=0.5)";
   		    oDiv.filters.blendTrans.apply();
		    oDiv.filters.blendTrans.play();
		}
        if (oldBannerIndex > -1)
            el('divbanner' + (oldBannerIndex)).style.display = 'none';
        el('divbanner' + (bannerIndex)).style.display = 'block';
        if (timeoutid)
            clearTimeout(timeoutid);
        timeoutid = setTimeout('trocaBanner(1)', 10000);
    }
    else
    {
        if (nie)
        {
            if (oldBannerIndex > -1)
                el('divbanner' + (oldBannerIndex)).style.display = 'none';
            el('divbanner' + (bannerIndex)).style.display = 'block';
            timeoutid = setTimeout('trocaBanner(1)', 10000);
        }
        else
            setTimeout('mostraBanner()', 2000);
    }
}


var ie5=document.all && !window.opera
var lastHeight = 0;
var autoHeight = 0;
var autoHSet = 0;
function adjustIFrameSize () 
{
	iframeElement = getel(window.parent.document, 'ifcontent');
	iframeWindow = window.parent.frames[name];
    if (nie)
        iframeElement.style.height = '';
    h = document.documentElement.scrollHeight;
	iframeElement.style.height = (h) +'px';
	lastHeight = h;
	if ((autoHeight) && (!autoHSet))
	{
	    autoHSet = 1;
	    setTimeout('autoH()', 500);
	}
}

function autoH()
{
	if (document.documentElement.scrollHeight != lastHeight)
	{
        scrollPos = window.parent.document.documentElement.scrollTop;
		adjustIFrameSize();
	    window.parent.document.documentElement.scrollTop = scrollPos;
	}
    setTimeout('autoH()', 500);
}

function contentBeforePrint(){
    getel(document, 'cabPrint').style.display = 'block';
}

function contentAfterPrint(){
    getel(document, 'cabPrint').style.display = 'none';
}

var elementosFonte = '';
function fonte(aumenta)
{
    // default
    dif = Number(readCookie('fontSize'));
    
    els = elementosFonte.split(',');

    for (i=0; i<els.length; i++)
    {
        df = el(els[i]);
        if (!df)
            continue;
	    def = Number(df.getAttribute('default-font', 0));
	    if (aumenta > -1)
	    {
    	    size = Number(df.style.fontSize.substr(0, df.style.fontSize.length-2));
    	    dif = size - def;
    	}
    	else
    	{
            dif = Number(readCookie('fontSize'));
    	    size = def+dif;
        }
        
	    if (aumenta > -1)
	    {
	        if ((dif <= 0) && !aumenta)
	        {
		        alert(fonteMinTxt);
		        return;
	        }
	        if ((dif >= 5) && aumenta)
	        {
		        alert(fonteMaxTxt);
		        return;
	        }
	        if (aumenta)
		        size++;
	        else
		        size--;
		}
		
		dif = size-def;

	    df.style.fontSize = (size) + "px";
	}
	
    var expire = new Date();
    expire.setTime(new Date().getTime() + 3600000*24*5000);
    document.cookie = 'fontSize'+"="+escape((dif) + '')+ ";expires="+expire.toGMTString();
    adjustIFrameSize();
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function indica()
{
	ifc = window.frames['ifcontent'];
	iurl = 'indique.aspx?1=1';
	if (ifc)
	{
	    if (ifc.idcontent != 0)
		    iurl += '&idContent=' + (ifc.idcontent);
	    if (ifc.idcontentsection != 0)
		    iurl += '&idContentSection=' + (ifc.idcontentsection);
	    ifc.location = htmlbase + iurl;
	}
	else
	    window.location = iurl;
}

function abreGaleria(id, idContentPicture)
{
	janela = window.open(htmlbase + 'galeria.aspx?idContent=' + (id) + (typeof(idContentPicture) != 'undefined' ? '&idContentPicture=' + (idContentPicture) : ""),'galeria','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,menubar=no,width=611,height=477,top='+((screen.height-477)/2)+',left='+((screen.width-611)/2));
	janela.focus();
	return false;
}

function busca()
{
    url = 'busca.aspx?p=' + el('txtBusca').value;
    if (el('ifcontent'))
        window.frames['ifcontent'].location = url;
    else
        window.location = 'padrao.aspx?' + url;
}

function mostraBusca()
{
    el('txtBusca').style.display = 'block';
}