$(document).ready(function(){
    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].clientWidth;
            elementos[i].style.height=((altura/2)+2);
            elementos[i].style.width=largura;
        }
    }

    $("#sitebg").height("100%");
    $("#loading").hide();

    $('#loading').ajaxStart(function(){
        if (document.getElementById("buscaBuscador")) {
            var a = 1;
        } else {
            $('#load').hide();
            $('#loading').show();
        }
    });

    $('#loading').ajaxStop(function(){
        if (document.getElementById("buscaBuscador") && a == 1) {
            var a = 0;
        } else {
            $('#loading').hide();
            $('#load').show();
        }
    });

    $(".socimgs").hover(function() {
        $(this).animate({
            width: '48',
            height: '96'
        }, 300);
    },
    function() {
        $(this).animate({
            width: '45',
            height: '93'
        }, 300);
    });

    imgs = $("#listagem ul#lastUpdates").find('li');
    for(i=0; i<imgs.length; i++) {
        jQuery.preLoadImages($(imgs[i]).find('a').attr('rel'));
    }

    $("#listagem ul#lastUpdates li a").hover(function() {
        newImg = $(this).attr('rel');
        document.getElementById("lastImg").src=newImg;
    });


    $("#listagem ul li a").hover(function() {
        nTag = $(this).next();
        $(nTag).css('display', 'block');
    },
    function() {
        nTag = $(this).next();
        $(nTag).css('display', 'none');
    });

    $("#letra").data('ordem','c');
    $("#letra").data('ordenar','titulo');
    
    $(".ajax").click(function(){
        pagina = $(this).attr('rel');
        $('#load').empty().load(pagina);
    });

    $(".letraAjax").click(function(){
        pagina = $(this).attr('rel');
        orde = $("#letra").data('ordenar');
        ord = $("#letra").data('ordem');
        pagina += "/"+orde+"/"+ord+"";
        $('#load').empty().load(pagina);
    });

    $("tr#ultLancs").hover(function() {
        $(this).children().css('background','#F8F8F8');
        $(this).css('cursor','pointer');
    },
    function() {
        $(this).children().css('background','#FFFFFF');
    });

    DD_roundies.addRule('#mtButtons', '5px 5px 0px 0px');
    DD_roundies.addRule('#line', '5px 5px 0px 0px');

});

(function($) {
    var cache = [];
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery);

function openNext(p) {
    var obj = $(p).next();
    if (obj.css('display') == 'none') {
        obj.slideDown();
    } else {
        obj.slideUp();
    }
}

function ajax(x) {
    $('#load').empty().load(x);
}

function mudaLetra(l) {
    document.getElementById("letra").innerHTML=l;
}

function apagarLeitura(name) {
    days = -1;
    value = "";
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    document.cookie = name+"="+value+expires+"; path=/";
    document.getElementById(name).style.display='none';
}


function ordenar(o) {
    $("#letra").data('ordenar',o);
    ord = $("#letra").data('ordem');
    letra = document.getElementById("letra").innerHTML;
    document.getElementById("orde_titulo").style.fontWeight='normal';
    document.getElementById("orde_rank").style.fontWeight='normal';
    document.getElementById("orde_capitulos").style.fontWeight='normal';
    document.getElementById("orde_"+o+"").style.fontWeight='bold';
    ajax('http://www.punchmangas.com.br/lmangas/'+letra+'/'+o+'/'+ord+'');
}

function ordem(o) {
    $("#letra").data('ordem',o);
    ord = $("#letra").data('ordenar');
    letra = document.getElementById("letra").innerHTML;
    document.getElementById("ord_c").style.fontWeight='normal';
    document.getElementById("ord_d").style.fontWeight='normal';
    document.getElementById("ord_"+o+"").style.fontWeight='bold';
    ajax('http://www.punchmangas.com.br/lmangas/'+letra+'/'+ord+'/'+o+'');
}
