$(function(){
    
    /* Accordion da Home */
    $('#divSemana').easyAccordion({ 
        autoStart: false,
        slideNum: false
    });
    
    /* Máscara */
    $('input').setMask();
    
    /* Página Lançamentos */
    $('#divLancamentosCarrousel').jcarousel();
    
    
    /* Redes Sociais do Topo */
    $('#redesSociais li a').hover(function(){
        $(this).parent().css("top","0px");
        $(this).parent().css("z-index","8");
        $('#linha').addClass($(this).parent().attr('id'));                    
    },function(){
        $(this).parent().css("top","-18px");
        $(this).parent().css("z-index","5");
        $('#linha').removeClass($(this).parent().attr('id')); 
    });
                
    /* Inputs com texto dentro */
    $('#formNewsletter input[type=text]').focus(function() {
        if (this.value == this.defaultValue){ 
            this.value = '';
        }
        if(this.value != this.defaultValue){
            this.select();
        }
    });
    $('#formNewsletter input[type=text]').blur(function() {
        if ($.trim($(this).val()) == ''){
            this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });
    
    /* Página Lancamentos */
    $('.divLancamento, .divEnqueteResultados').hover(function(){
        $(this).find('.info').fadeIn();
    },function(){
        $(this).find('.info').fadeOut();
    });   
    
    /* Fancy - Contato, Promocao e Cadastro  */
    $(".a-contato, .a-promocoes, .a-cadastro").fancybox({
        'titlePosition' : 'inside',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic'
    });    
    $(".a-cadastro").click(function(){
        var value = $("#email1").val();
        if(value == 'Informe seu e-mail e receba nossas novidades'){
            value = ''
        }
        $("#email").val(value);
    });
    
    /* Fancy - Vídeos do Youtube - Trailer dos filmes */
    $(".trailler").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'title'		: this.title,
            'titlePosition'     : 'inside',
            'width'		: 680,
            'height'		: 495,
            'href'		: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'		: 'swf',
            'swf'		: {
                'wmode'		: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });

        return false;
    });
    
    /* Cycle do banner Em cartaz */
    $('#divBannerPrincipal').cycle({
        slideExpr   : '.divBanner',
        timeout      : '10000'
    });
    
    /* Cycle - Lançamentos e Promoçõe da Home */
    $('#divLancamentos').cycle({
        pager       : '.nav',
        slideExpr   : 'div',
        timeout     : '8000'
    });
    
    
    /* Cycles dos dias da semana no Accordion da Home */
    $('.dd-segunda').cycle({
        pager       : '.nav-segunda',
        slideExpr   : '.filmes',
        timeout     : 0, 
        speed       : '1000'
    });    
    $('.dd-terca').cycle({
        pager       : '.nav-terca',
        slideExpr   : '.filmes',
        timeout     : 0, 
        speed       : '1000'
    });    
    $('.dd-quarta').cycle({
        pager       : '.nav-quarta',
        slideExpr   : '.filmes',
        timeout     : 0, 
        speed       : '1000'
    });    
    $('.dd-quinta').cycle({
        pager       : '.nav-quinta',
        slideExpr   : '.filmes',
        timeout     : 0, 
        speed       : '1000'
    });    
    $('.dd-sexta').cycle({
        pager       : '.nav-sexta',
        slideExpr   : '.filmes',
        timeout     : 0, 
        speed       : '1000'
    });    
    $('.dd-sabado').cycle({
        pager       : '.nav-sabado',
        slideExpr   : '.filmes',
        timeout     : 0, 
        speed       : '1000'
    });    
    $('.dd-domingo').cycle({
        pager       : '.nav-domingo',
        slideExpr   : '.filmes',
        timeout     : 0, 
        speed       : '1000'
    });    
    $('#divLancamentosCarrousel').jcarousel();
    
    
    /* Submit do contato, cadastro e enquete */
    
    function showRequest(formData, jqForm, options) { 
        var queryString = $.param(formData);
        $('.retorno').show();
        $('.retorno').html('Aguarde...!');
        return true; 
    } 
 
    function showResponse(responseText, statusText)  { 
        $('.retorno').html(responseText);
        setTimeout(function() {
            $('.retorno').fadeOut();
        }, 5000);
    }
    
    var optionsContato = { 
        target		: '.retorno',
        resetForm       : true,
        beforeSubmit	: showRequest,
        success		: showResponse
    };
    
    var optionsCadastro = { 
        target		: '.retorno',
        resetForm       : true,
        beforeSubmit	: showRequest,
        success		: showResponse
    };
    
     var optionsComentario = { 
        target		: '.retorno',
        resetForm       : true,
        beforeSubmit	: showRequest,
        success		: showResponse
    };
   
    var optionsEnquete = { 
        target		: '.retorno',
        resetForm       : true,
        dataType        : 'json',
        beforeSubmit	: showRequest,
        success		: function showResponse(data)  {             
            
            if(data.erro == '0'){
                $('.votarEnquete').remove();
                $('#formEnquete').append('<div class="votoEnquete">Obrigado por participar da nossa enquete!</div>');
            }
            
            $('.retorno').html(data.mensagem);
            
            $.each(data.votos, function(k,v){
                $('#result_'+k).html('').animate({
                    width: v+'%'
                    }, 500);
                $('.qt_votos_'+k).html(v+'%');
            });

            setTimeout(function() {
                $('.retorno').fadeOut();
            }, 2000);
        }
    };
                
    $('#formContato').submit(function() { 
        $(this).ajaxSubmit(optionsContato); 
        return false;
    });
    $('#formCadastro').submit(function() { 
        $(this).ajaxSubmit(optionsCadastro); 
        return false;
    });
   
    $('#formEnquete').submit(function() {        
        $(this).ajaxSubmit(optionsEnquete);
        return false;
    });
    
    $('#formComentario').submit(function() {        
        $(this).ajaxSubmit(optionsComentario);
        return false;
    });
    
    
    
});
