// JavaScript Document
var browser = null;
var g_a = null;
var g_img = null;
var g_title = null;
var destaque = "01";

function createRequest()
{
  var request = null;
  try
  {
    request = new XMLHttpRequest();
	  browser = "other";
  }
  catch (trymicrosoft)
  {
    try
	{
      request = new ActiveXObject("Msxml2.XMLHTTP");
	  browser = "ie";
    }
	catch (othermicrosoft)
	{
      try
	  {
        request = new ActiveXObject("Microsoft.XMLHTTP");
	  browser = "ie";
      }
	  catch (failed)
	  {
        request = null;
      }
    }
  }

  if (request == null) {
    alert("Erro ao criar o objeto Ajax!");
  } else {
    return request;
  }
}

var requestDestaque = createRequest();
var requestConteudo = createRequest();

function replaceText(el, text)
{
  if (el != null)
  {
    clearText(el);
    var newNode = document.createTextNode(text);
    el.appendChild(newNode);
  }
}

function clearText(el)
{
  if (el != null)
  {
    if (el.childNodes)
	{
      for (var i = 0; i < el.childNodes.length; i++)
	  {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}

function getText(el)
{
  var text = "";
  if (el != null)
  {
    if (el.childNodes)
	{
      for (var i = 0; i < el.childNodes.length; i++)
	  {
        var childNode = el.childNodes[i];
        if (childNode.nodeValue != null)
		{
          text = text + childNode.nodeValue;
        }
      }
    }
  }
  return text;
}

function mudaDestaque(a, img, title)
{
	g_a = a;
	g_img = img;
	g_title = title;
	document.getElementById("destaque").src = 'px_transp.gif';
	var url = 'miniaturas/' + img;
	requestDestaque.open("GET", url, true);
	requestDestaque.onreadystatechange = updateDestaque;
	requestDestaque.send(null);
}

function updateDestaque()
{
	if (requestDestaque.readyState == 4)
	{
		if (requestDestaque.status == 200)
		{
			//Muda zoom
			document.getElementById('zoom_' + destaque).style.display = 'none';
			document.getElementById('zoom_' + g_a).style.display = 'inline';
			//Muda legenda
			document.getElementById('legenda').innerHTML = g_title;
			//Muda a cor do link ativo
		//alert('g_a: ' + g_a + ' / destaque: ' + destaque);
			document.getElementById(destaque).style.color = "#666666";
			document.getElementById(g_a).style.color = "#cccccc";
			destaque = g_a;
			//Muda imagem
			document.getElementById("destaque").src = 'miniaturas/' + g_img;
			//Faz efeito de fade
			initImage();
		}
		else
			alert("Erro! Status de request: " + requestDestaque.status);
	}
}

/*ASD*/
// função genérica para o Flash (c/ fundo)
function swf(flash,width,height)
	{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'" />');
	document.write('<param name="movie" value="'+flash+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="0" />');
	document.write('<param name="wmode" value="opaque" />');
	document.write('<embed src="'+flash+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" menu="0" wmode="opaque"></embed>');
	document.write('</object>');
	}

// função para abrir mídia
function popup_midia(endereco, nome)
{
	var larguraTela = screen.width-10;
	var alturaTela = screen.height-87;
	window.open(endereco,nome,'width='+larguraTela+',height='+alturaTela+',top=0, left=0,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no')
}
