$(document).ready(function(){
    $('table.actions').hide();

    $('a.actionsExpand').click(function(){
        // Get the hidden table
        var actionsTable = $(this).parent().parent().children('table');

        // Toggle the view(hide/show)
        actionsTable.toggle();

        // Prevent the link follow the destination
        return false;
    });

    $('a.adjustPerm').click(function(){
        var actionRow = $(this).parent().parent();

        actionRow.children('td.allowed').text('Loading...');

        $.ajax({
            url: $(this).attr('href'),
            success: function(data){
                actionRow.children('td.allowed').empty();
                actionRow.children('td.allowed').html(data);
            }
        });

        // Prevent the link follow the destination
        return false;
    });

    if($.browser.msie){
        //$('div#brand').ifixpng();

        $('#menu li').mouseover(function(){
            $('#menu li ul').addClass('li-hover-ul');
        });

        $('#menu li').mouseout(function(){
            $('#menu li ul').removeClass('li-hover-ul');
        });
    }

    if($('.bite-download-timer').text() && $('.bite-download-timer').text() > 0){
        var timer = setInterval(function(){
            var second = $('.bite-download-timer').text();
            if(second > 0){
                second = second - 1;
                $('.bite-download-timer').text(second);
            }else{
                clearInterval(timer);
                var dId = $('.bite-download-timer').attr('title');

                $.ajax({
                    url: '/downloads/getchallenge/' + dId + '?' + new Date().getTime(),
                    success: function(data){
                        $('#challenge').html(data);
                    }
                });
            }

        }, 1000);
    }
});

