$(document).ready(function() {

    // Tell css that the user has JS turned on
    $('body').addClass('hasJs');

    // Adjust height of sidebar
    setTimeout(function() {
        var contentHeight = $('.content').height();
        if (contentHeight < 500) {
            contentHeight = 500;
        }
        $('.content .aside_tall').css('height', contentHeight);
    }, 100);

    // Extra selectors (CSS3 support in IE is, let's say, inconsistent)
    $('.teasers .teaser:first-child').addClass('first-child');
    $('.teasers .teaser:last-child').addClass('last-child');
    $('.aside_inner.isolate+.aside_inner:not(.isolate)').prev().addClass('margin_down');
    $('.aside .aside_inner:first-child').addClass('first-child');

    // Table info bubbles
    $('.certified_sim').prepend('<div class="table_bubble" style="display: none;"><div class="top"></div><div class="content"><div class="title"></div><div class="description"></div></div><div class="bottom"></div></div>');
    $('.certified_sim th').each(function() {
        $(this).attr('rel', $(this).attr('title')).attr('title', '');
    });
    $('.certified_sim th').hover(function(e) {

        var bubblePos = $(this).position();
        $('.table_bubble').css({ left: bubblePos.left });
        $('.table_bubble').css({ top: (bubblePos.top - 30) });
        $('.table_bubble .title').text($(this).text());
        $('.table_bubble .description').text($(this).attr('rel'));

    }, function() {
    });
    $('table.certified_sim tr:first').hover(function() {
        $('.table_bubble').fadeIn(250);
    }, function() {
        $('.table_bubble').fadeOut(250);
    });

    // Feedback lightbox
    $('a[href^=/wac.aspx], a[href^=/sendfile.aspx], a[href=/question.aspx],a[href=/feedback.aspx]').click(function() {

        if ($('.white_light').size() == 0) {
            $('body').append('<div class="white_light"><div class="close"></div><iframe src="" frameborder="0"></iframe></div>');
        }
        var bodyOffset = $(document).scrollTop();
        $('.white_light').css('marginTop', bodyOffset + 100 + 'px');

        $('.white_light iframe').load(function() {
            $(this).attr('height', this.contentWindow.document.body.offsetHeight + 100 + 'px');
        });
        $('.white_light iframe').attr('src', $(this).attr('href'))

        $('.white_light .close, *:not(.white_light):not(a)').click(function() {
            
            $('.white_light').remove();
        });

        return false;

    });


});