////////////////////////////////////////////////////////////////////////////////
// Overwrite stuff from opb_pre.js if necessary

(typeof cnPrimaryNavMenuManager != 'undefined') &&
    (cnPrimaryNavMenuManager.MENU_MAT_SRC = 'assets/images/spacer.gif');

////////////////////////////////////////////////////////////////////////////////
// Page load setup

jQuery(document).ready(function() {

    var closedNotes = { };
    try {
        var closedNotes = jQuery.secureEvalJSON(jQuery.cookies.get('closedNotes'));
    } catch (err) { };
    var cookieSettings = { hoursToLive: 24 * 365 * 5 };

    jQuery('#xls .note').each(function () {
        var noteID = this.id;
        if (!noteID || !closedNotes[noteID]) {
            jQuery(this).slideDown('fast');
        }
    });

    jQuery('#xls .note .close').click(function (e) {
        e.preventDefault();
        var note = jQuery(this).parent('.note').get(0);
        jQuery(note).slideUp('fast');
        if (note.id) {
            closedNotes[note.id] = 1;
            jQuery.cookies.set(
                'closedNotes',
                jQuery.compactJSON(closedNotes),
                cookieSettings
            );
        }
    });

    jQuery('input.clear_init').click(function (e) {
        var input = jQuery(this);
        if (input.hasClass('clear_init')) {
            input.val('');
            input.removeClass('clear_init');
        }
    });

    jQuery('.clickTrack').click(function (e) {
        // There are some things that we want to track that aren't pages on
        // which we can insert the tracking code (e.g. mailto links, PDFs).
        // So those links can be given the class name "clickTrack" plus an
        // ID specified in this hash. When clicked, the links will fire off
        // a request for the tracking JavaScript in addition to performing
        // their normal action. The tracking URL ID comes from the first
        // class name found on the link that exists in the hash.
        var clickTrackIDs = {
            factSheet:      'denxls_Factsheet_1',
            requestInfo:    'denxls_Requestmoreinformation_10',
            subscribeEmail: 'denxls_Subscribetoemailupdates_10'
        };
        var clickTrackStem = 'http://view.atdmt.com/jaction/';
        var linkClasses = jQuery(this).attr('class').split(/\s+/);
        for (var i = 0, len = linkClasses.length; i < len; i++) {
            var className = linkClasses[i];
            if (clickTrackIDs[className]) {
                jQuery.getScript(clickTrackStem + clickTrackIDs[className]);
                break;
            }
        }
    });

});

////////////////////////////////////////////////////////////////////////////////
// Our own functions, aliases, etc.

var XLS = {
    navMenuOn: function (li) {
        (typeof cnPrimaryNavMenuManager != 'undefined') &&
            cnPrimaryNavMenuManager.toggleMenu(li);
    },
    navMenuOff: function () {
        (typeof cnPrimaryNavMenuManager != 'undefined') &&
            cnPrimaryNavMenuManager.turnOffMenuNow(true);
    }
};
