function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


/* Corrige ActiveX do IE */
function ie_object_border_fix(id)
{
	var obj = document.getElementById(id);
	if ( obj['parentNode'] ) {
		var parentNode = obj['parentNode'];
		parentNode.innerHTML = parentNode.innerHTML;
	}
}

function windowPopup(url, features) {
	window.open(url, "", features)
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function showHideLayer(objId) {
	if (objId) {
		var obj = document.getElementById(objId);

		if (obj.style.display == "block") {
			obj.style.display = "none";
		} else {
			obj.style.display = "block";
		}

	}
}

function initPerguntasFrequentes() {
	dia = new Date();
	ano = dia.getYear();
	hora = dia.getHours();
	if (ano < 2000){
	ano = 1900 + dia.getYear();}
	mes = new Array("janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro")
	if (hora < 10){
	hora = "0" + hora;}
	minuto = dia.getMinutes();
	if (minuto < 10){
	minuto = "0" + minuto;}
	document.writeln("Belo Horizonte, " + dia.getDate() + " de " +  mes[dia.getMonth()] + " de " + ano);
}

function swapContent(o2show, o2hide, idioma){
	if (o2show == 'box_calendario'){
		document['box_calendario_apresentacoes'].src = "/images/box_calendario_on_v2.jpg";
		document.getElementById(titulo_calendario);
		titulo_calendario.style.color = '#ffffff';
		document.getElementById(titulo_apresentacoes);
		titulo_apresentacoes.style.color = '#777777';
	} else if (o2show == 'box_apresentacoes'){
		document['box_calendario_apresentacoes'].src = "/images/box_calendario_of_v2.jpg";
		document.getElementById(titulo_apresentacoes);
		titulo_apresentacoes.style.color = '#ffffff';
		document.getElementById(titulo_calendario);
		titulo_calendario.style.color = '#777777';
	} else if (o2show == 'box_comunicados'){
		document['box_comunicados_noticias'].src = "/images/box_comunicado_on_v2.jpg";
		document.getElementById(titulo_comunicados);
		titulo_comunicados.style.color = '#ffffff';
		document.getElementById(titulo_noticias);
		titulo_noticias.style.color = '#777777';
	} else if (o2show == 'box_noticias'){
		document['box_comunicados_noticias'].src = "/images/box_comunicado_of_v2.jpg";
		document.getElementById(titulo_noticias);
		titulo_noticias.style.color = '#ffffff';
		document.getElementById(titulo_comunicados);
		titulo_comunicados.style.color = '#777777';
	}else if (o2show == 'box_cotacoes'){
		document['box_cotacoes_ferramentas'].src = "/images/box_cotacoes_on_v2.jpg";
		document.getElementById(titulo_cotacoes);
		titulo_cotacoes.style.color = '#ffffff';
		document.getElementById(titulo_ferramentas);
		titulo_ferramentas.style.color = '#777777';
	} else if (o2show == 'box_ferramentas'){
		document['box_cotacoes_ferramentas'].src = "/images/box_cotacoes_of_v2.jpg";
		document.getElementById(titulo_ferramentas);
		titulo_ferramentas.style.color = '#ffffff';
		document.getElementById(titulo_cotacoes);
		titulo_cotacoes.style.color = '#777777';
	}
	document.getElementById(o2show).style.display = 'block';
	document.getElementById(o2hide).style.display = 'none';
}

function showHideObj(objId) {
	if(objId) {
		var element = document.getElementById(objId);
		element.style.display = (element.style.display=='block')?'none':'block';
	}
}

function showObj(toShow, toHide){
	if (toShow && toHide) {
		var objToShow = document.getElementById(toShow);
		var objToHide = document.getElementById(toHide);

		objToShow.style.display = 'block';
		objToHide.style.display = 'none';
	}
}

function redim() {
	var objAcessoRapido = document.getElementById('acesso_rapido');
}

function showHideObjHover(objId, newState) {
	if(objId && newState) {
		var element = document.getElementById(objId);
		element.style.display = (newState=='block')?'block':'none';
	}
}

function captura(){

	var endereco = document.location.href;

	/*if (endereco.indexOf("cemig_distribuicao") > -1) {

		var imagem_d = new Array();

		imagem_d[0] = "/images/banner_top_distribuicao_1.jpg";
		imagem_d[1] = "/images/banner_top_distribuicao_2.jpg";
		imagem_d[2] = "/images/banner_top_distribuicao_3.jpg";

		var i = Math.floor(Math.random() * (imagem_d.length));
		if (i >= imagem_d.length) i = imagem_d.length-1;

		var img_aleatoria = document.getElementById('img_aleatoria');
		if (img_aleatoria) img_aleatoria.src = imagem_d[i];

	} else if (endereco.indexOf("cemig_geracao_transmissao") > -1) {

		var imagem_gt = new Array();

		imagem_gt[0] = "/images/banner_top_geracao_1.jpg";
		imagem_gt[1] = "/images/banner_top_geracao_2.jpg";
		imagem_gt[2] = "/images/banner_top_geracao_3.jpg";

		var i = Math.floor(Math.random() * (imagem_gt.length));
		if (i >= imagem_gt.length) i = imagem_gt.length-1;

		var img_aleatoria = document.getElementById('img_aleatoria');
		if (img_aleatoria) img_aleatoria.src = imagem_gt[i];

	} else {*/

		var imagem = new Array();

		imagem[0] = "/images/layout_4.jpg";
		imagem[1] = "/images/layout_1_copy.jpg";
		imagem[2] = "/images/banner_top_new_3.jpg";

		var i = Math.floor(Math.random() * (imagem.length));
		if (i >= imagem.length) i = imagem.length-1;

		var img_aleatoria = document.getElementById('img_aleatoria');
		if (img_aleatoria) img_aleatoria.src = imagem[i];

	//}
}

function escreve_titulo_banner(){

	var titulo = document.title;
	$('#titulo_banner').text(titulo);
}
function escreve_titulo(texto){
	document.title = texto;
}

function showINFOinvestMenu(obj, id) {
	var div = $('#' + id);
	var obj = $(obj);
	if (!obj.size() || !div.size()) {
		return;
	}

	if (div.is(":visible")) {
		div.hide();
		return;
	}

	if (!obj.data("binded")) {
		obj.bind("mouseenter", function() {
			clearTimeout(obj.data("timeout"));
		}).bind("mouseleave", function() {
			obj.data("timeout", setTimeout(function() { div.hide(); }, 200));
		});

		div.bind("mouseenter", function() {
			clearTimeout(obj.data("timeout"));
		}).bind("mouseleave", function() {
			obj.data("timeout", setTimeout(function() { div.hide(); }, 200));
		});
	}
	obj.data("binded", true);

	div.show();
	var objPos = obj.offset();

	div.hide().slideToggle('normal').css({
		top: objPos.top + obj.outerHeight(),
		left: objPos.left + (obj.outerWidth() - div.outerWidth()) / 2
	});
}

function showINFOinvestKit(obj, id) {
	var div = $('#' + id);
	var obj = $(obj);
	if (!obj.size() || !div.size()) {
		return;
	}

	if (div.is(":visible")) {
		return;
	}

	if (!obj.data("binded")) {
		obj.bind("mouseenter", function() {
			clearTimeout(obj.data("timeout"));
		}).bind("mouseleave", function() {
			obj.data("timeout", setTimeout(function() { div.hide(); }, 200));
		});

		div.bind("mouseenter", function() {
			clearTimeout(obj.data("timeout"));
		}).bind("mouseleave", function() {
			obj.data("timeout", setTimeout(function() { div.hide(); }, 200));
		});
	}
	obj.data("binded", true);

	div.show();
	var objPos = obj.offset();

	div.hide().fadeIn('normal').css({
		top: objPos.top - div.outerHeight() - 4,
		left: objPos.left + obj.outerWidth() - 20
	});
}

/*	TRANSFORMA EMAIL CODIFICADO DO HTML
*
*	DE:		${email::infoinvest.com.br#contato}
*	PARA:	contato@infoinvest.com.br
*/
function transformaEmail(){

	var elements = $(".transformaEmail");

	for(var j=0; j<elements.length; j++){
		if(elements[j].className.indexOf('transformaEmail') >=0){
			if(elements[j].nodeName == 'A'){
				elements[j].setAttribute('href', unescape(elements[j].href).replace(/\${email::([^#]*)\#([^}]*)}/gi, "$2@$1"));
			}
			elements[j].innerHTML = unescape(elements[j].innerHTML).replace(/\${email::([^#]*)\#([^}]*)}/gi, "$2@$1");
		}
	}
}

function muda_idioma_ptb() {

	if(String(document.location.href).indexOf("busca.asp") >= 0){
		var oForm = document.getElementById("buscaForm");
		oForm["idioma"].value = 'ptb';
		oForm.submit();
		return;
	}

	if (String(document.location.href).match(/(index\.asp|\/)(\?|#|$)/)) {
		document.location = "?idioma=ptb";
		return;
	}

	var endereco = document.location.href;

	endereco = endereco.replace(/\/enu\/|\/esp\//gi,"/ptb/");
	endereco = endereco.replace(/\=enu|\=esp/gi,"=ptb");
	endereco = endereco.replace(/\-enu\-|\-esp\-/gi,"-ptb-");
	endereco = endereco.replace(/\-enu.|\-esp./gi,"-ptb.");

	if (!String(document.location.href).match(/idioma\=/)) {
		endereco = endereco + "?idioma=ptb";
	}

	document.location = endereco;
}

function muda_idioma_enu() {
	if (String(document.location.href).indexOf("busca.asp") >= 0) {
		var oForm = document.getElementById("buscaForm");
		oForm["idioma"].value = 'enu';
		oForm.submit();
		return;
	}

	if (String(document.location.href).match(/(index\.asp|\/)(\?|#|$)/)) {
		document.location = "?idioma=enu";
		return;
	}

	var endereco = document.location.href;

	endereco = endereco.replace(/\/ptb\/|\/esp\//gi,"/enu/");
	endereco = endereco.replace(/\=ptb|\=esp/gi,"=enu");
	endereco = endereco.replace(/\-ptb\-|\-esp\-/gi,"-enu-");
	endereco = endereco.replace(/\-ptb.|\-esp./gi,"-enu.");

	if (!String(document.location.href).match(/idioma\=/)) {
		endereco = endereco + "?idioma=enu";
	}

	document.location = endereco;
}

function muda_idioma_esp() {

	if(String(document.location.href).indexOf("busca.asp") >= 0){
		var oForm = document.getElementById("buscaForm");
		oForm["idioma"].value = 'esp';
		oForm.submit();
		return;
	}

	if (String(document.location.href).match(/(index\.asp|\/)(\?|#|$)/)) {
		document.location = "?idioma=esp";
		return;
	}

	var endereco = document.location.href;

	endereco = endereco.replace(/\/enu\/|\/ptb\//gi,"/esp/");
	endereco = endereco.replace(/\=enu|\=ptb/gi,"=esp");
	endereco = endereco.replace(/\-enu\-|\-ptb\-/gi,"-esp-");
	endereco = endereco.replace(/\-enu.|\-ptb./gi,"-esp.");

	if (!String(document.location.href).match(/idioma\=/)) {
		endereco = endereco + "?idioma=esp";
	}

	document.location = endereco;
}

$(document).ready(function() {
	if ($.browser.msie) {
		$('br[clear=none]+br:not([clear=none])').remove();
	}

	$("#titulos > p").click(function() {
		$(this).addClass("kit_titulo_on").siblings("p").removeClass("kit_titulo_on");
		var mostrar_kit = $(this).attr("title");
		$(mostrar_kit).css("display", "block").siblings("span").css("display", "none");
	});

	$("table tr:even").addClass("even");
	transformaEmail();
});
