Ajax.Queue = Class.create();
Object.extend(Object.extend(Ajax.Queue.prototype, Ajax.Request.prototype), {
	initialize : function(urls, _options, __options){
		this.urls = urls;
		this._options = _options;
		this.count = this.urls.length;
		this.__options = __options||{};
		this.transport = Ajax.getTransport();
		this.start();
	},
	start : function(){		
		var url = this.urls.shift();
		if (this._options instanceof Array){
			var options = this._options.shift();
		}else{
			var options = this._options;
		}
		this._complete = false;
		if(url){
			this.setOptions({
				onCreate : function(){
					if(this.urls.length==this.count-1&&this.__options.onCreate){
						this.__options.onCreate();
					}
					if(options.onCreate){
						options.onCreate();
					}
				}.bind(this),
				onComplete : function(transport, json){
					if(options.onComplete){
						options.onComplete(transport, json);
					}
					if(this.urls.length===0&&this.__options.onComplete){
						this.__options.onComplete(transport, json);
					}
					this.start();
				}.bind(this),
				onException : function(){
					if(options.onException){
						options.onException();
					}
				},
				onInteractive : function(){
					if(options.onInteractive){
						options.onInteractive();
					}
				},
				onLoaded : function(){
					if(options.onLoaded){
						options.onLoaded();
					}
				},
				onLoading : function(){
					if(options.onLoading){
						options.onLoading();
					}
				},
				onUninitialized : function(){
					if(options.onUninitialized){
						options.onUninitialized();
					}
				}
			});
			this.request(url);
		}
	}	
});

Client = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	height: function(){
		var windowHeight;
		if (self.innerHeight) {    // all except IE
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // IE 6 Strict Mode
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other IEs
			windowHeight = document.body.clientHeight;
		}
		return windowHeight;
	}, 	
	width: function(){
		var windowWidth;
		if (self.innerWidth) {    // all except IE
			windowWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientWidth) { // IE 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
		} else if (document.body) { // other IEs
			windowWidth = document.body.clientWidth;
		}
		return windowWidth;
	},
	scrollTop : function(){
		var y;
		if (self.pageYOffset){
			y = self.pageYOffset;
		}else if(document.documentElement && document.documentElement.scrollTop){
			y = document.documentElement.scrollTop;
		}else if (document.body){
			y = document.body.scrollTop;
		}
		return y;	
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
Client.init();

Viewport = {
	height: function(){
		var windowHeight;
		if (self.innerHeight) {    // all except IE
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // IE 6 Strict Mode
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other IEs
			windowHeight = document.body.clientHeight;
		}
		return windowHeight;
	}, 
  	width: function(){
      		var windowWidth;
      		if (self.innerWidth) {    // all except IE
          		windowWidth = self.innerWidth;
      		} else if (document.documentElement && document.documentElement.clientWidth) { // IE 6 Strict Mode
          		windowWidth = document.documentElement.clientWidth;
      		} else if (document.body) { // other IEs
          		windowWidth = document.body.clientWidth;
      		}
      		return windowWidth;
	}	  
};

Element.addMethods({  
  appendText: function(element, text) {
    element = $(element);
    text = String.interpret(text);
    element.appendChild(document.createTextNode(text));
    return element;
  }
});

Element.fromHTML = function(html){
	var root = new Element('div');
	root.innerHTML = html;
	return root.firstChild;
};
