$(document).ready(function(){
    $('#next').click(function() {
        next();
    });
    
    $('#prev').click(function() {
        prev();        
    });

    function next() {
        Aobj = $('#rct-categories').children();
        Aprimeiro = $(Aobj[0]);

        Obj = $('.show');
        Obj.fadeOut('slow');
        $(Obj.children('.hidden-top')).animate({"top": "-=90px"}, "slow");
        $(Obj.children('.hidden-left')).animate({"left": "-=100px"}, "slow");

        if($('.show').next().html() != null){  
            Obj.removeClass('show');
            Obj.next().fadeIn('slow');
            Obj.next().addClass('show');

            $(Obj.next().children('.hidden-top')).animate({"top": "+=90px"}, "slow");
            $(Obj.next().children('.hidden-left')).animate({"left": "+=100px"}, "slow");

        }else{
            Obj.removeClass('show');
            Aprimeiro.fadeIn('slow');
            Aprimeiro.addClass('show');

            $(Aprimeiro.children('.hidden-top')).animate({"top": "+=90px"}, "slow");
            $(Aprimeiro.children('.hidden-left')).animate({"left": "+=100px"}, "slow");
        }

        window.clearTimeout($('#timeout-id').val());
        var timeoutId = window.setTimeout(next, 10000);
        $('#timeout-id').val(timeoutId);
    }
    /**
     * Comment
     */
    function prev() {
        Aobj = $('#rct-categories').children();
        Aultimo = $(Aobj[Aobj.length-1]);

        Obj = $('.show');
        Obj.fadeOut('slow');
        $(Obj.children('.hidden-top')).animate({"top": "-=90px"}, "slow");
        $(Obj.children('.hidden-left')).animate({"left": "-=100px"}, "slow");

        if($('.show').prev().html() != null){   
            Obj.removeClass('show');
            Obj.prev().fadeIn("slow");
            Obj.prev().addClass('show');

            $(Obj.prev().children('.hidden-top')).animate({"top": "+=90px"}, "slow");
            $(Obj.prev().children('.hidden-left')).animate({"left": "+=100px"}, "slow");
        }else{
            Obj.removeClass('show');
            Aultimo.fadeIn("slow");
            Aultimo.addClass('show');

            $(Aultimo.children('.hidden-top')).animate({"top": "+=90px"}, "slow");
            $(Aultimo.children('.hidden-left')).animate({"left": "+=100px"}, "slow");
        }
        window.clearTimeout($('#timeout-id').val());
        var timeoutId = window.setTimeout(next, 10000);
        $('#timeout-id').val(timeoutId);
    }
    $($('.show').children('.hidden-top')).animate({"top": "+=90px"}, "slow");
    $($('.show').children('.hidden-left')).animate({"left": "+=100px"}, "slow");
    $('.mostra').fadeIn(2500);
    $('.mostra').css("width", "710px");
    $('.mostra').css("height","260px");
    $('.mostra').animate({"height": "+=100px", "width":"+=250px"}, 20000);
    $('.mostra').animate({"height": "-=50px", "width":"-=125px"}, 10000);
    $('.mostra-bn').fadeIn(1500);
    
    var timeoutId = window.setTimeout(next, 10000);
    window.setTimeout(topo, 10000);
    window.setTimeout(banner, 8000);
    
    $('#timeout-id').val(timeoutId);
   
   /*Chamada Comentada para desabilitar área de Login*/
   //$('#login').ajaxForm({dataType: 'script'});
   // login_func('off');
    
});

function login_func(type) {
    if(type == 'login'){
        $('#fn').val('login');
        $('#p1').val($('#lg_usuario').val());
        $('#p2').val($('#lg_pass').val());
        $('#login').submit();
        return true;
    }
    
    if(type == 'off'){
        $('#fn').val('toggleOff');
    }else{
        $('#fn').val('toggleOn');
        
    }
    
    $('#p1').val($('.login-topo').css('height'));
    $('#login').submit();
    return true;
}

function test() {
    $('#lbl-cli').fadeIn('slow');
    if($('#tbl-cli').html() != null){
        $('#tbl-cli').fadeIn('slow');
    }
}
function setHeight(size, height) {
    var original = (height.split('px'));
    var dif = (size - original[0]*1);

    $('.login-topo').animate({'height': '+='+dif+'px'}, 'slow');

}


function banner(){
    var oObj = $('#'+$('.mostra-bn').attr('id'));
    oObj.fadeOut(1500);
    oObj.removeClass('mostra-bn');
    
    var oObjNext = oObj.next('img');
    if(oObjNext.attr('id') == null){
        oObjNext = $("#lnk-aut img:first-child");
    }
    oObjNext.fadeIn(1500);
    oObjNext.addClass('mostra-bn');
    
    window.setTimeout(banner, 8000);
    
}

function topo(){
    var oObj = $('#'+$('.mostra').attr('id'));
    oObj.fadeOut(2500);
    
    oObj.removeClass('mostra');
    
    var oObjNext = oObj.next('img');
    if(oObjNext.hasClass('back-bottom')){
        oObjNext = $('#tp-logo1');
    }
    
    oObjNext.fadeIn(2500);
    oObjNext.animate({"height": "+=100px", "width":"+=250px"}, 20000);
    oObjNext.animate({"height": "-=50px", "width":"-=125px"}, 10000);
    window.setTimeout(resize, 30000, [oObj.attr('id')]);
    
    
    
    oObjNext.addClass('mostra');
    
    window.setTimeout(topo, 30000);
    
}
function resize(id){
    $('#'+id).css("width", "710px");
    $('#'+id).css("height","260px");
}

function showSubmenu(codsecao, url){
    
    if($('.down').attr('id') != null){
        $('.down').slideUp("slow", function () {
            if($('.tr-'+codsecao).hasClass('down') == true){
                $(this).removeClass('down');
            }else{
                $(this).removeClass('down');
                $('.tr-'+codsecao).slideDown('slow', function() {
                    location.href=url;
                });
                $('.tr-'+codsecao).addClass('down');
            }
        });
        if($('#td-'+codsecao).hasClass('selected-menu')){
            $('#td-'+codsecao).removeClass('selected-menu');
            $('#td-'+codsecao+' a').css('color','#FFF');
        }else{
            $('.selected-menu a').css('color','#FFF');
            $('.selected-menu').removeClass('selected-menu');
            $('#td-'+codsecao).addClass('selected-menu');
            $('#td-'+codsecao+' a').css('color','#CDAC54');
        }
        

    }else{                       
        $('.tr-'+codsecao).slideDown('slow', function() {
            location.href=url;
        });
        $('.tr-'+codsecao).addClass('down');
        $('#td-'+codsecao).addClass('selected-menu');
        $('#td-'+codsecao+' a').css('color','#CDAC54');
        
    }
    
}

