if (typeof GS == 'undefined') { var GS = {}; }
(function(){

	var UID = 0;

	GS.noop = function(){};

	GS.getUniqueId = function(prefix) {
		UID++;
		return (prefix + '' + UID);
	};

	if (typeof console != 'undefined') {
		var cm = function(x) {return function(){try{if(console[x]) console[x].apply(console, arguments);} catch (e) {}}};
		GS.dir = console.dir ? cm('dir') : GS.noop;
		GS.log = console.log ? cm('log') : GS.noop;
		GS.warn = console.warn ? cm('warn') : GS.log;
		GS.error = console.error ? cm('error') : GS.warn;
	} else {
		GS.dir = GS.log = GS.warn = GS.error = GS.noop;
	}

	// setup the extender library
	GS.extend = function($namespace, $def) {
		//
		var namespace = $namespace.split('.');
		// take the GS object
		var a = GS, end = namespace.length - 1;

		if (end > 0) {
			// take the last item off of the end of the array
			namespace.slice(0, end);
			// now go through the namespace
			for (var i = 0, length = end; i < length; i++) {
				// is this namespace already there?
				if (typeof(a[namespace[i]]) == 'undefined') {
					// are we at the end of the namespace?
					//var b = ( ( i + 1 ) == length && typeof($def) != 'undefined' ) ? $def : {};
					// setup the namespace
					a[namespace[i]] = {};
				}
				// now tick on
				a = a[namespace[i]];
			}
		}
		// now set the definition
		a[namespace[end]] = ( typeof($def) == 'undefined' ) ? {} : $def;
	};

	//
	GS.extend('_require', {

		init : function() {
			window.onload = function() {
				GS._require._loaded = true;
			};
		},

		add : function($dependancies) {
			if (GS._require._loaded) {
				GS.log('Depedancies cannot be loaded as the DOM has already fully loaded.');
			} else {
				if (GS._require._jq_mode) {
					var urls = [];
				}
				for (var i = 0, length = $dependancies.length; i < length; i++) {
					var dependancy = $dependancies[i];
					if (!GS._require.isAdded(dependancy)) {
						if (dependancy == 'jquery' && typeof(jQuery) != 'undefined') {
							//alert('jQuery');
						} else {
							var url = GS._require.getURL(dependancy);
							if (url) {
								document.write('<scr'+'ipt type="text/javascript" src="' + url + '"></scr'+'ipt>');
							}
							/*if (dependancy == 'jquery' && GS._require._jq_compat) {
								document.write('<scr'+'ipt type="text/javascript">$jq=jQuery;$jq.noConflict();</scr'+'ipt>');
							}*/
						}
						GS._require._added.push(dependancy);
					}
				}
			}
		},

		getURL : function($name) {
			if (typeof $name == 'string') {
				if ($name.indexOf('http://') == 0 || $name.indexOf('https://') == 0) {
					return $name;
				} else {
					// does it need the css library? TODO: general CSS map
					if ($name == 'jquery-ui' && !GS._require._css.jqui && GS._require._jq_compat) {
						document.write('<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />');
						//document.write('<link rel="stylesheet" type="text/css" href="' + GS.MEDIA_URL + 'styles/jquery-ui/jquery-ui.css" />');
						GS._require._css['jqui'] = true;
					} else if ($name.indexOf('ui.') && !GS._require._css.gsui) {
						document.write('<link rel="stylesheet" type="text/css" href="' + GS.MEDIA_URL + 'styles/gs-ui-components.css?' + GS.CSS_VERSION + '" />');
						GS._require._css['gsui'] = true;
					}
					// is this url mapped?
					if (typeof(GS._require._maps[$name]) != 'undefined') {
						return GS._require._maps[$name];
					}
					// return the url
					return GS.MEDIA_URL + 'js/neu/' + $name + '.js?'+GS.CSS_VERSION;
				}
			}
			return false;
		},

		isAdded : function($dependancy) {
			for (var i = 0, length = GS._require._added.length; i < length; i++) {
				if (GS._require._added[i] == $dependancy) {
					return true;
				}
			}
			return false;
		},

		_maps : {
			'jquery': 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js',
			'jquery-ui': 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js'
		},
		_css : {},
		_added : [],
		_loaded : false,
		_jq_compat : false

	});

	// setup the require library
	GS.extend('require', function($dependancies) {
		GS._require.add($dependancies);
	});

	GS._require.init();
})();

GS.extend('MEDIA_URL', 'http://media.groupspaces.com/');
GS.extend('CSS_VERSION', '1329913851');
// setup the localisation
GS.extend('l10n');
GS.extend('l18n');
GS.extend('isGroup', function() { return ( typeof GS.Group == 'undefined' ) ? false : true; });
// shhh
GS.require(['jquery','gs.gate','gs.konami']);
// using new modal, need this on every page now
GS.require(['gs.modal_instance']);

