
jQuery(function() {
	Project._init();
});

var Project = {
    _init: function () {
        try {
            Project._grid();
            Project._busca();
            Project._iconesOverlay();
            Project._posThumbs();
            Project._posTitulos();
            Project._arredondarCantos();
        } catch (e) {
            console.log('Error: ' + e.description);
        }
    },

    //dropdown header
    _grid: function () {
        $('a.mostrar_info').hover(
			function () { $(this).find('div.info').show(); },
			function () { $(this).find('div.info').hide(); }
		);
    },

    //busca
    _busca: function () {

        //busca escondida
        $('ul#menu li.busca').hover(
			function () {
			    $(this).stop().animate({ width: 196 }, 'fast', function () {
			        $(this).find('input[type=text]').show();
			        $(this).find('input[type=text]').focus();
			    });
			    $(this).find('span').hide();
			},
			function () {
			    $(this).find('input[type=text]').hide();
			    $(this).stop().animate({ width: 28 }, 'fast');
			    $(this).find('span').show();
			}
		);

        // Evento click botão da busca geral
        $(".busca_geral").find("input[title='Buscar']").click(function (e) {
            e.preventDefault();
            var termo = $(this).parents("div").find("input[name='TermoDaBusca']").val();
            window.location.href = "/Busca/" + termo;
        });

        // Evento da tecla enter no campo da busca geral
        $(".busca_geral").find("input[name='TermoDaBusca']").bind("keypress", function (e) {
            var key = e.keyCode || e.which;
            if (key == '13') {
                window.location.href = "/Busca/" + $(this).val();
            }
        });

        // Evento click botão da busca do blog
        $(".busca_blog").find("input[title='Buscar']").click(function (e) {
            e.preventDefault();

            var termo = $(this).parents("div").find("input[name='TermoDaBusca']").val();
            window.location.href = "/Blog/Busca/" + termo;
        });

        // Evento da tecla enter no campo da busca do blog
        $(".busca_blog").find("input[name='TermoDaBusca']").bind("keypress", function (e) {
            var key = e.keyCode || e.which;
            if (key == '13') {
                window.location.href = "/Blog/Busca/" + $(this).val();
            }
        });
    },

    _tweets: function (url) {
        $.ajax({
            type: 'GET',
            url: url,
            dataType: 'html',
            beforeSend: function () {
                $("ul#twitter_feed").hide();
            },
            success: function (retorno) {
                $("ul#twitter_feed").html(retorno).fadeIn();
            }
        });
    },

    //icones overlay
    _iconesOverlay: function () {
        var div;
        $.each($('a.thumb_video'), function () {
            if ($(this).parent().hasClass('destaque')) div = '<div class=\'thumb_zoom\'></div>';
            else div = '<div class=\'thumb\'></div>';
            $(this).prepend(div);
        });
    },

    //posicionar thumb nos resultados da busca
    _posThumbs: function () {
        $.each($('ul.resultados li a span'), function () {
            if ($(this).children('img').height() < $(this).parent().height()) {
                var dif = ($(this).parent().height() - $(this).children('img').height()) / 2;
                if ($.browser.msie && $.browser.version < "8") dif += 8;
                $(this).css('margin-top', dif);
            }
        });
    },

    //posicionar titulos das últimas na home
    _posTitulos: function () {
        $.each($('.blog_item h3 a'), function () {
            if ($(this).height() < 30) $(this).parent().css('padding-top', 28);
        });
    },

    //arredondar cantos das categorias
    _arredondarCantos: function () {
        $('ul#blog_categorias li a').corner('6px');
        $('.round').corner('6px');
    }
}

