//"use strict";
var disableTopbar, jQuery, $; // outer globals

function loadScript(url, completeCallback) {
    if (!completeCallback) {
        completeCallback = function () {};
    }
    var head = document.getElementsByTagName("head")[0],
        done = false,
        script = document.createElement("script");

    script.src = url;
    script.onload = script.onreadystatechange = function () {
        if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
            done = true;
            completeCallback();

            // IE memory leak
            script.onload = script.onreadystatechange = null;
            head.removeChild(script);
        }
    };
    head.appendChild(script);
}

function loadJquery(completeCallback) {
    if (!completeCallback) {
        completeCallback = function () {};
    }
    if (typeof(jQuery) === "undefined") {
        if (typeof($) === "undefined") {
            loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", completeCallback);
        } else {
            loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", function () {
                jQuery.noConflict();
                completeCallback();
            });
        }
    } else {
        if (/^1\.(0|1|2)/.test(jQuery.fn.jquery)) {
            alert("Idlesoft's Global script doesn't function with jQuery < 1.3");
        } else {
            completeCallback();
        }
    }
}


loadJquery(function () {
    if (typeof(disableTopbar) === "undefined" || !disableTopbar) {
        loadScript("http://styles.idlesoft.net/isn4/scripts/topbar.js");
    }
});
