/* Keep footer at base. */
/* Ensure dynamic content and background image heights are set to ensure content height is correctly calculated in Chrome. */
function expandToView() {
    var expandAmount = 0; // the amount to push the footer down to
    var viewportHeight = $(window).height();
    var footerTop = $('div.footer_wrap').offset().top;
    var footerBottom = (footerTop + 40);
    if (footerBottom < viewportHeight) {
        expandAmount += (viewportHeight - footerBottom);
        var internalHeight = $('div.internal_content').height();
        $('body div.internal_content, body div.shadow_repeat').height(internalHeight + expandAmount);
        $('body#search div.shadow_repeat').css("background", "url(../images/backgrounds/shadow.png) no-repeat 1px -7px transparent");
        $('body#search div.wrapper div.content').css("background", "url(../images/backgrounds/bg_shadow_repeat.png) repeat-y center top transparent");
    }
}

function bookmark(title, url) {
  try {

    // Gecko or compatible
    if (window.sidebar) {
       window.sidebar.addPanel(title, url, "");
       return;
    }

    // Opera or compatible
    if (window.opera && window.print) {
       var anchor = document.createElement('a');
       anchor.setAttribute('href', url);
       anchor.setAttribute('title', title);
       anchor.setAttribute('rel', 'sidebar');
       anchor.click();
       return;
    }

    // Internet Explorer 4 or compatible
    if (document.all && (parseInt(navigator.appVersion, 10) >= 4)) {
       window.external.AddFavorite(url, title);
       return;
    }

  } catch (e) {
    // fall through
  }

  alert("To bookmark the current page press Ctrl-D" +
      "\n(Internet Explorer, Firefox, Safari and Chrome)" +
      "\nor Ctrl-T (Opera)");
}


$(document).ready(function () {

    $("a[rel='external']").each(function (i) {
        if (!this.target) {
            this.target = "_blank";
        }
        if (!this.title) {
            this.title = "the page will open in a new window";
        }
    });

    $("a[rel='pdf']").each(function (i) {
        if (!this.target) {
            this.target = "_blank";
        }
        if (!this.title) {
            this.title = "the PDF document will open in a new window";
        }
    });

//    $('div.news ul li.alt').hover(
//        function () {
//            $(this).css('background-image', 'url(../images/backgrounds/news_item_1_on.png)');
//        },
//        function () {
//            $(this).css('background-image', '');
//        }
//    );

//    $('div.news ul li:not(.alt,.read_all)').hover(
//        function () {
//            $(this).css('background-image', 'url(../images/misc/news_redbar.png)');
//        },
//        function () {
//            $(this).css('background-image', '');
//        }
//    );

    /* Push footer down if needed. */
//    if (typeof noExpandView == "undefined" || !noExpandView) {
//        expandToView();
//        $(window).resize(expandToView);
//    } 

    /* Font size switch. */
    $('a.small').click(function () {
        $('body').css('font-size', '60%');
        $('li.font_size a').css('text-decoration', 'none');
        $(this).css('text-decoration', 'underline');
    });

    $('a.medium').click(function () {
        $('body').css('font-size', '75%');
        $('li.font_size a').css('text-decoration', 'none');
        $(this).css('text-decoration', 'underline');
    });

    $('a.large').click(function () {
        $('body').css('font-size', '100%');
        $('li.font_size a').css('text-decoration', 'none');
        $(this).css('text-decoration', 'underline');
    });

    $('ul.left_nav li.sub a img:first').height(25);

});


function printPage() {
    window.print();
}

$(window).load(function () {
    $('ul.left_nav li:not(.current)').hover(
        function () {
            $(this).addClass('current');
            $(this).next("img:first").addClass('hide');

        },
        function () {
            $(this).removeClass("current");
            $(this).next("img:first").addClass('hide');
        }
    );
});

