﻿function NaoFazNada() { return false; }
function FacaParte() {
    var Grupo = ".facaparte .grupo"
    var Resultado = ".facaparte .resultado"
    var Email = ".facaparte .email"
    var Descricao = ".facaparte .vagadescricao"
    var Perfil = ".facaparte .vagaperfil"
    $(Grupo).hide();
    $(Resultado).hide();
    $(Email).hide();
    $(Grupo + " .item").removeClass('selecionado');
    $(Grupo + " .item .detalhes").hide();
    $(Descricao).html("");
    $(Perfil).html("");
    $(Grupo + " .item").click(function() {
        $(Grupo + " .item").removeClass('selecionado');
        $(this).addClass('selecionado');
        $(Descricao).html($(this).find(".descricao").html());
        $(Perfil).html($(this).find(".perfil").html());
        $(Resultado).show();
        $(Email).show();
        $('.scroll').jScrollPane();
    });
    $(Grupo).show();
}

function TrataPaginacaoNoticias(PaginaAtual) {
    /************ Paginacao ***************************************************************/
    var items_per_page = 1;
    function pageselectCallback(page_index, jq) {
    // Get number of elements per pagionation page from form
    var num_entries = $('#hiddenresult2 div.result').length;

        var max_elem = Math.min((page_index + 1) * items_per_page, num_entries);

        $('#Searchresult2').empty();
        // Iterate through a selection of the content and build an HTML string
        for (var i = page_index * items_per_page; i < max_elem; i++) {
            $('#Searchresult2').append($('#hiddenresult2 div.result:eq(' + i + ')').clone());
        }
        // Prevent click eventpropagation
        $(".popup").thumbPopup({
            imgSmallFlag: "_thumb",
            imgLargeFlag: "",
            cursorTopOffset: 0,
            cursorLeftOffset: 50,
            loadingHtml: "<div style='padding: 5px;width:400px;text-align:center'>Carregando imagens...</div>"
        });

        $('.slideshow').cycle({
            fx: 'fade',
            speed: 500,
            timeout: 3000,
            pause: 0
        });
        return false;
    }

    /** 
    * Callback function for the AJAX content loader.
    */
    function initPagination() {
        var num_entries = $('#hiddenresult2 div.result').length;
        // Create pagination element
        $("#Pagination2").pagination(num_entries, {
            num_edge_entries: 1,
            num_display_entries: 5,
            callback: pageselectCallback,
            items_per_page: items_per_page,
            current_page: PaginaAtual
        });
    }

    initPagination();
}


function ExecutarJavaScripts() {
    /************ Paginacao ***************************************************************/
    var items_per_page = 4;
    function pageselectCallback(page_index, jq) {
        // Get number of elements per pagionation page from form
        var num_entries = $('#hiddenresult div.result').length;

        var max_elem = Math.min((page_index + 1) * items_per_page, num_entries);

        $('#Searchresult').empty();
        // Iterate through a selection of the content and build an HTML string
        for (var i = page_index * items_per_page; i < max_elem; i++) {
            $('#Searchresult').append($('#hiddenresult div.result:eq(' + i + ')').clone());
        }
        // Prevent click eventpropagation
        $(".popup").thumbPopup({
            imgSmallFlag: "_thumb",
            imgLargeFlag: "",
            cursorTopOffset: 0,
            cursorLeftOffset: 50,
            loadingHtml: "<div style='padding: 5px;width:400px;text-align:center'>Carregando imagens...</div>"
        });
        $('.slideshow').cycle({
            fx: 'fade',
            speed: 500,
            timeout: 3000,
            pause: 0
        });
        return false;
    }

    function onBefore() {
        try {

            if (this.alt != undefined)
                $('#output').html(this.alt);
            else
                $('#output').html($('img:first-child', this).attr("alt"));
        } catch (err) { }
    }
    function onAfter() {
        try {

            if (this.alt != undefined)
                $('#output').html(this.alt);
            else
                $('#output').html($('img:first-child', this).attr("alt"));
        } catch (err) { }
    }

    /** 
    * Callback function for the AJAX content loader.
    */
    function initPagination() {
        var num_entries = $('#hiddenresult div.result').length;
        // Create pagination element
        $("#Pagination").pagination(num_entries, {
            num_edge_entries: 1,
            num_display_entries: 5,
            callback: pageselectCallback,
            items_per_page: items_per_page
        });
    }
        $(".popup").thumbPopup({
            imgSmallFlag: "_thumb",
            imgLargeFlag: "",
            cursorTopOffset: 0,
            cursorLeftOffset: 50,
            loadingHtml: "<div style='padding: 5px;width:400px;text-align:center'>Carregando imagens...</div>"
        });

        $('.slideshowhome').toggle();

        $('#resume2').toggle();

        $('#pause2').click(function() {
            $('#pause2').toggle();
            $('#resume2').toggle();
            $('.slideshow').cycle('pause');
        });
        $('#resume2').click(function() {
            $('#pause2').toggle();
            $('#resume2').toggle();
            $('.slideshow').cycle('resume', true);
        });

        $('.slideshow').cycle({
            fx: 'fade',
            speed: 500,
            timeout: 3000,
            pause: 0
        });

        $('.slideshowhome').cycle({
            fx: 'fade',
            speed: 500,
            timeout: 12000,
            before: onBefore,
            after: onAfter,
            next: '#next2',
            prev: '#prev2',
            pause: 1,
            cleartype: 1
        });

        $('.slideshowhome').toggle();


        $('.scroll').jScrollPane();

        initPagination();
        $("#tree").treeview({
            collapsed: true,
            animated: "medium",
            persist: "location"
        });


        $(".popupgaleria").colorbox({
            width: "812px",
            height: "524px",
            iframe: true,
            /*href:"#inline_example1",*/
            onComplete: function() {
                /*alert('Acabou de carregar tudo'); */
            },
            onClosed: function() {
                $("a").blur(); 
            }
        });
        $(".popupfoto").colorbox({
            onClosed: function() {
                $("a").blur();
            }
        });

        FacaParte();

        $.ajax({
            type: "POST",
            url: "default.aspx/GetPaginaAtual",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                TrataPaginacaoNoticias(msg.d);
            }
        }); 
    }



function EndRequestHandler(sender, args) {
    $(function() {ExecutarJavaScripts();});
}

$(function() {
    ExecutarJavaScripts();
    lContinua = false;
    try {
        if (Sys != undefined) lContinua = true;
    } catch (e) {
    }
    if (lContinua) {
        if (Sys.WebForms != undefined) Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    }
});

