/*
 * Requires JQuery
 * http://www.jquery.com
 */

$(document).ready(function() {
    initLightBox();
    initPopupLinks();
    initBlockQuotes();
    initLayout();
});

function initBlockQuotes() {
    var blockquotes = $('blockquote');
    
    $(blockquotes).each(function() {
        var quote = $(this).find('p:first');
        $(quote).addClass('quote');

        if (quote.length > 1) {
            var source = $(this).find('p:last');
            $(source).addClass('source');
        }

    });
    
}

function initLayout() {
    var footer_h = $('div#footer_container').height();
    var primary = $('div#content_primary');
    var primary_pad = ($(primary).height() <= 598) ? (616 - $(primary).height()) : 0;
    var secondary = $('div#content_secondary');
    var secondary_h = ($(secondary).height() <= 598) ? 616 : $(secondary).height();

    $(primary).css('padding-bottom', primary_pad);
    $(secondary).css('height', ($(window).height() - footer_h));

}

function initLightBox() {
    $('a.thickbox').lightBox();
}

function initPopupLinks() {
    var externals = $('a.external');
    var printables = $('a.printable');

    $(externals).click(function() {
        var target = $(this).attr('href');
        openPopupLink(target);
        
        return false;
    });
    
    $(printables).click(function() {
        var target = $(this).attr('href');
        openPrintableLink(target);
        
        return false;
    });
}

function openPopupLink(target) {
    var popup = window.open(target, '_blank');

    popup.focus();
}

function openPrintableLink(target) {
    var popup = window.open(target, '_blank', 'location=0, menubar=1, status=0, toolbar=0, width=600, height=480');

    popup.moveTo(0,0);
    popup.focus();
}

