﻿$(document).ready(function(){

    var width='';
    var newWidth='';
    var contWidth='';

    var elementos = document.getElementsByTagName('*');
    for (i=0; i<elementos.length; i++) {
        if(elementos[i].id == "line" || elementos[i].id == "line2") {
            altura = elementos[i-1].clientHeight;
            largura = elementos[i-1].style.width;
            elementos[i].style.height=((altura/2)+2);
            elementos[i].style.width=largura;
        }
        if(elementos[i].id == "boxOut") {
            width = elementos[i].clientWidth;
            newWidth = width-20;
            elementos[i].style.width=newWidth;
            contWidth = newWidth-8;
        }
        if (elementos[i].id == "boxContent") {
            elementos[i].style.width=contWidth;
        }
    }

    $(".lastScreen").css('display','none');
    $(".divScreen").css('display','block');
    $("#barraEsquerda").css('height',$("#container").css('height'));
    $("#barraDireita").css('height',$("#container").css('height'));
    $('.hideVersion').css('display','none');
    
    $("#voltar").click(function(){
        rel = $(this).find('a').attr('rel');
        clearTimeout(t);
        lastUpdate(rel);
    });

    $("#avancar").click(function(){
        rel = $(this).find('a').attr('rel');
        clearTimeout(t);
        lastUpdate(rel);
    });

    $(".listaProjeto").hover(function() {
        $(this).prev("#projetoImagem").css('display','block');
    },
    function() {
        $(this).prev("#projetoImagem").css('display','none');
    });

    $("tr#elenco").hover(function() {
        $(this).children().css('background','#3B3B3B');
        $(this).css('cursor','pointer');
    },
    function() {
        $(this).children().css('background','#282828');
    });
   
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $("#ultimosLancamentos").mousemove(function(e){
        $('#balaoTip').css('top', e.pageY+30).css('left', e.pageX+30);
    });

    $(".voltaLancs").click(function(){
        clearTimeout(t);
        screens = $(".screensB");
        if (lastNow == 1) {
            num = screens.length;
            now = 1;
        } else if (lastNow == screens.length) {
            now = screens.length;
            num = Number(lastNow)-Number(1);
        }
        else {
            now = lastNow;
            num = Number(lastNow)-Number(1);
        }
        lastNow = num;
        next = num+1;
        $("#screensBlock"+now+"").animate({
            opacity: "hide"
        }, 500);
        $("#screensBlock"+num+"").animate({
            opacity: "show"
        }, 500);
        updates(num);
    });

    $(".avancaLancs").click(function(){
        clearTimeout(t);
        screens = $(".screensB");
        if (lastNow == screens.length) {
            num = 1;
            now = screens.length;
        } else {
            now = lastNow;
            num = Number(lastNow)+Number(1);
            
        }
        lastNow = num;
        $("#screensBlock"+now+"").animate({
            opacity: "hide"
        }, 500);
        $("#screensBlock"+num+"").animate({
            opacity: "show"
        }, 500);
        updates(num);
    });

    $(".lastUpdatesA").hover(function() {
        var title = $(this).attr("rel");
        $("#balaoTip").text(title);
        $("#balaoTip").show();
    },
    function() {
        $("#balaoTip").hide();
    });

    $("#assunto").change(function() {
        if ($(this).val() == "Recrutamento") {
            $("#recrutamentoDiv").slideDown();
        } else {
            $("#recrutamentoDiv").slideUp();
        }
    });

    $(".icones").hover(function() {
        var title = $(this).attr("rel");
        $("#balaoTip").text(title);
        $("#balaoTip").show();
    },
    function() {
        $("#balaoTip").hide();
    });

    $(".icones").mousemove(function(e){
        $('#balaoTip').css('top', e.pageY+10).css('left', e.pageX+10);
    });

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $(".projetoImg").click(function() {
        projeto = $(this).prev("#projetoImagem");
        if (projeto.css('display') == 'none') {
            $(this).prev("#projetoImagem").animate({
                opacity: "show",
                height: "toggle"
            }, 500);
        } else {
            $(this).prev("#projetoImagem").animate({
                opacity: "hide",
                height: "toggle"
            }, 700);
        }
    });
    
    $(".calendario").click(function() {
        projeto = $("#calendario");
        if (projeto.css('display') == 'none') {
            projeto.animate({
                opacity: "show",
                height: "toggle"
            }, 500);
        } else {
            projeto.animate({
                opacity: "hide",
                height: "toggle"
            }, 700);
        }
    });

    $(".mostraLayer").click(function() {
        layer = $(this).attr('rel');
        $("#"+layer+"").animate({
            opacity: "show",
            height: "toggle"
        }, 500);
        $("#ajaxFundo").show();
    });

    $(".cenClose").click(function() {
        layer = $(this).attr('rel');
        $("#"+layer+"").animate({
            opacity: "hide",
            height: "toggle"
        }, 700);
        $("#ajaxFundo").hide();
    });

    $("ul#projetosTabs li a").click(function() {
        id = $(this).attr('rel');
        tabsOff($("#"+id+"_episodios"));
        tabsOff($("#"+id+"_filmes"));
        tabsOff($("#"+id+"_ovas"));
        tabsOff($("#"+id+"_musicas"));
        $("#div_"+id+"_episodios").hide();
        $("#div_"+id+"_filmes").hide();
        $("#div_"+id+"_ovas").hide();
        $("#div_"+id+"_musicas").hide();
        $("#div_"+$(this).attr('id')+"").show();
        tabsOn($(this));
    });
    
    $(".projetoSinopse").click(function() {
        projeto = $(this).prev("#projetoSinopse");
        if (projeto.css('display') == 'none') {
            $(this).prev("#projetoSinopse").animate({
                opacity: "show",
                height: "toggle"
            }, 500);
        } else {
            $(this).prev("#projetoSinopse").animate({
                opacity: "hide",
                height: "toggle"
            }, 700);
        }
    });

    $(".imgProjeto").click(function() {
        $(this).closest('div').animate({
            opacity: "hide"
        }, 700);
    })

    $('#ajaxFundo').css('height','100%');
    
    $('.ajaxLoad').click(function(){
        pagina = $(this).attr('rel');
        $('#ajaxLoad').show();
        $('#ajaxFundo').show();
        $('#ajaxConte').show();
        $('#ajax').empty().load(pagina);
    });

    $('.ajax1').click(function(){
        $('#ajaxFundo').hide();
        $('#ajaxConte').hide();
        $('#ajax').empty();
    });

    $("#ajaxLoad").hide();

    $('#ajaxLoad').ajaxStart(function(){
        $('#ajaxLoad').show();
        $('#ajax').hide();
    });

    $('#ajaxLoad').ajaxStop(function(){
        $('#ajaxLoad').hide();
        $('#ajax').show();
        lines();
    });

    if ($('#adsOverlay').css('display') == 'block') {
        altura = $('#container').height();
        largura = $('body').width();
        $('#adsOverlay').height(altura+80);
        $('#adsOverlay').width(largura);
        contador(1, 15);
    }

    DD_roundies.addRule('#buttonTopo', '8px');
    DD_roundies.addRule('#buttonDown', '10px');
    DD_roundies.addRule('#menuTitle', '10px');
    DD_roundies.addRule('#atualizacao', '8px');
    DD_roundies.addRule('#menuContent', '0px 0px 7px 7px');
    DD_roundies.addRule('#menuOut', '0px 0px 7px 7px');
    DD_roundies.addRule('.roundTitle', '5px 5px 0px 0px');
    DD_roundies.addRule('.roundDown', '10px 10px 0px 0px');
    DD_roundies.addRule('#boxTitle', '10px');
    DD_roundies.addRule('#boxOut', '0px 0px 7px 7px');
    DD_roundies.addRule('#boxContent', '0px 0px 7px 7px');
    DD_roundies.addRule('#downBox', '10px');
    DD_roundies.addRule('#downInfo', '10px');
    DD_roundies.addRule('#projetoImagem', '0px 17px 0px 17px');
    DD_roundies.addRule('#projetoBoxInfos', '10px');
    DD_roundies.addRule('#loginForm', '20px');
    DD_roundies.addRule('.login', '10px');
    DD_roundies.addRule('#ultimasNoticias', '8px');
    DD_roundies.addRule('#lastColums', '8px');
    DD_roundies.addRule('#atuScreen', '8px');
    DD_roundies.addRule('#ultimosLancamentos', '8px');

    lastUpdate(0);
    updates(1);
    
});

function lastUpdate(num) {
    var imagens = document.getElementsByTagName('img');
    var screens = Array();
    for (i=0; i<imagens.length; i++) {
        if(imagens[i].className == "lastScreen") {
            screens.push(imagens[i]);
        }
    }
    for (i=0; i<screens.length; i++) {
        if (i == num) {
            if (i == screens.length-1) {
                next = 0;
            } else {
                next = parseInt(i+1);
            }
            prev = (i-1);
            if (prev < 0) {
                prev = (screens.length-1);
            }
            $(screens[i]).fadeIn('300');
            text = '<a href="'+$(screens[i]).attr('rel')+'" title="'+$(screens[i]).attr('title')+'">'+$(screens[i]).attr('alt')+'</a>';
            $('#lastNome').html(text);
            $('#voltar').html('<a href="#lastVoltar" rel="'+prev+'"><</a>');
            $('#avancar').html('<a href="#lastAvancar" rel="'+next+'">></a>');
            t=setTimeout('lastUpdate('+next+');', '5000');
        } else {
            $(screens[i]).css('display','none');
        }
    }
}

var t;
var lastNow;

function updates(num) {
    screens = $(".screensB");
    if (num > screens.length) {
        next = 1;
        now = parseInt(num-1);
        num = 1;
    } else {
        next = parseInt(num+1);
        now = parseInt(num-1);
    }
    lastNow = num;
    $("#screensBlock"+now+"").animate({
        opacity: "hide"
    }, 500);
    $("#screensBlock"+num+"").animate({
        opacity: "show"
    }, 500);
    $("#ultimosLancsTitle").html("Ultimos lançamentos no site Clique e acesse painel&nbsp;"+num+"");
    t=setTimeout("updates("+next+");", 8000);
}

function openNext(p) {
    var obj = $(p).next();
    if (obj.css('display') == 'none') {
        obj.slideDown();
    } else {
        obj.slideUp();
    }
}

function fechaBalao() {
    $("#balaoTip").hide();
}

function lines() {
    var elementos = document.getElementsByTagName('*');
    for (i=0; i<elementos.length; i++) {
        if(elementos[i].id == "line" || elementos[i].id == "line2") {
            altura = elementos[i-1].clientHeight;
            largura = elementos[i-1].style.width;
            elementos[i].style.height=((altura/2)+2);
            elementos[i].style.width=largura;
        }
    }
    DD_roundies.addRule('#downBox', '10px');
    DD_roundies.addRule('#downInfo', '10px');
    DD_roundies.addRule('#downloadLinks', '10px');
    DD_roundies.addRule('#downlist', '10px');
    DD_roundies.addRule('#buttonDown', '10px');
    DD_roundies.addRule('.roundDown', '10px 10px 0px 0px');
}

function ajax(x) {
    $('#ajaxLoad').show();
    $('#ajaxFundo').show();
    $('#ajaxConte').show();
    $('#ajax').empty().load(x);
}

function contador(x, y) {
    if (x < y) {
        z = y-x;
        document.getElementById("contador").innerHTML='Faltam '+z+' Segundos.';
        t=setTimeout('contador('+parseInt(x+1)+', '+y+');', 1000);
    } else {
        document.getElementById("adsOverlay").style.display='none';
        document.getElementById("dlAds").style.display='none';
    }
}

function versoes(id, versao) {
    var versoes = new Array("FullHD", "HD", "SD", "MP4", "SLQ", "RMVB");
    for(i=0; i<versoes.length; i++){
        ver = versoes[i];
        div = document.getElementById(""+id+"_"+ver+"");
        if (div != null) {
            div.style.display='none';
        }
    }
    document.getElementById(""+id+"_"+versao+"").style.display='block';
}

function resposta(id) {
    document.commentForm.resposta.value=id;
}

function addComment(){
    comentado = document.getElementById("comentado");
    if (comentado.value == 0) {
        campos = document.forms.commentForm.elements.length
        vazio = 0;
        for(var j=0; j<campos; j++) {
            var elemento = document.forms.commentForm.elements[j];
            if (elemento.value=="") {
                elemento.style.border='1px solid #FFA500';
                alert('Campo "'+elemento.name+'" vazio!\nPreencha todos os campos!');
                vazio = 1;
                return false;
            } else {
                elemento.style.border='1px solid #1A1A1A';
                elemento.style.background='#343434';
            }
        }
        if (vazio == 0) {
            p=setTimeout("document.getElementById('comentado').value=1", 5000);
            //alert('Seu comentário foi enviado com sucesso e está sujeito a aprovação.');
            t=setTimeout("document.getElementById('comentado').value=0", 30000);
        }
    } else {
        alert('Espere 30 segundos para comentar novamente.');
        return false;
    }
}

function tabsOn(tab) {
    $(tab).css('background','#3B3B3B');
    $(tab).css('borderBottom','0px');
    $(tab).css('marginTop','1px');
}

function tabsOff(tab) {
    $(tab).css('background','#1e1e1e');
    $(tab).css('borderBottom','1px');
    $(tab).css('marginTop','0px');
}

function validaNick(f) {
    f.value = f.value.replace(/[^a-z\u00D1\u00F10-9]*/ig,'');
}
