
function focusCommentForm() {
    $('#formComment :input:not([type=hidden]):first').focus();
}

jQuery(document).ready(function() {

	
    /* scroll when clicking a link */
    $('a[href^=#]').live('click', function () {
        var match = $(this).attr('href').match('^#(.+)$');
        if (match) {
            var top = $('a[name=' + match[1] + ']').offset().top;
            var offset = $('#headlineWrapper').outerHeight();
            top -= offset;
            $.scrollTo(top >= 0 ? top : 0, 'slow');
        }
        return false;
    });

    $('.subNav').hide();
    $('#siteNav').mouseleave(function () {
        $('.subNav').hide();
    });
    $('[data-show-menu]').mouseover(function () {
        $('.subNav').hide();
        $('#' + $(this).attr('data-show-menu')).show();
    });

    if ($('#menuwrapper').length) {
        if ($('#menuwrapper').offset().top + $('#menuwrapper').height() > $(window).height()) {
            $('#menuwrapper').removeClass('fixed').addClass('scroll');
        }
    }

    if (new String(window.location).match(/#(postcomment|comments)$/)) {
        focusCommentForm();
    }

    if ($('.highlight-clicked').length) {
        $('.highlight-clicked a').click(function () {
            $(this).parents('.highlight-clicked').find('a').removeClass('highlight');
            $(this).addClass('highlight');
        });
    }

    /* Show overlay for current productions */
    $('body.current .itemGrid .relatedItem').hover(function () {
        var overlay = $(this).find('.itemOverlay');
        if (overlay.is(':animated')) {
            overlay.stop().fadeTo(250, 1);
        } else {
            overlay.fadeIn(250);
        }
    }, function () {
        var overlay = $(this).find('.itemOverlay');
        if (overlay.is(':animated')) {
            overlay.stop().fadeTo(1000, 0);
        } else {
            overlay.fadeOut(1000, 0);
        }
    });
    /* Show overlay for current productions if only information */
    $('body.current .itemGrid .relatedItem').hover(function () {
        var overlay = $(this).find('.itemOverlayInfo');
        if (overlay.is(':animated')) {
            overlay.stop().fadeTo(250, 1);
        } else {
            overlay.fadeIn(250);
        }
    }, function () {
        var overlay = $(this).find('.itemOverlayInfo');
        if (overlay.is(':animated')) {
            overlay.stop().fadeTo(1000, 0);
        } else {
            overlay.fadeOut(1000, 0);
        }
    });
});

