$(function () {
			

    // Redirect site
    var urlSite = "" + window.location;
    var pieceUrl1 = urlSite.split(".");
    var siteZeMaranhao = pieceUrl1[1].toLowerCase();


    switch (siteZeMaranhao) {

    case "15zemaranhao":

        window.location = "http://www.zemaranhao15.com.br"

        break

    default:

    };


    $('a.media').media({
        width: 300,
        height: 20
    });

    $('.ColunaCentral .UltimasNoticias ul').find('li:first').addClass('DestaqueNoticia');
    $('.ColunaCentral .UltimasNoticias ul').find('li:last').addClass('UltimaNoticia');


/*    var FotosTvFlash = $('.TvFlash ul').find('li').size();
    switch (FotosTvFlash) {
    case (FotosTvFlash = 1):

        $('.TvFlash .Anterior, .TvFlash .Proximo').css('display', 'none');

        break;

default: 

};*/
/*
	$('.TvFlash').jCarouselLite({
		btnNext: '.Proximo',
		btnPrev: '.Anterior',
		auto: 10000,
		speed: 500,
		visible: 1
	});
*/

    $('.FotosEuComZe').jCarouselLite({
        btnNext: '.Proximo2',
        btnPrev: '.Anterior2',
        auto: 10000,
        speed: 500,
        visible: 1
    });

	$('.ContainerEventos').jCarouselLite({
        vertical: true,
        scroll: 1,
		auto: 3000,
		speed: 900,
		visible: 2
    });	


    $('#cf_field_1, .FormularioDoacoes li input').attr('value', 'Digite seu e-mail');


    $('#s, #cf_field_1, .FormularioDoacoes input').each(function () {
        var default_value = this.value;
        $(this).css('color', '#929292');
        $(this).focus(function () {
            if (this.value == default_value) {
                this.value = '';
                $(this).css('color', '#666');
            }
        });
        $(this).blur(function () {
            if (this.value == '') {
                $(this).css('color', '#929292');
                this.value = default_value;
            }
        });
    });

	$('.ContainerTvFlash').css('overflow','visible');
    $('.Videoteca li:nth-child(4n)').css('margin-right', '0');
    $('.ListaMiniaturas li:nth-child(3n)').css('padding-right', '0');
    $('.EuComZe li:nth-child(4n)').css('padding-right', '0');


    $('.GaleriaFotos div').cycle({
        fx: 'fade',
        speed: 'slow',
        speed: 2000,
        timeout: 4000
    });
	
	$('#home-rotator-container').cycle({
	   	fx: 'fade',
	   	timeout: '10000',
	   	speed: '400',
	   	pager: '#home-rotator-pager',
	   	pagerEvent: 'mouseover',
	   	pauseOnPagerHover: 'true',
	   	allowPagerClickBubble: 'true',
		pagerAnchorBuilder: function(idx, slide) { return '#home-rotator-pager li:eq(' + idx + ') a'; } 
	});	


    var Eventos = $('.AgendaCandidato .ContainerEventos ul').find('li').size();
    var AlturaUl = $('.ContainerEventos ul').height();
    body = $('body');

    switch (Eventos) {
    case (Eventos = 1):
        $('.AgendaCandidato .Link').css('display', 'none');
        if (body.hasClass("Home")) {
            $('.ContainerEventos').css('height', '146px');
        }
        else {
            $('.ContainerEventos').css('height', '69px');
        };
        break;
    case (Eventos = 2):
        $('.AgendaCandidato .Link').css('display', 'none');
        if (body.hasClass("Home")) {
            $('.ContainerEventos').css('height', '146px');
        }
        else {
            $('.ContainerEventos').css('height', '146px');
        };
        break;
    case (Eventos = 3):

        if (body.hasClass("Home")) {
            $('.ContainerEventos').css('height', '146px');
        }
        else {
            $('.AgendaCandidato .Link').css('display', 'none');
            $('.ContainerEventos').css('height', '223px');
        };
        break;
    default:

    };


   /* $('.AgendaCandidato .Link').click(function () {

        elemento = $(this);


        if (elemento.hasClass("Ocultar")) {
            if (body.hasClass("Home")) {


                $('.AgendaCandidato .ContainerEventos').animate({
                    'height': '146px'
                }, "slow");
            }
            else {
                $('.AgendaCandidato .ContainerEventos').animate({
                    'height': '223px'
                }, "slow");
            };

            $(this).removeClass('Ocultar').text('Ver todas');
        }
        else {
            $(this).addClass('Ocultar').text('Ocultar');
            $('.AgendaCandidato .ContainerEventos').animate({
                'height': AlturaUl
            }, "slow");
        }
        return (false);
    });*/


    $('#MenuFases a').click(function () {

        var Fase = $(this).attr('rel');

        $('.ColunaEsquerda, .ColunaCentral').css('display', 'none');
        $('#InternaBiografia').fadeIn('fast');

        $('.NavBiografia').find('#' + Fase).addClass('Ativo');
        $('#InternaBiografia').find('div.' + Fase).slideDown();
    });

    $('.NavBiografia a').click(function () {
        var Clique = $(this).attr('id');
        $('.NavBiografia a').removeClass('Ativo');
        $(this).addClass('Ativo');
        $('.DescricaoPeriodo').css('display', 'none');
        $('.' + Clique).css('display', 'block');

        return (false);

    });

    $('.PaginacaoInativa').click(function () {
        return (false);
    });

    $('.BioAnterior').click(function () {
        var PagAtual = $(this).parent();

        $(PagAtual).prev().css('display', 'block');
        $(PagAtual).css('display', 'none');

        var LinkAtual = $('.NavBiografia').find('a.Ativo');

        $(LinkAtual).parent().prev().find('a').addClass('Ativo');
        $(LinkAtual).removeClass('Ativo');

        $('html,body').animate({
            scrollTop: $("#Ancora").offset().top
        }, 'slow');

        return (false);

    });
    $('.BioProxima').click(function () {
        var PagAtual = $(this).parent();

        $(PagAtual).next().css('display', 'block');
        $(PagAtual).css('display', 'none');

        var LinkAtual = $('.NavBiografia').find('a.Ativo');

        $(LinkAtual).parent().next().find('a').addClass('Ativo');
        $(LinkAtual).removeClass('Ativo');

        $('html,body').animate({
            scrollTop: $("#Ancora").offset().top
        }, 'slow');

        return (false);

    });

    $('.Videoteca img').click(function () {
        var url = $(this).attr('rel');
        var pieceUrl = url.split("=");
        var chave = pieceUrl[1];

        $('.Player').html('<object width="562" height="317">' + '<param name="movie" value="http://www.youtube.com/v/' + chave + '&amp;hl=pt_BR&amp;fs=1?rel=0"></param>' + '<param name="allowFullScreen" value="true"></param>' + '<param name="allowscriptaccess" value="always"></param>' + '<embed src="http://www.youtube.com/v/' + chave + '&amp;hl=pt_BR&amp;fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="562" height="317">' + '</embed>' + '</object>');
        $('html,body').animate({
            scrollTop: $("#Ancora").offset().top
        }, 'slow');
    });


    $('#CategoriasTexto li').find('a:first').click(function () {

        if ($(this).next('ul').is(':visible')) {
            $('#CategoriasTexto li').find('ul:first').css('display', 'none');
            $(this).next('ul').slideUp('slow');
        } else {
            $('#CategoriasTexto li').find('ul:first').css('display', 'none');
            $(this).next('ul').slideDown('slow');
        };


        $('#CategoriasTexto').find('ul:last').addClass('Ultimo');


        return (false);
    });


/*var UltimoVideo = $('.Videoteca').find('li:first img').attr('rel');
		var pieceUrl = UltimoVideo.split("=");
		var chave2 = pieceUrl[1];*/

    $('.emailreqtxt, .reqtxt').html('<em>*</em>').addClass('CamposObrigatorios');

    $('.sendbutton').attr('value', '');


    $('body.Home .Twitter').find('li:first').css('display', 'block');

});
// Funcao para exibir ultimo video 

function ExibeUltimo() {
    $('.Player').html('<object width="562" height="317">' + '<param name="movie" value="http://www.youtube.com/v/' + Video + '&amp;hl=pt_BR&amp;fs=1?rel=0"></param>' + '<param name="allowFullScreen" value="true"></param>' + '<param name="allowscriptaccess" value="always"></param>' + '<embed src="http://www.youtube.com/v/' + Video + '&amp;hl=pt_BR&amp;fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="562" height="317">' + '</embed>' + '</object>');
};

function ExibeUltimoHome() {
    $('.MiniaturaVideo').html('<object width="265" height="208">' + '<param name="movie" value="http://www.youtube.com/v/' + Video + '&amp;hl=pt_BR&amp;fs=1?rel=0"></param>' + '<param name="allowFullScreen" value="true"></param>' + '<param name="allowscriptaccess" value="always"></param>' + '<param name="wmode" value="transparent"></param>' + '<embed src="http://www.youtube.com/v/' + Video + '&amp;hl=pt_BR&amp;fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="transparent" allowfullscreen="true" width="265" height="208">' + '</embed>' + '</object>');
};
// Funcao para exibir thumb do video do youtube 
(function ($) {
    $.extend({
        jYoutube: function (url, size) {
            if (url === null) {
                return "";
            }
            size = (size === null) ? "big" : size;
            var vid;
            var results;
            results = url.match("[\\?&]v=([^&#]*)");
            vid = (results === null) ? url : results[1];
            if (size == "small") {
                return "http://img.youtube.com/vi/" + vid + "/2.jpg";
            } else {
                return "http://img.youtube.com/vi/" + vid + "/0.jpg";
            }
        }
    })
})(jQuery);
