Shadowbox.init({ skipSetup:true });

function changeTab(id){
    $('#content').animate({height:$(id).height()+40},500,function(){ $('#content').height('auto'); $(id).show(); });
    $('.tabbed:visible').fadeOut(200);
}

function openshadow(){
    url = $(this).attr('href'); title = $(this).attr('title') + '<a onclick="Shadowbox.close()" title="Cerrar" id="sb-nav-close-top"></a>';
    if (url.split('.').pop().toLowerCase() == 'pdf') url = 'ipdf.php?f='+url;

    Shadowbox.open({ content:url, player:"iframe", title:title, width:1200 });
    return false;
}

$(document).ready(function(){
    $('#tabs a').click(function(){
        changeTab('#c'+$(this).attr('href').split('/').pop());
        $('#tabs li').removeClass('current');
        $(this).parent().addClass('current');
        return false;
    });

    $('.subcat a').click(function(){
        cid = $(this).attr('href').split('/').pop();
        if ($('#c'+cid).length == 0){
            $('#loading').show();
            $.get($(this).attr('href')+'/ajax','',function(data){
                $('#content').append(data);
                $('#c'+cid).find('a.sbox').click(openshadow);
                changeTab('#c'+cid);
                $('#loading').hide();
            });
        } else changeTab('#c'+cid);
        return false;
    });

    $('#form_buscar').submit(function(){
        $('#loading').show();
        $.post($(this).attr('action')+'/ajax',{busqueda:$('#busqueda').val()},function(data){
            $('#resultados').html(data).find('a.sbox').click(openshadow);
            $('#loading').hide();
        });
       return false;
    });

    $('.cat_bread a').live('click',function(){ changeTab('#c'+$(this).attr('href').split('/').pop()); return false; });
});
