var Browser = {
	initialize: function(){
		if (!document.getElementById || !document.createElement)
			return this.supported = false;
		
		Browser.debug = Browser.debug || true;
		
		if (location.search.indexOf('debug') > -1)
			Browser.debug = true;
		
		if (location.search.indexOf('force') > -1)
			return this.supported = true;
		
		this.supported   = true; // optimistic, sort of...
		this.scriptsPath = '/scripts/';
		this.stylesPath  = '/styles/';
		
		this.UA = navigator.userAgent;
		this.AV = navigator.appVersion;
		
		this.mac   = (this.AV.indexOf('Macintosh') >= 0);
		this.win   = (this.AV.indexOf('Windows') >= 0);
		this.linux = (this.AV.indexOf('X11') >= 0);
		
		this.opera     = (window.opera) ? true : false;
		this.ie        = (document.all && !this.opera) || false;
		this.safari    = (this.AV.indexOf('Safari') >= 0);
		this.konqueror = (this.AV.indexOf('Konqueror') >= 0);
		this.khtml     = this.safari || this.konqueror;
		
		var geckoPos = this.UA.indexOf('Gecko');
		this.mozilla = (geckoPos >= 0 && !this.khtml);
		
		//Check versions
		if (this.mozilla)
			this.geckoVersion = this.UA.substring(geckoPos + 6, geckoPos + 14);
		else if (this.safari)
			this.version = parseFloat(/[\d\.]+$/g.exec(this.UA));
		else if (this.ie)
			this.version = parseFloat(/MSIE\s([\d\.]+)/g.exec(this.UA)[1]);
		else if (this.opera)
			this.version = parseFloat(/^[\d\.]+/g.exec(this.AV));
		
		//Check support
		if (this.mac && this.ie)
			this.supported = false;
		else if (this.ie && this.version < 6)
			this.supported = false;
		else if (this.safari && this.version < 312)
			this.supported = false;
		else if (this.opera)
			this.supported = false;
		
		return this.supported;
	},
	
	require: function(name) {
		document.write('<script type="text/javascript" src="'+this.scriptsPath+((Browser.debug)?'source/':'')+name+'.js"><'+'/script>');
	},
	
	includeStyles: function(name, media) {
		media = media || 'screen';
		document.write('<style type="text/css" media="'+media+'">@import "'+this.stylesPath+name+'.css";<'+'/style>');
	}
};

if (Browser.initialize()) {
	var links = document.getElementsByTagName('link');
	for (var h=0; h<links.length; h++)
		if (links[h].getAttribute('title') == 'minimal')
			links[h].disabled = true;
	
	var files = [];	
	if (Browser.debug)
		files =  ['lib/jquery',
							'lib/jquery/bgIframe',
							//'lib/jquery/cookie',
							//'lib/jquery/datepicker',
							'lib/jquery/deserialize',
							'lib/jquery/dimensions',
							'lib/jquery/dombuilder',
							'lib/jquery/mousewheel',
							'lib/jquery/offset',
							//'lib/jquery/scrollwindow',
							//'lib/slideShow',
							'lib/ufo',
							'Interface',
							'Interface/Globals',
							//'Interface/Brands',
							'Interface/Nav',
							//'Interface/Promotions',
							//'Interface/Footer',
							'../config',
							'application'];
	else
		files = ['application', 'config'];
	
	for (var h=0; h<files.length; h++)
		Browser.require(files[h]);
	
	var scriptTags = document.getElementsByTagName('script');
	for (var i=0; i<scriptTags.length; i++) {
		var scriptTag = scriptTags[i];
		if (scriptTag.src && scriptTag.src.indexOf('bootstrap.js')) {
			var scripts = scriptTag.getAttribute('scripts');
			if (scripts) scripts = scripts.split(' ');
			if (scripts && scripts.length > 0) {
				for (var j=0; j<scripts.length; j++) {
					var script = scripts[j];
					if (script.indexOf('-ie6') != -1) {
						if (Browser.ie && parseInt(Browser.version) == 6)
							Browser.require(script);
					} else {
						Browser.require(script);
					}
				}
			}
			Browser.includeStyles('print', 'print');
			var styles = scriptTag.getAttribute('styles');
			if (styles) styles = styles.split(' ');
			if (styles && styles.length > 0) {
				for (var k=0; k<styles.length; k++) {
					var style = styles[k].split('|');
					if (style[0].indexOf('-ie6') != -1) {
						if (Browser.ie && parseInt(Browser.version) == 6)
							Browser.includeStyles(style[0],style[1]);
					} else {
						Browser.includeStyles(style[0],style[1]);
					}
				}
			}
			break;
		}
	}
}