var GzipLoader = {
	settings : {
		disk_cache : true,
		path : '',
		debug : false,
		page_name: ''
	},

	init : function(s) {
		var n, d = document, nl, i, b = '', sr, db;
		
		this.isIE = (navigator.appName == "Microsoft Internet Explorer");
		this.isOpera = navigator.userAgent.indexOf('Opera') != -1;

		for (n in s)
			this.settings[n] = s[n];

		for (i=0, nl = d.getElementsByTagName('base'); i<nl.length; i++) {
			if (nl[i].href)
				b = nl[i].href;
		}

		db = document.location.href;

		if (db.indexOf('?') != -1)
			db = db.substring(0, db.indexOf('?'));

		db = db.substring(0, db.lastIndexOf('/'));

		if (b.indexOf('://') == -1 && b.charAt(0) != '/')
			b = db + "/" + b;

		this.baseURL = b + '/';
		this.load(this.settings.page_name);
	},

	load : function(v) {
		var s = this.settings, h, d = document, sp2;

		v += '&js=true';
		v += '&diskcache=' + (s.disk_cache ? 'true' : 'false');
		this.loadFile(s.path+ v);
	},

	checkCompress : function() {
		var sp2, ver, na = navigator, ua = navigator.userAgent;

		// Non IE browsers are fine
		if (!this.isIE)
			return 1;

		sp2 = na.appMinorVersion.indexOf('SP2') != -1;
		ver = parseFloat(ua.match(/MSIE\s+([0-9\.]+)/)[1]);

		// IE 6.0+ with SP2 seems fine
		if (ver >= 6 && sp2)
			return 1;

		// IE 7.0+ seems fine
		if (ver >= 7)
			return 1;

		// All others might fail
		return 0;
	},

	loadFile : function(u) {
		var x, ex;

		if (this.settings['debug'])
			alert('JS: ' + u);

		if (this.isIE) {
			// Synchronous AJAX load gzip JS file
			try {
				x = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (ex) {
				x = new ActiveXObject("Msxml2.XMLHTTP");
			}

			x.open("GET", u.replace(/%2C/g, ','), false);
			x.send(null);

			this.scriptData = x.responseText;

			document.write('<script type="text/javascript">eval(GzipLoader.scriptData);</script>');
		} else
			document.write('<script type="text/javascript" src="' + u + '"></script>');
	}
};
