//Configura a função 'montre' para ser iniciada no carregamento da página
window.onload=montre;

//Função Padrão para utilização de AJAX
function openAjax()
{
	var Ajax;
	try{
		Ajax = new XMLHttpRequest();
	}catch(ee){
		try{
			Ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				Ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				Ajax = false;
			}
		}
	}
	return Ajax;
}

//Função pra esconder os submenu´s do menu
function montre(id)
{
var d = document.getElementById(id);
	for (var i = 1; i<=6; i++) {
		if (document.getElementById('smenu'+i)){
			document.getElementById('smenu'+i).style.display='none';
		}
	}

	if (d){
		d.style.display='block';
		d.style.visibility='visible';
	}
	
	montaEfeitoHoverLinkSubMenu();
}

//função para criar o efeito hover no submenu clicado
function montaEfeitoHoverLinkSubMenu()
{
	
	var Url   = location.href;
	Variaveis = Url.split ("/");
	
	qtdeItens = document.getElementById("sub-menu-produto").getElementsByTagName("li").length;

	//cntTagA = document.getElementById("sub-menu-produto").getElementsByTagName("li")[0].getElementsByTagName("a")[0].href;
	
	//alert (cntTagA.substr(cntTagA.lastIndexOf('&') + 1, 15));
	if (Variaveis[5].lastIndexOf('cod_sub_menu') == -1){
		document.getElementById("sub-menu-produto").getElementsByTagName("li")[0].getElementsByTagName("a")[0].style.color='#ffcc00';
	}else{
		for (i=0; i<qtdeItens; i++){
			cntTagA = document.getElementById("sub-menu-produto").getElementsByTagName("li")[i].getElementsByTagName("a")[0].href;
			if ((cntTagA.substr(cntTagA.lastIndexOf('&') + 1, 15)) == (Variaveis[5].substr(Variaveis[5].lastIndexOf('&') + 1, 15))){
				document.getElementById("sub-menu-produto").getElementsByTagName("li")[i].getElementsByTagName("a")[0].style.color='#ffcc00';
			}
		}
	}
}

//Função para carregar as fotos dos submenu´s dos produtos
function carregaFotosResort(legenda, nome_arquivo, cod_produto, cod_sub_menu)
{
	if(document.getElementById){
        var exibeResultado = document.getElementById("foto-player-resort");
		var exibeLegenda = document.getElementById("texto-legenda");

		var dataArray = new Array();
		
		dataArray.push("funcao=" + "foto_produto");
		dataArray = dataArray.join("&");
		var Ajax = openAjax();

		Ajax.open("POST", "http://www.litoralverde.com.br/funcoes_produtos.php", true);
		
		Ajax.onreadystatechange = function()
		{
			if(Ajax.readyState == 1){
				exibeResultado.src = "http://www.litoralverde.com.br/layout/produtos/carregando_foto.gif";
			}

			if(Ajax.readyState == 4){
				if(Ajax.status == 200){
					var resultado = Ajax.responseText;
					resultado = "http://www.litoralverde.com.br/imagens/resorts/" + cod_produto + "/" + cod_sub_menu + "/foto" + nome_arquivo +".jpg";
					exibeResultado.src = resultado;
					exibeLegenda.innerHTML = legenda;
					
				}else{
					alert("erro");
					exibeResultado.innerHTML = "Erro: .";

				}
			}
		}
		Ajax.send(dataArray);
	}
}

//Função para trocar a cor dos links para as fotos dos Produtos
function trocaCor(objeto)
{
	nNos = document.getElementById('legenda-link').getElementsByTagName('a').length;

	objeto.style.color="#ffcc00";
	for (i=0;i<nNos;i++){
		if (document.getElementById('legenda-link').getElementsByTagName('a')[i] != objeto){
			document.getElementById('legenda-link').getElementsByTagName('a')[i].style.color="#fff";
		}
	}

}


/*FUNÇÃO PARA ABRIR AS JANELAS POP-UP*/
var popUpWin=0;
function popUpWindow_scroll(URLStr, left, top, width, height)
{
	if(popUpWin){
    	if(!popUpWin.closed) popUpWin.close();
    }

	popUpWin = open
	(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='
	 +width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
	if(popUpWin){
    	if(!popUpWin.closed) popUpWin.close();
    }
    popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='
					+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

//Função para Adicionar Página aos favoritos
function adicionar_favoritos()
{
	var browsName = navigator.appName;
    var url=document.location
    var site=document.title
    if (browsName == 'Microsoft Internet Explorer'){
		if (document.all){
			window.external.AddFavorite(url,site);
		}
	}
    else if (browsName == 'Netscape'){
		alert ('Pressione CTRL + D para adicionar esta página a seus Favoritos');
	}
}

//Função para Mostrar os Resorts do Acesso Rápido
function mostraLista()
{
	document.getElementById("box-lista-links-produtos").style.display="block";
}	

//Função para Fechar os Resorts do Acesso Rápido
function fechaLista()
{
	document.getElementById("box-lista-links-produtos").style.display="none";
}



