Shadowbox.init();

checkFields = function() {
    var retorno = true;
    var erro = '';

    $('.required-input').each(
        function() {
            if($(this).val() == '') {
                retorno = false;
                erro += 'Campo '+$(this).attr('title')+' precisa ser preenchido!<br />';
            }
        }
    );
    $('.required-select').each(
        function() {
            if($(this).val() == -1) {
                retorno = false;
                erro += 'Campo '+$(this).attr('title')+' precisa ser selecionado!<br />';
            }
        }
    );

    $('.check-email').each(
        function() {
            var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
            if( $(this).val().search(emailRegEx) == -1 ) {
                retorno = false;
                erro += 'Email inválido!';
            }
        }
    );

    if(!retorno) {
        $('#alert-fail .message').html(erro);

        Shadowbox.open({
            content:    $('.alert-fail').html(),
            player:     "html",
            height:     $('.alert-fail').height(),
            width:      $('.alert-fail').width()
        });
    }

    return retorno;
}

$(document).ready(
    function() {
        box('.shadow');
        box('.shadow-rounded',true);
        box('.shadow-rounded .shadow-rounded',true);

        $('input[name=botao-newsletter]').click(
            function() {
                var nome = Base64.encode($('input[name=nome-newsletter]').val());
                var email = Base64.encode($('input[name=email-newsletter]').val());

                if($('input[name=nome-newsletter]').val() == '' || $('input[name=nome-newsletter]').val() == 'Nome' ||
                   $('input[name=email-newsletter]').val() == '' || $('input[name=email-newsletter]').val() == 'Email' ) {
                    
                    $('#alert-fail .message').html('Preencha os campos corretamente!');

                    Shadowbox.open({
                        content:    $('.alert-fail').html(),
                        player:     "html",
                        height:     $('.alert-fail').height(),
                        width:      $('.alert-fail').width()
                    });

                } else {
                    $.ajax({
                            url: "/index/cadastro-newsletter/nome/"+nome+"/email/"+email,
                            success: function(data) {
                                if(data == 'win') {
                                    $('#alert-success .message').html('Cadastro efetuado com sucesso!');

                                    Shadowbox.open({
                                        content:    $('.alert-success').html(),
                                        player:     "html",
                                        height:     $('.alert-success').height(),
                                        width:      $('.alert-success').width()
                                    });
                                } else {
                                    $('#alert-fail .message').html('Erro ao tentar efetuar o cadastro!<br/>Por favor, tente novamente mais tarde.');

                                    Shadowbox.open({
                                        content:    $('.alert-fail').html(),
                                        player:     "html",
                                        height:     $('.alert-fail').height(),
                                        width:      $('.alert-fail').width()
                                    });
                                }
                            }
                        });
                }
            }
        );

        if($('.hide-value-from-title').length > 0) {
            $('.hide-value-from-title').focus(
                function() {
                    if($(this).val() == $(this).attr('title'))
                        $(this).val('');
                }
            );
            $('.hide-value-from-title').blur(
                function() {
                    if($.trim($(this).val()) == '')
                        $(this).val($(this).attr('title'));
                }
            );
        }

        $('select[name=artistas]').change(
            function() {
                var selecionado = $(this).val();

                $('.dias-artista').hide();

                if(selecionado != -1) {
                    $('#dias-livres-'+selecionado).show();
                }
            }
        );

        if($('.detalhes-noticia .image-container').length > 0) {
            $('.detalhes-noticia .image-container').hover(
                function() {
                    $(this).find('.zoom').show();
                },
                function() {
                    $(this).find('.zoom').hide();
                }
            );
        }

        if($('.evento-data-click').length > 0) {
           $('.evento-data-click').click(
                function() {
                    var class_imagem = this.id;

                    $('.data-ativa').removeClass('data-ativa');
                    $(this).addClass('data-ativa');

                    if(!$('.imagem-evento-atual').hasClass(class_imagem)) {
                        var imagem_atual = $('.imagem-evento-atual');
                        var imagem_escolhida = $('.'+class_imagem);
                        
                        imagem_atual.css('z-index','100');

                        imagem_escolhida.hide();
                        imagem_escolhida.css('z-index','150');
                        imagem_escolhida.fadeIn('slow',function(){
                            imagem_escolhida.addClass('imagem-evento-atual');

                            imagem_atual.css('z-index','50');
                            imagem_atual.removeClass('imagem-evento-atual');
                        });
                    }
                }
            );
        }
        
        if($('#cycle').length > 0) {
            $('#cycle').cycle({
                speed:  800,
                timeout:  10000,
                pager: '#cycle-nav'
            });
        }
        if($('#artistas-cycle').length > 0) {
            $('#artistas-cycle').cycle({
                fx: 'scrollLeft',
                speed:  800,
                timeout:  10000,
                before: function(){
                    $('#legenda-artista').html('');
                },
                after: function() {
                    $('#legenda-artista').html($('#legenda-artista-'+this.id).html());
                },
                next:   '#right-scroller',
                prev:   '#left-scroller'
            });
        }
        if($('#vips-cycle').length > 0) {
            $('#vips-cycle').cycle({
                fx: 'scrollLeft',
                speed:  800,
                timeout:  10000,
                before: function(){
                    $('#legenda-vip').html('');
                },
                after: function() {
                    $('#legenda-vip').html($('#legenda-vip-'+this.id).html());
                },
                next:   '#right-scroller-vip',
                prev:   '#left-scroller-vip'
            });
        }
        if($('#palestrante-cycle').length > 0) {
            $('#palestrante-cycle').cycle({
                fx: 'scrollLeft',
                speed:  800,
                timeout:  10000,
                before: function(){
                    $('#legenda-palestrante').html('');
                },
                after: function() {
                    $('#legenda-palestrante').html($('#legenda-palestrante-'+this.id).html());
                },
                next:   '#right-scroller-palestrante',
                prev:   '#left-scroller-palestrante'
            });
        }
    }
);



