/* © 2010 kitGUI LLC. All Rights Reserved, patent pending */
(function (w,k) {
	var d = w.document,
	j = '1.6.1',
	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.onreadystatechange = function() {
				if (this.readyState === 'complete') {
					if (loaded) { loaded(); }
				} 
			};
		} 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);
	},
    init = function() {
	    var i = 0;
	    if (k.readyQueue) {
	        for (i = 0; i < k.readyQueue.length; i++) {
	            k.readyQueue[i](k.$);
	        }
	    }
		if (k.loggedin) {
			c('editor');
			s(a+'js/editor2',function(){});
		} else {
			c('login');
			s(a+'js/login2',function(){});
		}
	}
	k.loggedin=(d.cookie.indexOf('kitgui=1') > -1);
	k.showTab = 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);
