// Menu
function FundoSubMenuHover (fundo)
	{
	document.getElementById(fundo).className="submenucomhover";
	}
function FundoSubMenuNormal(fundo)
	{
	document.getElementById(fundo).className="";
	}
// Menu

// Troca de imagens
var g_id = null;
var g_img = null;
var g_title = null;
var g_id_anterior = 1;

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 iniciaImagemDestaque(id) {
	g_id_anterior = id;
}

function mudaDestaque(id, img, title)
{
	g_id = id;
	g_img = img;
	g_title = title;
	document.getElementById("img_grande").src = '../imagens/px_transp.gif';
	var url = img;
	requestDestaque.open("GET", url, true);
	requestDestaque.onreadystatechange = updateDestaque;
	requestDestaque.send(null);
}

function updateDestaque()
{
	if (requestDestaque.readyState == 4)
	{
		if (requestDestaque.status == 200)
		{
			//Muda a listagem das imagens, faz a imagem selecionada desaparecer da listagem
			document.getElementById('imagem_'+g_id_anterior).className = "borda_img";
			document.getElementById('imagem_'+g_id).className = "borda_img_destaque";
			g_id_anterior = g_id;
			//Muda imagem
			document.getElementById("img_grande").src = g_img;
			document.getElementById("img_grande").title = g_title;
			//Faz efeito de fade
			initImage();
			//muda a legenda
			document.getElementById("leg_img").innerHTML = "<strong>" +  g_title + "</strong>";
		}
		else
			alert("Erro! Status de request: " + requestDestaque.status);
	}
}
// Troca de imagens