var title = 'brgomes.com [ criação de sites e sistemas PHP ]';

$(document).ready(function() {
    var queryhash = window.location.hash
    switch (queryhash) {
        case "#about":
            document.title = title + ' - Quem sou';
            initialShowAbout();
            break;
        case "#networks":
            document.title = title + ' - Redes sociais';
            initialShowNetworks();
            break;
        case "#contact":
            document.title = title + ' - Contato';
            initialShowContact();
            break;
        case "#portfolio":
            document.title = title + ' - Portfólio';
            initialShowPortfolio();
            break;
        default:
            initialShowAbout();
            break;
    }
    $("h2").hide();
    $("#vcard a").hover(showVcardLabel, hideVcardLabel);
    $("#nav-about a").click(showAbout);
    $("#nav-networks a").click(showNetworks);
    $("#nav-portfolio a").click(showPortfolio);
    $("#nav-contact a").click(showContact);
    
    $('#browsable').scrollable({
        size: 1, 
        clickable: false
    }).navigator();
    
    $('#fContact').submit(function() {
        var nome = $('#nome');
        var email = $('#email');
        var assunto = $('#assunto');
        var mensagem = $('#mensagem');
        
        if (jQuery.trim(nome.val()) == '') {
            alert('Informe o seu NOME COMPLETO!');
            nome.focus();
            return false;
        } else if (!checkMail(email.val())) {
            alert('Informe um endereço de E-MAIL válido!');
            email.focus();
            return false;
        } else if (jQuery.trim(assunto.val()) == '') {
            alert('Informe o ASSUNTO da mensagem!');
            assunto.focus();
            return false;
        } else if (jQuery.trim(mensagem.val()) == '') {
            alert('Digite a MENSAGEM a ser enviada!');
            mensagem.focus();
            return false;
        } else {
            return true;
        }
    });
    
    function checkMail(mail) {
        return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(mail);
    }
    
    createExternalLinks();
});

function createExternalLinks() {
    if (document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for (var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'externo') { // <-- É necessário inserir rel="externo" no link
                anchor.target = '_blank';
            //var title = anchor.title + ' (Este link abre uma nova janela)'; // <-- Insere este texto no final do Title do link
            //anchor.title = title;
            } else if (anchor.getAttribute('form') && anchor.getAttribute('rel') == 'externo') {
                anchor.target = '_blank';
            }
        }
    }
}

function showVcardLabel() {
    $("#vcard a span").show();
    $("#vcard a span").animate({
        top: "-40px",
        opacity: 1
    }, 250 );
}

function hideVcardLabel() {
    $("#vcard a span").animate({ 
        top: "-35px",
        opacity: 0
    }, 250 );
    setTimeout("$('#vcard a span').hide();", 250);
    $("#vcard a span").animate({ 
        top: "-45px",
    }, 250 );
}

function initialShowPortfolio() {
    $("#content").hide();
    $("#brgomes").removeClass();
    $("#brgomes").addClass("portfolio");
    $(".node").hide();
    $("#portfolio").show();
    setTimeout("$('#content').slideDown('slow');", 1000);
}

function initialShowAbout() {
    $("#content").hide();
    $("#brgomes").removeClass();
    $("#brgomes").addClass("about");
    $(".node").hide();
    $("#about").show();
    setTimeout("$('#content').slideDown('slow');", 1000);
}

function initialShowNetworks() {
    $("#content").hide();
    $("#brgomes").removeClass();
    $("#brgomes").addClass("networks");
    $(".node").hide();
    $("#networks").show();
    setTimeout("$('#content').slideDown('slow');", 1000);
}

function initialShowContact() {
    $("#content").hide();
    $("#brgomes").removeClass();
    $("#brgomes").addClass("contact");
    $(".node").hide();
    $("#contact").show();
    setTimeout("$('#content').slideDown('slow');", 1000);
}

function showAbout() {
    if ($("#brgomes").hasClass("about")){ }
    else {
        document.title = title + ' - Quem sou';
        $("#content").slideUp(500);
        $(".node").fadeOut(500);
        setTimeout("$('.node').hide();", 500);
        setTimeout("$('#about').show();", 500);
        $("#content").slideDown(500);
        $("#brgomes").removeClass();
        $("#brgomes").addClass("about");
    }
}

function showNetworks() {
    if ($("#brgomes").hasClass("networks")){ }
    else {
        document.title = title + ' - Redes sociais';
        $("#content").slideUp(500);
        $(".node").fadeOut(500);
        setTimeout("$('.node').hide();", 500);
        setTimeout("$('#networks').show();", 500);
        $("#content").slideDown(500);
        $("#brgomes").removeClass();
        $("#brgomes").addClass("networks");
    }
}

function showPortfolio() {
    document.title = title + ' - Portfólio';
    if ($("#brgomes").hasClass("portfolio")){ }
    else {
        $("#content").slideUp(500);
        $(".node").fadeOut(500);
        setTimeout("$('.node').hide();", 500);
        setTimeout("$('#portfolio').show();", 500);
        $("#content").slideDown(500);
        $("#brgomes").removeClass();
        $("#brgomes").addClass("portfolio");
    }
}

function showContact() {
    if ($("#brgomes").hasClass("contact")){ }
    else {
        document.title = title + ' - Contato';
        $("#content").slideUp(500);
        $(".node").fadeOut(500);
        setTimeout("$('.node').hide();", 500);
        setTimeout("$('#contact').show();", 500);
        $("#content").slideDown(500);
        $("#brgomes").removeClass();
        $("#brgomes").addClass("contact");
    }
}

