/**
 * Rotinas que operam no lado do cliente.
 *
 * @author Microcis
 * @copyright 2010 - Prefeitura Municipal de Paty do Alferes
 *
 * @package WordPress
 * @subpackage PMPA
 *
 * $Id$
*/

// Ao iniciar o DOM do website..
$(document).ready(function() {
    
  /*
    if ($('#inicial').length > 0) {
        // Exibe o banner da Festa do Tomate.
 
        $.fancybox({
            'type': 'image',
            'href': 'http://patydoalferes.rj.gov.br/wp-content/themes/pmpa/imagens/banner-festa-do-tomate-2011.jpg',
            'autoDimensions': true,
            'transitionIn': 'fade',
            'transitionOut': 'fade'
        });
    }
  */  
    /** Rotinas globais. */
        /** Cabeçalho. */
            /** Navegação superior e normal. */
            jQuery.each([
                $('ul.navegacao > li'),
                $('ul.navegacao > li > ul > li')
            ], function() {
                // Executa ao "entrar" com o mouse no elemento..
                $(this).mouseenter(function(e) {
                    // Insere o elemento do "plano de fundo" do link.
                    var $hover = $('<a>').attr({'href': $(this).children('a').attr('href'), 'class': 'hover'}).css({display: 'none', opacity: 0});
                    $hover.insertAfter($(this).children('a:first'));

                    // Exibe de forma animada o "plano de fundo" do link.
                    $hover.css('display', 'block').animate({opacity: 1}, 200);

                    // Exibe a "aba" correspondente ao item solicitado.
                    $(this).children('ul').css({display: 'block', opacity: 0}).animate({opacity: 1}, 200, function() {
                        $(this).attr('style', '');
                    });
                });

                // Executa ao "sair" com o mouse do elemento..
                $(this).mouseleave(function() {
                    // Define a fila de efeitos, pára o que está em execução e e exclui o "plano de fundo".
                    $(this).children('.hover').queue("fx", []);
                    $(this).children('.hover').stop().animate({opacity: 0}, 200, function() {
                        $(this).remove();
                    });

                    // Define a fila de efeitos, pára o que está em execução e oculta o div.
                    $(this).children('ul').queue("fx", []);
                    $(this).children('ul').stop().animate({opacity: 0}, 200, function() {
                        $(this).css('display', 'none');
                    });
                });
            });
            /** ENDOF Navegação superior e normal. */
        /** ENDOF Cabeçalho. */

        /** Sidebar esquerda. */
        $sidebarEsquerda = $('div#esquerda.sidebar');
        
        if ($('div.combos', $sidebarEsquerda).length == 1) {
            /** Combos. */
            $combos = $('div.combos form', $sidebarEsquerda);

            $.each($combos, function(n, e) {
                $(this).submit(function() {
                    window.location = $('select', $(this)).val();
                    return false;
                });
            });
            /** ENDOF Combox. */
        }
        /** ENDOF Sidebar esquerda. */
    /** Rotinas globais. */

    /** Posts. */
    $post = $('body.post');
        /** Páginas. */
        $pagina = $('body.pagina');

        if ($('div#galeria-fotos', $pagina).length) {
            /** Galeria de Fotos. */
            $('div#galeria-fotos a').fancybox({
                'transitionIn' : 'fade',
                'transitionOut' : 'elastic',
                'speedIn' : 350,
                'speedOut' : 200,
                'overlayShow' : true,
                'titlePosition': 'over'
            });
            /** ENDOF Galeria de Fotos. */
        }

        if ($('div#prestacao-de-contas', $pagina).length) {
            /** Prestação de Contas. */
            $prestacaoDeContas = $('div#prestacao-de-contas', $pagina);

            $('li', $prestacaoDeContas).each(function() {
                $($(this)).mouseenter(function() {
                    $('h3', $(this)).css('font-weight', 'bold');
                });

                $($(this)).mouseleave(function() {
                    $('h3', $(this)).css('font-weight', 'normal');
                });

                $('select', $(this)).change(function() {
                    window.location = $('option:selected', $(this)).attr('value');
                });
            });
            /** ENDOF Prestação de Contas. */
        }
        /** ENDOF Página. */
    /** ENDOF Post. */
});
