﻿jQuery(function($) {
    var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
    
    if (IE6 || !$defined(__IsLoggedIn) || !__IsLoggedIn) {
        var tocElement = $("#tableOfContents");
        tocElement.css("position", "relative");
    }
    else {
        var pageTop = $(".pageTop").first();
        var topOffset = pageTop.offset().top + pageTop.outerHeight();
        DocumentView_position(topOffset);
        jQuery(window)
            .bind("scroll resize", { topOffset: topOffset }, function(e) {
                DocumentView_position(e.data.topOffset);
            });
    }

    // HACK: Adjusts the left margin of the breadcrumb document title element to be equal to the width of the breadcrumb document number element.
    var breadcrumb = $(".topBreadcrumb .documentView_aspx .title .num").first();
    if (breadcrumb != null) {
        var numWidth = breadcrumb.outerWidth();;
        $(".topBreadcrumb .documentView_aspx .title .text").first().css("margin-left", numWidth);
    }
});


function DocumentView_position(topOffset) {
    var tocElement = jQuery("#tableOfContents");
    var scrollTop = jQuery(window).scrollTop();
    var targetHeight = jQuery(window).height();
    var delta = topOffset - scrollTop;
        
    if (delta > 0) {
        targetHeight -= delta;
    }
    
    tocElement.css("height", targetHeight+"px");
}


function openBksDoc(docNumber) {
    var url = "DocumentView.aspx?sectionId=" + PortalSectionId;
    url += '&docNumber=' + docNumber;
    window.location = url;
}


function openExternalFile(attachmentId) {
    window.location = "Download.ashx?attachmentId=" + attachmentId;
}
