function whenDefined(name,callback,interval) {
    (function attempt() {
        if (typeof window[name] != "undefined") callback();
        else window.setTimeout(attempt,interval||10);
    })();
}

function loadScript(url,nocache) {
    window.setTimeout(function(){
        url += nocache ? "?nocache="+new Date().getTime() : "";
        var script = document.createElement('script');
        script.type = 'text/javascript'; script.src = url;
        document.getElementsByTagName('head')[0].appendChild(script);
    },0);
}

function loadCounters() {
    // Statcounter
    sc_project=2313298; sc_invisible=1; sc_partition=21; sc_security="2994b275"; sc_remove_link=1;
    loadScript("http://www.statcounter.com/counter/counter_xhtml.js");

    // Google Analytics
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    loadScript(gaJsHost + "google-analytics.com/ga.js");
    whenDefined("_gat",function(){
        var pageTracker = _gat._getTracker("UA-2009955-1");
        pageTracker._initData();
        pageTracker._trackPageview();
    })
}

function $(func) {
    loadScript("/js/jquery.js");
    whenDefined("jQuery",function() {
        if (document.body) {
            func();
        } else {
            $(func);
        }
    });
}

loadCounters();
