var exibe = '';

function verificaOffset(){
    $('#trabalhosItem .umJob').each(function(){ // thanks leo santana
            if(this.offsetLeft==230||this.offsetLeft==690)
                    $(this).addClass('descToLeft');
    });
}

function carregaImgs(classe){
    $('#trabalhosItem '+ classe +' img').each(function(){
            if( $(this).attr('rel') != ''){
                    $(this).attr('src',$(this).attr('title'));
                    $(this).attr('title','');
            }
    });
}

// executed after loading all assets - http://api.jquery.com/ready/
$(document).ready(function(){


            // add class to items in the fourth column
            verificaOffset();

            /*
                    rounded cornerz
            */

            // trabalhos
            $('#trabalhosItem .umJob .thumb a, #trabalhosItem .umJob:not(.destaque) .desc, #tagsLine').cornerz({
                    radius: 5,
                    background: "#171717"
            })

            // listagem de stills
            $('#trabalho #stillsItem ul li a.imagem ').cornerz({radius: 5, background: "white"})

            // home content's rounded corners
            $('#contentLine:not(body#home)').cornerz({
                    radius: 5,
                    background: "#171717"
            })

            // current tags feedback
            /*
            $('#tagsItem ul li a.current').cornerz({
                    radius: 3,
                    background: "#333333"
            })
            */






            // add class 'ultimo' to the 'stills' thumbnail listing... every multiple of 4
            $('#trabalho #stillsItem ul li:nth-child(4n)').addClass('ultimo');








            var zindex  =   1;
            // TEMP actions that shows each job's description on the portfolio listing
            $('#trabalhosItem .umJob:not(.destaque) .thumb').mouseenter(function() {
                    //console.log(parentTag);
                    zindex++;

                    $(this).parent().css('z-index', (zindex));
                    
                    desc    =   $(this).parent().find(".desc");
                    texts   =   desc.find('.texts');
                    visualizar  =   desc.find('.visualizar');

                    texts.hide();
                    visualizar.hide();


                    exibe = iniciaContagem();


            }
        );

            $('#trabalhosItem .umJob:not(.destaque) .thumb').mousemove(function(){
                clearTimeout(exibe)
                exibe   =   iniciaContagem();
            });

            $('#trabalhosItem .umJob:not(.destaque) .thumb').mouseleave(function() {
                    clearTimeout(exibe)
            });

            $('#trabalhosItem .umJob:not(.destaque) .desc').mouseleave(function() {
                    $(this).css('display', 'none');
                    $(this).parent().find(".thumb").css('display', 'block');
            });





}); // end document.ready


function iniciaContagem(){
    var tempoAbrindo=   200;
    var tempoParado =   50;
    
    exibe = setTimeout(function(){

        //primeiro fecha qualquer outro que tenha ficado aberto
        $('#trabalhosItem .umJob:not(.destaque) .desc').css('display','none').parent().find(".thumb").css('display','block');

        //agora abre o atual
        desc.fadeIn(tempoAbrindo);
        texts.fadeIn(tempoAbrindo);
        visualizar.fadeIn(tempoAbrindo);

    }, tempoParado);

    return exibe;
}
