﻿var menu_atual = "";
var menu_bool = 1;
var accord_atual = "";
var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

$(document).ready(function(){
    $('#topo div.menu div.menu_item, #menu div.menu_item').mouseover(function(){
        var id = $(this).children("a").attr("rel");
        if(menu_atual != "" && id != menu_atual){
            $('#submenu_'+menu_atual.replace("menu_","")).hide();
        }
        if(id == "menu_1"){ $(this).children("a").children("img").attr("src","imagens/"+idioma+"/menu_alagoa_on.gif"); }
        if(id == "menu_2"){ $(this).children("a").children("img").attr("src","imagens/"+idioma+"/menu_projeto_on.gif"); }
        $('#submenu_'+id.replace("menu_","")).show();
        menu_atual = id;
    });
    
    $('#topo div.menu div.menu_item, #menu div.menu_item').mouseout(function(){
        var id = $(this).children("a").attr("rel");
        if(id == "menu_1"){ $(this).children("a").children("img").attr("src","imagens/"+idioma+"/menu_alagoa.gif"); }
        if(id == "menu_2"){ $(this).children("a").children("img").attr("src","imagens/"+idioma+"/menu_projeto.gif"); }
        $('#submenu_'+id.replace("menu_","")).hide();
    });
    
    $('span.tooltip').mouseover(function(){
        $(this).css("color", "#b2d234");
        var left = parseInt($(this).offset()['left']);
        var top = parseInt($(this).offset()['top']);
        if(left >= 445){
            $('#habitatip').css({
                'top': top - 140,
                'left': left - (193 - ($(this).width()/2)),
                'background': 'url(imagens/bg_tooltip.png) no-repeat'
            });
        } else {
            $('#habitatip').css({
                'top': top - 140,
                'left': left + (($(this).width()/2) - 25),
                'background': 'url(imagens/bg_tooltip2.png) no-repeat'
            });
        }
        $('#habitatip_tit').html($(this).children("b").html());
        $('#habitatip_txt').html($(this).children("i").html());
        $('#habitatip').fadeIn(500);
    });
     
    $('span.tooltip').mouseout(function(){
        $(this).css("color", "#1f9dcc");
        $('#habitatip').hide();
    });
    
    $('#topo, #menu, #rodape').pngFix({ metodo: 'crop' });
    
    $('#rodape div.ico a').mouseover(function(){
        var id = $(this).attr("rel");
        var nr = id.replace("tooltip_", "");
        if(jQuery.browser.msie && (ie55 || ie6)){
            var filter = $('span', $(this)).css("filter");
            $('span', $(this)).css("filter", filter.replace("ico_rodape"+nr+".png", "ico_rodape"+nr+"_on.png"));
        } else {
            $('#ttip_img_'+nr).attr("src", "imagens/ico_rodape"+nr+"_on.png");
        }
        $('#'+id).fadeIn(500);
    });
    
    $('#rodape div.ico a').mouseout(function(){
        var id = $(this).attr("rel");
        var nr = id.replace("tooltip_", "");
        if(jQuery.browser.msie && (ie55 || ie6)){
            var filter = $('span', $(this)).css("filter");
            $('span', $(this)).css("filter", filter.replace("ico_rodape"+nr+"_on.png", "ico_rodape"+nr+".png"));
        } else {
            $('#ttip_img_'+nr).attr("src", "imagens/ico_rodape"+nr+".png");
        } 
        $('#'+id).hide();
    });
   
    initLightbox();
    
    if(url.search("#") != "-1"){
        galeria = url.split("#");
        abrirGaleria(galeria[1]);
    }
});

function initLightbox(){
    if($('a[rel*=lightbox]').size() > 0){
        $('a[rel*=lightbox]').fancybox();
    }
    if($('a[rel*=mapas]').size() > 0){
        $('a[rel*=mapas]').fancybox({
            galeria : 'mapa'
        });
    }
    if($('a[class*=iframe]').size() > 0){
        $('a[class*=iframe]').fancybox();
    }
}

function configurar_input(oElem,iValue,blankValue) {
	if(oElem.value==iValue || oElem.value=='') {
		oElem.value = (blankValue)?'':iValue;
	}
}

function corrigirAltura(url){
    var colesq = $('#colesq').height();
    var coldir = $('#coldir').height();
    
    if(url != "default.aspx" && url != "Default.aspx" && url != "" && coldir > colesq){
        if(url == "documentos.aspx" || url == "contato.aspx" || url == "imprensa.aspx" || url == "videos.aspx" || url == "mapas.aspx"){
            $('#colesq div.box div.texto').height($('#coldir').height()-120);
        } else {
            $('#colesq div.box div.texto').height($('#coldir').height()-133);
        }
    }
}

function AbrirFullScreen(video){
    window.location = "videos.aspx#"+video;
}

function abrirVideo(video){
    video = video.replace("video_","");
    video = parseInt(video)-1;
    $('#colesq div.galeria div.img a[class=iframe]:eq('+video+')').click();
}

function abrirGaleria(galeria){
    $('#colesq div.galeria div.img a[rel=lightbox['+galeria+']]').click();
}

function verDocumentos(id){
    if(accord_atual != id){
        if(accord_atual != ""){
            $('#coldir #arquivos_'+accord_atual).hide(500);
        }
        $('#coldir #arquivos_'+id).show(500);
        accord_atual = id;
    } else {
        $('#coldir #arquivos_'+accord_atual).hide(500);
        accord_atual = "";
    }
}

function validar_busca(){
    if(document.getElementById('pS').value=='' || document.getElementById('pS').value=='Search in the Website'){
        alert("Type a keyword!");
        document.getElementById('pS').focus();
        return false;
    }
    return true;
}

function validar_contato(){
    if(document.getElementById('t_nome').value=='' || document.getElementById('t_nome').value=='Name'){
        alert("The field name is required!");
        document.getElementById('t_nome').focus();
        return false;
    }
    if(document.getElementById('t_email').value=='' || document.getElementById('t_email').value=='E-mail'){
        alert("The field email is required!");
        document.getElementById('t_email').focus();
        return false;
    }
    if(document.getElementById('t_mensagem').value=='' || document.getElementById('t_mensagem').value=='Message'){
        alert("The field message is required!");
        document.getElementById('t_mensagem').focus();
        return false;
    }
    return true;
}
