var loaded = false;
$(document).ready(function() {
    if (!loaded) {
        $('.entry').click(function(event) {
            if (!$(event.target).is('a')) {
                window.location = $('h2 a', this).attr('href');
            }
        }).hover(function(event) {
            $(this).addClass('hover');
        }, function(event) {
            $(this).removeClass('hover');
        });

        $('label').each(function() {
            if (!$(this).next('select').size()) {
                $(this).overlabel();  
            }
        });

        var tagList = $('#tags li');
        var visibleTagMax = 5;
        tagList.slice(visibleTagMax).hide();
        if (tagList.size() > visibleTagMax) {
            $('#tags').after('<p id="show-all-tags">+ <a href="#">More...</a></p>');
            $('#show-all-tags a').click(function(event) {
                event.preventDefault();
                tagList.show();
                $(this).parents('p').hide();
            });
        }
        loaded = true;
    }

    // simple search "overlabel" (without the label)
    $('input.email-subscribe').focus(function() {
        if ($(this).val() == 'example@houseofradon.com') {
            $(this).val('');
        }
        $(this).addClass('focus');
    }).blur(function() {
        if ($(this).val() == '') {
            $(this).val('example@houseofradon.com');
        }
        $(this).removeClass('focus');
    }).blur();

    // hack
    $('a.rpxnow').click(function(event) {
        setTimeout(function() {
            var iframe = $('.rpxnow_lightbox iframe');
            var target = iframe.parent();
            target.prepend('<p style="margin: 0 20px; font-size: 13px; line-height: normal; padding-top: 120px;">Follow us to receive updates, music and exclusive news and footage.</p>');
        }, 300);
    });

    $('#trailer-navigation a').click(function(event) {
        event.preventDefault();
        $('#trailer-header li.active').removeClass('active');
        $('#trailer-header .trailer-video.active').removeClass('active');
        $($(this).attr('href')).addClass('active');
        $(this).parent().addClass('active');
    });

    $('.ppp-header .link .heading').click(function(event) {
        event.preventDefault();
        var active = $(this).parent().hasClass('active');
        $('.ppp-header .link.active .body').slideUp();
        $('.ppp-header .link.active').removeClass('active');
        if (!active) {
            $(this).parent().addClass('active');
            $(this).next().slideDown();
        }
    });

    $('#report-spam').click(function(event) {
        event.preventDefault();
        var comment = $(this).parents('.comment');
        if (confirm("Are you sure you want to report the comment as spam?")) {
            $.ajax({
                url: $(this).attr('href'),
                data: { comment_id: $(this).attr('data-comment-id') },
                type: 'post',
                success: function(r) {
                    comment.slideUp();
                }
            });
        }
    });
});

