$(document).ready( function(){

    $("input[name='telefone'], input[name='celular']").focus( function(){
        $(this).mask('9999-9999', { placeholder : '_' });
    });
//    $("input[name='telefone'], input[name='celular']").blur( function(){
//        if($(this).val() == '____-____'){
//            if($(this).attr('name') == 'celular')
//                nome = 'celular';
//            else if($(this).attr('name') == 'telefone')
//                nome = 'telefone';
//            $(this).unmask().val(nome);
//        }
//    });

    $('#slider-code').tinycarousel();

    $('#ritmos-carousel').tinycarousel({axis: 'y'});

    $('li.ritmo-descricao').not('.visivel').hide();

    $('li.ritmo-nome').click( toggleRitmo );

    $('img.infra-thumb').click( function(){
        $('#imagem-grande').html("<img src='_imgs/infra/" + $(this).attr('tgt') + "' />");
    });

    $('table.grade tr:gt(1)').hover( function(){
        $(this).css('background-color','#E1E1E1');
    }, function(){
        $(this).css('background-color','#FFF');
    })

    $('table.grade-intensivos tr:gt(0)').hover( function(){
        $(this).css('background-color','#E1E1E1');
    }, function(){
        $(this).css('background-color','#FFF');
    })

    $('#filtraRitmo').change( function(){
        if($(this).val() != ''){
            $('table tr').show();
            $('table tr').not('.dias, .titulos, .rit-'+$(this).val() ).hide();
        }else{
            $('table tr').show();
        }
    });

    if($('#filtro-ritmo').length){
        if($('#filtro-ritmo').val() != ''){
            ritmo = $('#filtro-ritmo').val();
            $('#filtraRitmo option').each( function(){
               if($(this).val() == ritmo)
                   $(this).attr('selected', 'selected');
            });
            $('#filtraRitmo').trigger("change");
        }
    }

    $('.abreModal').each( function(){
        locat = location.pathname;
        $(this).modal({closeClickOut:true});
    })

    $('.youtube').each( function(){
        if($(this).hasClass('nothumb')){
            $(this).prettyPhoto({theme: 'light_square', social_tools : ''});
        }else{
            vid = $(this).attr('href');
            size = $(this).attr('size');
            thumb = $.jYoutube(vid, size);
            $(this).html("<a class='ytlink' href='"+vid+"'><img src='"+thumb+"'></a>");
            $(this).prettyPhoto({theme: 'light_square', social_tools : ''});
        }
    })

    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'light_square',
        social_tools : '',
        slideshow : false
    });
/* 15h Gazeta */
    $('.promo').each( function(){
        alt = $(this).find('.descricao').css('height');
        alt = alt.replace("px", "");
        acresc = (parseInt(alt) + 25) - 133;
        if(acresc > 0){
            $(this).find('.esquerda').css('marginTop', acresc + 'px');
            $(this).find('.saber').css('marginTop', acresc + 'px');
        }
    });

    $('#form-contato').submit( function(){
        if($('#msg').val() == '' || $('#msg').val() == 'escreva sua mensagem juntamente com o ritmo de interesse'){
            alert('escreva sua mensagem juntamente com o ritmo de interesse!');
            $('#msg').focus();
            return false;
        }
        return true
    });
});

