﻿/*global loader, YAHOO, document, window, catalog, getHeader, getFooter, ua */
ua = YAHOO.env.ua;

YAHOO.namespace("ROWWW.Catalog");
catalog = YAHOO.ROWWW.Catalog;

catalog.use_ajax = (ua.ie >= 6 || ua.opera >= 8 || ua.gecko >= 1.8 || ua.webkit >= 416);

if (catalog.use_ajax) {
    catalog.campus = function() {
        var re = /http:\/\/[\w.]+(?::\d+)?\/(Pullman|Spokane|Vancouver|Tri-Cities|DDP|General)\/?/i;
        if (re.test(window.location)) {
            return re.exec(window.location)[1];
        } else {
            return "General";
        }
    } ();

    // The following loop is required because ASP.NET changes Ids in the Master Page file.
    catalog.printCss = undefined;
    for (index = 0; index < document.styleSheets.length; index += 1) {
        if (document.styleSheets[index].href.match('print')) {
            catalog.printCss = document.styleSheets[index].ownerNode;
            break;
        }
    }

    // Null template keys load by default.
    catalog.TemplateKeys = {
        "Spokane": "1ia9bVzi010"
    };

    catalog.CSSGets = [];
    if (catalog.TemplateKeys[catalog.campus]) {
        catalog.CSSGets.push("http://designer.wsu.edu/template/css2.aspx?key=" + catalog.TemplateKeys[catalog.campus]);
    }

    YAHOO.util.Get.css(catalog.CSSGets,
        { insertBefore: catalog.printCss }
    );
}