/* © 2010 kitGUI LLC. All Rights Reserved, patent pending */
(function (w, k) {
    var d = w.document,
	j = '1.6.2',
	a = 's3.amazonaws.com/kitgui/',
	s = function (_, loaded) {
	    var scr = d.createElement('script');
	    scr.type = 'text/javascript';
	    scr.src = '//' + _ + '.js';
	    if (navigator.userAgent.indexOf('MSIE') > -1) {
	        scr.onload = scr.onreadystatechange = function () {
	            if (this.readyState == "loaded" || this.readyState == "complete") {
	                if (loaded) { loaded(); }
	            }
	            scr.onload = scr.onreadystatechange = null;
	        };
	    } else {
	        scr.onload = loaded;
	    }
	    d.getElementsByTagName('head')[0].appendChild(scr);
	},
	c = function (_) {
	    var link = d.createElement('link');
	    link.type = 'text/css';
	    link.rel = 'stylesheet';
	    link.href = '//' + a + 'css/' + _ + '.css';
	    link.media = 'screen';
	    d.getElementsByTagName('head')[0].appendChild(link);
	};
    k.loggedin = (d.cookie.indexOf('kitgui=1') > -1);
    k.showTab = function () { };
    function init() {
        if (k.loggedin) {
            c('editor');
            s(a + 'js/editor2', function () { });
        } else {
            c('login');
            s(a + 'js/login2', function () { });
        }
    }
    if (!w.jQuery || w.jQuery.fn.jquery !== j) {
        var jq = null, $ = null;
        if (w.jQuery) { jq = w.jQuery; }
        if (w.$) { $ = w.$; }
        s('ajax.googleapis.com/ajax/libs/jquery/' + j + '/jquery.min', function () {
            k.$ = w.jQuery.noConflict(true);
            if (jq) { w.jQuery = jq; }
            if ($) { w.$ = $; }
            init();
        });
    } else {
        k.$ = w.jQuery;
        init();
    }
})(this, kitgui);
