function Ajax() {
	this.failed = false;
	this.xmlhttp = null;
	this.method = 'GET';
	this.URLString = null;
	this.timer = null;
	this.nocache = 0;

	this.resetFunction();
}

Ajax.prototype = {
	resetFunction: function() {
		this.onloading = function() { return false; };
		this.onsuccess = function() { return false; };
		this.createAJAX();
	},

	createAJAX: function() {
		this.failed = false;
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}
		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	},

	timerRequest: function(file, time, options) {
		var _this = this;
		this.timer = setInterval(function() { _this.request(file, options); }, time);
	},

	stopTimer: function() {
		clearInterval(this.timer);
	},

	request: function(file, options) {
		if(options) {
			this.onsuccess = options.onsuccess || this.onsuccess;
			this.method = options.method || this.method;
			this.nocache = options.nocache || this.nocache;
		}
		if(!this.failed) {
			if (this.xmlhttp) {
				var self = this;
				if (this.nocache) file += ((file.indexOf('?')==-1)?'?':'&')+"rnd=" + Math.random();
				if (this.method == "GET") {
					this.xmlhttp.open(this.method, file, true);
				} else {
					this.xmlhttp.open(this.method, file, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}
				
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
						case 2:
						case 3:
							self.onloading();
							break;
						case 4:
							self.failed = false;
							self.responseText = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.onsuccess(self.xmlhttp);
					}
				};
				this.failed = true;
				this.xmlhttp.send(this.URLString);
			}
		}

	}
};

var basepath = 'http://skoltz.com/';
