/*
	mintajax.1.2.0.4
	www.mintajax.pl
	Copyright 2007 Piotr Korzeniewski
	Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

var mint = new Object();

mint.Request = function(url, target, OnSuccess, OnError)
{
	var req = {
		xmlHttpRequest : null,
		
		responseText : null,
		responseXML : null,
		responseJSON : null,
		
		getJSON : false,
		clearParams : true,
		clearHeader : true,
		
		params : new Array(),
		header : new Array(),
		
		group : null,
		
		url : null,
		async : true,
		method : "GET",
		encoding : "utf-8",
		contentType : "text/plain",
		username : "",
		password : "",
		
		form : null,
		disableForm : true,
		
		status : null,
		statusText : null,
		
		reqDone : false,
		retryCount : 0,
		retryNum : 3,
		timeout : 5000,
		
		OnStateChange : function() {},
		OnLoading : function() {},
		OnLoaded : function() {},
		OnInteractive : function() {},
		OnComplete : function() {},
		OnSuccess : function() {},
		OnError : function() {},
		OnAbort : function() {},
		OnRetry : function() {},
		OnTimeout : function() {},
		OnInsert : function() {},
		
		Send : function(url, target) {
			this.reqDone = false;
			
			if(window.XMLHttpRequest)
				this.xmlHttpRequest = new XMLHttpRequest();
			else if(window.ActiveXObject) {
				try	{
					this.xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e) {
					this.xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			
			var paramStr = "";
			
			for(var i in this.params) {
				if(i != 0) paramStr += "&";
				paramStr += encodeURIComponent(this.params[i].name)+"="+encodeURIComponent(this.params[i].value);
			}
			
			if(url) this.url = url;
			
			if(this.method.toLowerCase() == "post")
				this.xmlHttpRequest.open(this.method.toUpperCase(), this.url, this.async, this.username, this.password);
			else
				this.xmlHttpRequest.open(this.method.toUpperCase(), this.url+(!/\?/.test(this.url) ? "?"+paramStr : "&amp;"+paramStr), this.async, this.username, this.password);
			
			for(var i in this.header)
				this.xmlHttpRequest.setRequestHeader(this.header[i].name, this.header[i].value);
			
			if(this.method.toLowerCase() == "post")
				this.xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"+(this.encoding ? "; charset="+this.encoding : ""));
			else
				this.xmlHttpRequest.setRequestHeader("Content-Type", this.contentType);
				
			this.xmlHttpRequest.setRequestHeader("If-Modified-Since", "Sat, 11 Jan 1977 00:00:00 GMT");
			
			var that = this;
			
			this.xmlHttpRequest.onreadystatechange =
			function() {
				that.OnStateChange();
				
				switch(that.xmlHttpRequest.readyState) {
					case 1 : that.OnLoading(); break;
					case 2 : that.OnLoaded(); break;
					case 3 : that.OnInteractive(); break;
					case 4 : {
						that.OnComplete();
						
						try {
							if(that.xmlHttpRequest.status >= 200 && that.xmlHttpRequest.status < 300) {
								that.reqDone = true;
								
								that.responseText = that.xmlHttpRequest.responseText;
								that.responseXML = that.xmlHttpRequest.responseXML;
								
								that.status = that.xmlHttpRequest.status;
								that.statusText = that.xmlHttpRequest.statusText;
								
								if(target) $D(target).innerHTML = that.responseText;
								
								if(that.getJSON)
									that.responseJSON = eval("("+that.responseText+")");
									
								if(that.form && that.disableForm) {
									for(var i = 0; i < that.form.elements.length; ++i) {
										that.form.elements[i].disabled = false;
									}
								}
								
								if(that.group) {
									var groupDone = true;
									
									for(var i in that.group.req)
										if(!that.group.req[i].reqDone) groupDone = false;
										
									if(groupDone) {
										that.group.isRunning = false;
										that.group.OnDone(that);
									}
								}
								
								that.OnSuccess();
								
								if(that.clearParams) that.params.length = 0;
								if(that.clearHeader) that.header.length = 0;
							}
							else
								that.OnError(that.status);
						}
						catch (e) {
							that.OnError(-1);
						}	
						
						break;
					}
				}
			}
			
			if(this.group) {
				if(!this.group.isRunning) {
					this.group.isRunning = true;
					this.group.OnStart(this);
				}
			}
				
			if(this.method.toLowerCase() == "post")
				this.xmlHttpRequest.send(paramStr);
			else
				this.xmlHttpRequest.send(null);
			
			if(this.retryNum) {
				setTimeout(
						function() {
							if(!that.reqDone) {
								that.xmlHttpRequest.onreadystatechange = function() {};
								that.xmlHttpRequest.abort();
								that.OnTimeout();
								
								if(that.retryCount < that.retryNum) {
									that.retryCount++;
									that.Send();
									that.OnRetry();
								}
								else {
									that.retryCount = 0;
									that.OnAbort();
								}
							}
						},
						this.timeout);
			}
		},
		
		SendForm : function(form, url, method) {
			this.form = $D(form);
			
			this.url = url || this.form.action || this.url;
			this.method = method || this.form.method || "post";
			
			var input = this.form.elements;
			
			for(var i = 0; i < input.length; i++) {
				if(this.disableForm)
					input[i].disabled = true;
					
				switch(input[i].type) {
					case "radio":
					case "checkbox":
						if(input[i].checked)
							this.AddParam(input[i].name, input[i].value);
						break;
					case "select-one":
						this.AddParam(input[i].name, input[i].options[input[i].selectedIndex].value);
						break;
					case "select-multiple":
						for(var x = 0; x < input[i].options.length; ++x) {
							if(input[i].options[x].selected)
								this.AddParam(input[i].name, input[i].options[x].value);
						}
						break;
					default:
						this.AddParam(input[i].name, input[i].value);
				}
			}
			
			this.Send(this.url);
		},
		
		Set : function(name, value) {
			this[name] = value;
			return this;
		},
		
		AddParam : function(name, value) {
			this.params.push({name:name, value:value});
			return this;
		},
		
		RemoveParam : function(name) {
			for(var i in this.params) {
				if(this.params[i].name == name) {
					this.params.splice(i, 1);
					break;
				}
			}
			return this;
		},
		
		AddHeader : function(name, value) {
			this.params.push({name:name, value:value});
			return this;
		},
		
		RemoveHeader : function(name) {
			for(var i in this.header) {
				if(this.header[i].name == name) {
					this.header.splice(i, 1);
					break;
				}
			}
		}
	}
		
	if(OnSuccess && typeof OnSuccess == "function")
		req.OnSuccess = OnSuccess;
		
	if(OnError && typeof OnError == "function")
		req.OnError = OnError;
		
	if(url) target ? req.Send(url, target) : req.Send(url);
		
	return req;
};

mint.RequestGroup = function() {
	var group = {
		req : [],
		isRunning : false,
		
		OnStart : function() {},
		OnDone : function() {},
		
		Add : function() {
			for(var i = 0; i < arguments.length; ++i) {
				arguments[i].group = this;
				this.req.push(arguments[i]);
			}
		}
	}
	
	for(var i = 0; i < arguments.length; ++i)
		group.Add(arguments[i]);
	
	return group;
};

function $D(obj) {
	return (typeof obj == "string") ? document.getElementById(obj) : obj;
}

mint.fx =
{
	GetElapsedTime : function(obj, style) {
		obj = $D(obj);
		
		if(!obj.$fx || !obj.$fx[style])
			return null;
		
		return obj.$fx[style].elapsedTime;
	},
	
	IsRunning : function(obj, style) {
		obj = $D(obj);
		return (obj.$fx && obj.$fx[style] && obj.$fx[style].timeoutID);
	},
	
	Stop : function(obj, style) {
		obj = $D(obj);
		
		if(!obj.$fx) return null;
		
		if(!style) {
			for(var s in obj.$fx) {
				obj.$fx[s].Stop();
			}
		}
		else {
			switch(style) {
				case "move" : {
					if(obj.$fx["left"]) obj.$fx["left"].Stop();
					if(obj.$fx["top"]) obj.$fx["top"].Stop();
					break;
				}
				case "size" : {
					if(obj.$fx["width"]) obj.$fx["width"].Stop();
					if(obj.$fx["height"]) obj.$fx["height"].Stop();
					break;
				}
				case "fade" : {
					if(obj.$fx["opacity"]) obj.$fx["fade"].Stop();
					break;
				}
				default : {
					if(obj.$fx[style]) obj.$fx[style].Stop();
				}
			}
		}
	},

	Size : function(obj, width, height, steps, duration, OnStep, OnDone) {
		obj = $D(obj);
		
		var group = mint.fx.Group(null, steps, duration);
		
		group.OnStep = OnStep || function() {};
		group.OnDone = OnDone || function() {};

		if(width !== null) group.Add(obj, "width", GetWidth(obj), width);
		if(height !== null) group.Add(obj, "height", GetHeight(obj), height);
		
		group.Run();
		return group;
	},

	Move : function(obj, x, y, steps, duration, OnStep, OnDone) {
		obj = $D(obj);
		
		if(GetStyleFast(obj, "position") != "absolute")
			SetPos(obj, GetX(obj), GetY(obj));
		
		obj.style.margin = "0px";
		obj.style.padding = "0px";
		obj.style.position = "absolute";
		
		var group = mint.fx.Group(null, steps, duration);
		
		group.OnStep = OnStep || function() {};
		group.OnDone = OnDone || function() {};
		
		if(x !== null) group.Add(obj, "left", GetX(obj), x);
		if(y !== null) group.Add(obj, "top", GetY(obj), y);
		
		group.Run();
		return group;
	},

	Fade : function(obj, endOpacity, steps, duration, OnStep, OnDone) {
		this.Style(obj, "opacity", null, endOpacity, steps, duration, OnStep, OnDone);
	},
	
	Style : function(obj, style, start, end, steps, duration, OnStep, OnDone) {
		obj = $D(obj);
		
		if(!obj.$fx) obj.$fx = {};
		
		if(this.IsRunning(obj, style))
			obj.$fx[style].Stop();
			
		var value = start !== null ? parseInt(start) : parseInt(GetStyle(obj, style));
		
		obj.$fx[style] = {
			end : end,
			value : value,
			style : style,
			step : (end-value)/steps,
			stepTime : duration/steps,
			elapsedTime : 0,
			timeoutID : null,
			OnStep : OnStep || function() {},
			OnDone : OnDone || function() {},
			Stop : function() {
				if(this.timeoutID)
					clearTimeout(this.timeoutID);
					
				this.timeoutID = null;
			}
		}
		
		mint.fx.$Style(obj, obj.$fx[style], style);
	},
	
	$Style : function(obj, fx, style) {
		fx.OnStep(obj);
		fx.value += fx.step;
		fx.elapsedTime += fx.stepTime;
		
		if((fx.step > 0 && fx.value > fx.end) || (fx.step < 0 && fx.value < fx.end))
			fx.value = fx.end;
		
		fx.style == "opacity" ? SetOpacity(obj, fx.value) : obj.style[style] = fx.value+"px";
		
		if(fx.value == fx.end) {
			fx.OnDone(obj);
			fx.timeoutID = null;
		}
		else
			obj.$fx[style].timeoutID = setTimeout(function() {mint.fx.$Style(obj, fx, style)}, fx.stepTime);
	},
	
	Group : function(style, steps, duration, OnStep, OnDone) {
		var group = {
			fx : [],
			style : style,
			steps : steps,
			stepCount : 0,
			duration : duration,
			stepTime : duration/steps,
			elapsedTime : 0,
			timeoutID : null,
			
			OnStep : OnStep || function() {},
			OnDone : OnDone || function() {},
			
			Add : function(obj, style, start, end, OnStep, OnDone) {
				obj = $D(obj);
				
				if(!obj.$fx) obj.$fx = {};
				if(!style) style = this.style;
				
				var value = start !== null ? parseInt(start) : parseInt(GetStyle(obj, style));
				
				if(mint.fx.IsRunning(obj, style))
					obj.$fx[style].Stop();
				
				obj.$fx[style] = {
					obj : obj,
					end : end,
					value : value,
					step : (end-value)/this.steps,
					style : style,
					group : this,
					timeoutID : false,
					OnStep : OnStep || function() {},
					OnDone : OnDone || function() {},
					Stop : function() {
						for(var i = 0; i < this.group.fx.length; ++i) {
							if(this.group.fx[i] == this) {
								this.group.fx.splice(i, 1);
								break;
							}
						}
						
						this.timeoutID = false;
					}
				}
				
				this.fx.push(obj.$fx[style]);
				return obj.$fx[style];
			},
			
			Run : function() {
				this.fx.reverse();
				
				for(var x in this.fx)
					this.fx[x].timeoutID = true;
				
				mint.fx.$Group(this);
			},
			
			Stop : function() {
				if(this.timeoutID)
					clearTimeout(this.timeoutID);
					
				this.timeoutID = null;
			},
			
			Clear : function() {
				while(this.fx.length) {
					this.fx.pop().group = null;
				}
			}
		}
		
		return group;
	},
	
	$Group : function(g) {
		g.OnStep(g);
		g.elapsedTime += g.stepTime;
		
		for(var i = g.fx.length-1, fx = g.fx[i]; i >= 0; fx = g.fx[--i]) {
			fx.OnStep(fx.obj);
			fx.value += fx.step;
			
			if((fx.step > 0 && fx.value > fx.end) || (fx.step < 0 && fx.value < fx.end)) {
				fx.value = fx.end;
				fx.OnDone(fx.obj);
			}
		}
		
		for(var i = g.fx.length-1, fx = g.fx[i]; i >= 0; fx = g.fx[--i]) {
			fx.style == "opacity" ? SetOpacity(fx.obj, fx.value) : fx.obj.style[fx.style] = fx.value+"px";
		}

		if(g.stepCount++ == g.steps) {
			g.stepsElapsed = 0;
			g.timeoutID = false;
			g.OnDone(g);
		}
		else
			g.timeoutID = setTimeout(function() {mint.fx.$Group(g)}, g.stepTime);
		
	},
	
	Color : function(obj, style, startColor, endColor, steps, duration, OnStep, OnDone) {
		obj = $D(obj);
			
		if(!obj.$fx) obj.$fx = {};
		
		if(this.IsRunning(obj, style))
			obj.$fx[style].Stop();
		
		obj.$fx[style] = {
			end : {},
			endHex : endColor,
			value : {},
			step : {},
			stepTime : duration/steps,
			elapsedTime : 0,
			timeoutID : null,
			OnStep : OnStep || function() {},
			OnDone : OnDone || function() {},
			Stop : function() {
				if(this.timeoutID)
					clearTimeout(this.timeoutID);
					
				this.timeoutID = null;
			}
		}
		
		var fx = obj.$fx[style];
		
		if(!startColor) {
			var value = GetStyle(obj, style == "borderColor" ? "borderLeftColor" : style);
			
			if(/^rgb\( ?(\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\)$/.test(value))
				fx.value =  {r : parseInt(RegExp.$1), g : parseInt(RegExp.$2), b : parseInt(RegExp.$3)}
			else
				fx.value = HexToRGB(value);
		}
		else
			fx.value = HexToRGB(startColor);
			
		fx.end = HexToRGB(endColor);
			
		for(var c in fx.value) {
			fx.step[c] = (fx.end[c]-fx.value[c])/steps;
		}
		
		mint.fx.$Color(obj, fx, style);
	},

	$Color : function(obj, fx, style) {
		fx.OnStep(obj);
		fx.elapsedTime += fx.stepTime;
		
		for(var c in fx.value) {
			fx.value[c] += fx.step[c];
			
			if((fx.step[c] > 0 && fx.value[c] > fx.end[c]) || (fx.step[c] < 0 && fx.value[c] < fx.end[c]))
				fx.value[c] = fx.end[c];
		}
		
		obj.style[style] = "rgb("+parseInt(fx.value.r)+", "+parseInt(fx.value.g)+", "+parseInt(fx.value.b)+")";
		
		if(fx.value.r == fx.end.r && fx.value.g == fx.end.g & fx.value.b == fx.end.b) {
			fx.OnDone(obj);
			fx.timeoutID = null;
			obj.style[style] = fx.endHex;
		}
		else
			obj.$fx[style].timeoutID = setTimeout(function() {mint.fx.$Color(obj, fx, style)}, fx.stepTime);
	},
	
	Round : function(obj, corners, radius, fixedHeight) {
		obj = $D(obj);
		
		var m = [ [5, 3, 2, 1], [8, 6, 4, 3, 2, 1], [12, 9, 7, 6, 5, 4, 3, 2, 1] ];					
		var h = [ [0, 1, 1, 2], [0, 1, 1, 1, 2, 2], [0, 1, 1, 1, 1, 1, 1, 2, 3] ];			
		var o = [ [1, 2, 1, 1], [1, 2, 2, 1, 1, 1], [1, 3, 2, 1, 1, 1, 1, 1, 1] ];
		
		var ht = 0, hb = 0;
		
		if(!corners) corners = "all";
		
		var top = /all|top|tl|tr/.test(corners);
		var bottom = /all|bottom|bl|br/.test(corners);
		
		if(radius) radius = radius.toLowerCase();
		
		switch(radius) {
			case "large" : radius = 2; break;
			case "medium" : radius = 1; break;
			default : radius = 0;
		}
		
		for(var i = 0; i < h[radius].length; ++i) {
			if(top) ht += h[radius][i];
			if(bottom) hb += h[radius][i];
		}
		
		var c = $C("div");
		
		if(fixedHeight)
			typeof fixedHeight == "number" ? c.style.height = fixedHeight+"px" : c.style.height = GetStyleFast(obj, "height");
			
		c.style.backgroundColor = GetStyle(obj, "backgroundColor");
		c.style.paddingLeft = GetStyle(obj, "paddingLeft");
		c.style.paddingRight = GetStyle(obj, "paddingRight");
		c.style.paddingTop = Math.max(parseInt(GetStyle(obj, "paddingTop"))-ht, 0)+"px";
		c.style.paddingBottom = Math.max(parseInt(GetStyle(obj, "paddingBottom"))-hb, 0)+"px";

		var borderColor = !isNaN(parseInt(GetStyle(obj, "borderLeftWidth"))) && parseInt(GetStyle(obj, "borderLeftWidth")) > 0 ? GetStyle(obj, "borderLeftColor") : null;
			
		if(borderColor) {
			c.style.borderWidth = "0px 1px";
			c.style.borderColor = borderColor;
			c.style.borderStyle = "solid";
		}
		else
			c.style.borderWidth = "0px";
		
		obj.style.width = (obj.offsetWidth)+"px";
		obj.style.padding = "0px";
		obj.style.background = "transparent";
		obj.style.borderWidth = "0px";

		while(obj.firstChild) {
			c.appendChild(obj.firstChild);
		}
		
		if(top) {
			for(var i = 0; i < m[radius].length; ++i) {
				var rt = $C("b");
				
				if(/all|top|tl tr|tr tl/.test(corners))
					rt.style.margin = "0 "+m[radius][i]+"px";
				else if(/tl/.test(corners))
					rt.style.marginLeft = m[radius][i]+"px";
				else if(/tr/.test(corners))
					rt.style.marginRight = m[radius][i]+"px";
				
				rt.style.height = h[radius][i]+"px";
				rt.style.display = "block";
				rt.style.overflow = "hidden";
				rt.style.backgroundColor = c.style.backgroundColor;
				
				if(borderColor) {
					rt.style.borderWidth = "0 "+o[radius][i]+"px";
					
					if(/tl/.test(corners) && !/tr|top|all/.test(corners))
						rt.style.borderRightWidth = "1px";
					else if(/tr/.test(corners) && !/tl|top|all/.test(corners))
						rt.style.borderLeftWidth = "1px";
						
					rt.style.borderColor = borderColor;
					rt.style.borderStyle = "solid";
				}
				
				obj.appendChild(rt);
			}
		}
		
		obj.appendChild(c);
		
		if(bottom) {
			for(var i = 0; i < m[radius].length; ++i) {
				var bt = $C("b");
				
				if(/all|bottom|bl br|br bl/.test(corners))
					bt.style.margin = "0 "+m[radius][m[radius].length-1-i]+"px";
				else if(/bl/.test(corners))
					bt.style.marginLeft = m[radius][m[radius].length-1-i]+"px";
				else if(/br/.test(corners))
					bt.style.marginRight = m[radius][m[radius].length-1-i]+"px";
					
				bt.style.height = h[radius][h[radius].length-1-i]+"px";
				bt.style.display = "block";
				bt.style.overflow = "hidden";
				bt.style.backgroundColor = c.style.backgroundColor;
				
				if(borderColor) {
					bt.style.borderWidth = "0 "+o[radius][o[radius].length-1-i]+"px";
					
					if(/bl/.test(corners) && !/br|bottom|all/.test(corners))
						bt.style.borderRightWidth = "1px";
					else if(/br/.test(corners) && !/bl|bottom|all/.test(corners))
						bt.style.borderLeftWidth = "1px";
						
					bt.style.borderColor = borderColor;
					bt.style.borderStyle = "solid";
				}
				
				obj.appendChild(bt);
			}
		}
		
		if(top && borderColor)
			obj.firstChild.style.borderTopWidth = "1px";
		else if(borderColor)
			obj.style.borderTop = "1px solid "+borderColor;

		if(bottom && borderColor)
			obj.lastChild.style.borderBottomWidth = "1px";
		else if(borderColor)
			c.style.borderBottom = "1px solid "+borderColor;
		
		return c;
	}
};

mint.gui =
{
	dragObject : null,
	dragStartX : 0,
	dragStartY : 0,
	dragOffsetX : 0,
	dragOffsetY : 0,

	stack : [],
	stackOffset : 0,

	tabWidgets : [],
	treeWidgets :[],
	gridWidgets : [],
	accordionWidgets : [],
	dragObjects : [],
	dropZones : [],

	Init : function() {
		var that = this;
		AddEvent(document.getElementsByTagName("html")[0], "mousemove", function(event) {that.OnMouseMove(event)});
		AddEvent(document.getElementsByTagName("html")[0], "mouseup", function(event) {that.OnMouseUp(event)});
	},

	OnMouseMove : function(e) {
		if(this.dragObject) {
			if(window.getSelection)
				window.getSelection().removeAllRanges();
			else if(document.getSelection)
				document.getSelection().removeAllRanges();
			else if(document.selection)
				document.selection.empty();
				
			var d = this.dragObject, z;

			if(!d.isDragged && d.threshold != 0 && Math.pow(e.clientX-this.dragStartX, 2)+Math.pow(e.clientY-this.dragStartY, 2) > Math.pow(d.threshold, 2)) {
				SetPos(d.obj, GetX(d.obj), GetY(d.obj));
				d.obj.style.position = "absolute";	
				
				d.OnDragStart(d.obj);
				d.isDragged = true;
			}
			
			if(!d.lockX) {
				if(d.minX !== null && e.clientX-this.dragOffsetX < d.minX)
					SetX(d.obj, d.minX);
				else if(d.maxX !== null && e.clientX-this.dragOffsetX+GetWidth(d.obj) > d.maxX)
					SetX(d.obj, d.maxX-GetWidth(d.obj));
				else
					SetX(d.obj, e.clientX-this.dragOffsetX);
			}
			
			if(!d.lockY) {
				if(d.minY !== null && e.clientY-this.dragOffsetY < d.minY)
					SetY(d.obj, d.minY);
				else if(d.maxY !== null && e.clientY-this.dragOffsetY+GetHeight(d.obj) > d.maxY)
					SetY(d.obj, d.maxY-GetHeight(d.obj));
				else
					SetY(d.obj, e.clientY-this.dragOffsetY);
			}
			
			for(var i = this.dropZones.length-1, z = this.dropZones[i]; i >= 0; --i) {
				if(IsInside(z.obj, e.clientX, e.clientY, true)) {
					if((z.acceptClass && $(d.obj).hasClass(z.acceptClass)) || (!z.acceptClass && z.OnAccept(d.obj))) {
						if(!z.hover) {
							$(z.obj).addClass(z.hoverClass);	
							z.hover = d;
							z.OnHoverIn(d.obj);
						}
						
						if(!z.over && (z.over = GetChildAtPos(z.obj, e.clientX, e.clientY, true))) {
							if(z.useDummyNode) {
								if(z.dummyNode)
									z.obj.removeChild(z.dummyNode);
									
								z.dummyNode = d.obj.cloneNode(false);
								z.dummyNode.style.position = "static";
								
								if(z.autoInline) {
									z.dummyNode.style.cssFloat = "left";
									z.dummyNode.style.clear = "none";
								}
								
								z.dummyNodeClass ?  z.dummyNode.className = z.dummyNodeClass : z.dummyNode.style.visibility = "hidden";
									
								z.obj.insertBefore(z.dummyNode, z.over);
								z.over = z.dummyNode;
							}
							else {
								$(z.over).addClass(z.overClass);
								z.OnOverIn(d.obj, z.over);
							}
						}
						else {
							if(z.over != GetChildAtPos(z.obj, e.clientX, e.clientY, true))
								z.ResetOverState();
							else if(!z.dummyNode)
								z.OnOver(d.obj, z.over);
						}
						
						z.OnHover(d.obj);
						return true;
					}
				}
				else if(z.hover) {
					z.ResetOverState();
					z.ResetHoverState();
				}
			}
		}
		
		return true;
	},

	OnMouseUp : function(e) {
		if(this.dragObject) {
			var d = this.dragObject;
			
			for(var i = this.dropZones.length-1, z = this.dropZones[i]; i >= 0; --i, z = this.dropZones[i]) {
				if(IsInside(z.obj, e.clientX, e.clientY)) {
					if((z.acceptClass && $(d.obj).hasClass(z.acceptClass)) || (!z.acceptClass && z.OnAccept(d.obj))) {
						d.dropZone = z;
						
						z.over && z.insertInside ? z.InsertItem(d.obj, z.over) : z.InsertItem(d.obj);
							
						z.ResetOverState();
						z.ResetHoverState();
					}
					
					break;
				}
			}
			
			$(d.obj).removeClass(d.dragClass);
			d.OnDragStop(d.obj);
			
			this.dragObject.isDragged = false;
			this.dragObject = null;
		}
	},

	AddToStack : function(obj) {
		$D(obj).style.zIndex = this.stack.push($D(obj))+this.stackOffset;
	},
	
	RemoveFromStack : function(obj) {
		for(var i = $D(obj).style.zIndex-1-this.stackOffset; i < this.stack.length-1; ++i) {
			this.stack[i] = this.stack[i+1];
			this.stack[i].style.zIndex = i+1+this.stackOffset;
		}
		
		this.stack.pop();
	},
	
	MoveOnTop : function(obj) {
		this.RemoveFromStack(obj);
		this.AddToStack(obj);
	},
	
	SetStackOffset : function(offset) {
		this.stackOffset = offset;
	},

	$DragStart : function(e) {
		var m = mint.gui, d = this.dragObject, t = this;
		
		if(d.stopPropagation) {
			e.cancelBubble = true;
			if(e.stopPropagation) e.stopPropagation();
			if(e.preventDefault) e.preventDefault();
		}
		
		var pos = GetPos(t);
		
		m.dragObject = d;
		m.dragStartX = e.clientX;
		m.dragStartY = e.clientY;
		m.dragOffsetX = e.clientX-pos.x;
		m.dragOffsetY = e.clientY-pos.y;
		
		$(d.obj).addClass(d.dragClass);
		
		if(d.moveOnTop) m.MoveOnTop(t);
		if(d.threshold) return;
		
		if(d.dropZone) {
			d.dropZone.RemoveItem(t);
			m.OnMouseMove(e);
			d.dropZone = null;
		}
		
		if(GetStyleFast(t, "position") != "absolute") {
			SetPos(t, pos.x, pos.y);
			t.style.position = "absolute";
		}
		
		if(t.parentNode != document.body)
			document.body.appendChild(t);
			
		d.OnDragStart(t);
		d.isDragged = true;
		
		return false;
	},

	RegisterDragObject : function(obj) {
		obj = $D(obj);
		
		this.AddToStack(obj);
		
		AddEvent(obj, "mousedown", this.$DragStart);
		AddEvent(obj, "dragstart", function() {return false;});
		
		if(GetStyleFast(obj, "right") != "") obj.style.right = "";
		if(GetStyleFast(obj, "bottom") != "") obj.style.bottom = "";
		
		var d = {
			obj : obj,
			minX : null,
			maxX : null,
			minY : null,
			maxY : null,
			lockX : false,
			lockY : false,
			dragClass : null,
			hoverClass : null,
			dropZone : null,
			moveOnTop : true,
			threshold : 0,
			isDragged : false,
			stopPropagation : false,
			OnDrag : function() {},
			OnDragStart : function() {},
			OnDragStop : function() {},
			
			SetBBox : function(obj)  {
				obj = obj ? this.obj.parentNode : $D(obj);
				
				var pos = GetPos(obj), size = GetSize(obj);
				
				this.minX = pos.x;
				this.maxX = pos.x+size.width;
				this.minY = pos.y;
				this.maxY = pos.y+size.height;
			},
			
			RemoveBBox : function() {
				this.minX = this.maxX = this.minY = this.maxY = 0;
			}
		}
		
		obj.dragObject = d;
		
		this.dragObjects.push(d);
		
		return d;
	},

	UnregisterDragObject : function(obj) {
		obj = $D(obj);
		
		RemoveEvent(obj, "mousedown", this.$DragStart);
		RemoveEvent(obj, "dragstart", function() {return false;});
		
		for(var i in this.dragObjects) {
			if(this.dragObjects[i] == obj.dragObject) {
				this.dragObjects.splice(i, 1);
				obj.dragObject = null
				return true;
			}
		}
		
		return false;
	},

	RegisterDropZone : function(obj) {
		obj = $D(obj);
		
		var z = {
			obj : obj,
			over : null,
			hover : null,
			overClass : null,
			hoverClass : null,
			acceptClass : null,
			dummyNode : null,
			dummyNodeClass : null,
			useDummyNode : true,
			insertInside : true,
			autoInline : true,
			OnAdd : function() {},
			OnRemove : function() {},
			OnDrag : function() {},
			OnDrop : function() {},
			OnHover : function() {},
			OnHoverIn : function() {},
			OnHoverOut : function() {},
			OnOver : function() {},
			OnOverIn : function() {},
			OnOverOut : function() {},
			OnAccept : function() {return true;},
			
			InsertItem : function(obj, before) {
				obj = $D(obj);
				
				before ? this.obj.insertBefore(obj, before) : this.obj.appendChild(obj) ;
				
				obj.dragObject.dropZone = this;
				obj.style.position = "static";
				
				if(this.autoInline) {
					obj.style.cssFloat = "left";
					obj.style.clear = "none";
				}
				
				this.OnAdd(obj);
			},
			
			RemoveItem : function(obj) {
				obj = $D(obj);
				
				SetPos(obj, GetX(obj), GetY(obj));
				obj.style.position = "absolute";
				
				document.body.appendChild(obj);
				
				obj.dragObject.dropZone = null;
				
				this.OnRemove(obj);
			},
			
			ResetOverState : function() {
				if(!this.over) return;
				
				if(this.dummyNode) {
					this.obj.removeChild(this.dummyNode);
					this.dummyNode = null;
				}
				else {
					$(this.over).removeClass(this.overClass);
					this.OnOverOut(this.over);
				}
				
				this.over = null;
			},
			
			ResetHoverState : function() {
				if(!this.hover) return;
				
				$(this.obj).removeClass(this.hoverClass);
				this.OnHoverOut(this.hover);
				this.hover = null;
			}
		}
		
		obj.dropZone = z;
		
		this.dropZones.push(z);
		
		return z;
	},
	
	UnregisterDropZone : function(obj) {
		obj = $D(obj);
		
		for(var i in this.dropZones) {
			if(this.dropZones[i] == obj.dropZone) {
				this.dropZones.splice(i, 1);
				obj.dropZone = null;
				return true;
			}
		}
		
		return false;
	},
	
	LiveWidget : function(target, name, link) {
		var w = {
			target : target ? $D(target) : null,
			items : [],
			name : name,
			link : link,
			useHash : false,
			useCache : true,
			autoTextUpdate : true,
			selectFirstItem : true,
			widgetParam : "widget",
			itemParam : "item",
			alwaysUpdate : false,
			fading : false,
			fadeDuration : 500,
			fadeSteps : 25,
			hoverClass : null,
			req : mint.Request(),
			
			OnSelect : function() {},
			OnDeselect : function() {},
			OnUpdate : function() {},
			OnRetrieve : function() {},
			OnError : function() {},
			
			$AddItem : function() {},
			$Update : function() {},
			
			AddItem : function(obj, name, type, link) {
				obj = $D(obj);
				
				var t = this.LiveItem(obj, name, type, link);
				
				this.$AddItem(t);
				
				AddEvent(t.obj, "click", function() {this.liveWidget.Select(this.liveItem)});
				
				AddEvent(t.obj, "mouseover", function() {$(this).addClass(this.liveWidget.hoverClass)});
				AddEvent(t.obj, "mouseout", function() {$(this).removeClass(this.liveWidget.hoverClass)});
				
				if(this.selectFirstItem && this.items.length == 0)
					this.Select(t);
				
				this.items.push(t);
				return t;
			},
			
			LiveItem : function(obj, name, type, link, target) {
				var t = {
					obj : $D(obj),
					name : name,
					type : type ? type : "text",
					link : link,
					target : target,
					cache : null
				}
				
				t.obj.liveItem = t;
				t.obj.liveWidget = this;
				
				return t;
			},
			
			GetItem : function(name) {
				if(!name || typeof name != "string") return name;
				
				for(var i in this.items) {
					if(this.items[i].name == name)
						return this.items[i];
				}
			},
			
			Select : function(item) {
				if(this.activeItem != item || this.alwaysUpdate)
					this.GetLiveData(item);
			},
			
			Deselect : function(item) {
			},
			
			GetLiveData : function(liveItem) {
				var t = liveItem, w = this;
				
				if(w.activeItem) {
					var a = w.activeItem;
					w.activeItem = null;
					w.Deselect(a);
				}
					
				w.activeItem = t;
				
				if(w.useHash)
					window.location.hash = t.name;
				
				if(w.useCache && t.cache) {
					if(w.autoTextUpdate && t.type.toLowerCase() == "text" && w.target)
						w.fading ? w.Fade(t.cache) : w.target.innerHTML = t.cache;
					
					w.$Update(t, t.cache);
					w.OnUpdate(t, t.cache);
				}
				else if(t.type) {
					w.req.OnSuccess =function() {
						if(t.type.toLowerCase() == "text") {
							if(w.autoTextUpdate && w.target)
								w.fading ? w.Fade(this.responseText) : w.target.innerHTML = this.responseText;
							
							if(w.useCache) t.cache = this.responseText;
							w.$Update(t, this.responseText);
							w.OnUpdate(t, this.responseText);
						}
						else if(t.type.toLowerCase() == "json") {
							if(w.useCache) t.cache = this.responseJSON;
							w.$Update(t, this.responseJSON);
							w.OnUpdate(t, this.responseJSON);
						}
						else if(t.type.toLowerCase() == "xml") {
							if(w.useCache) t.cache = this.responseXML;
							w.$Update(t, this.responseXML);
							w.OnUpdate(t, this.responseXML);
						}
						else {
							w.$Update(t, null);
							w.OnUpdate(t, null);
						}
					}
					
					if(w.widgetParam && w.name) w.req.AddParam(w.widgetParam, w.name);
					if(w.itemParam && t.name) w.req.AddParam(w.itemParam, t.name);
					
					w.req.Send(t.link ? t.link : w.link);
					w.OnRetrieve(t);
				}
			},
			
			Fade : function(content) {
				var w = this;
				
				if(w.target.innerHTML.length == 0 || !/\S/.test(w.target.innerHTML))
					w.target.innerHTML = content;
				else {
					mint.fx.Style(w.target, "opacity", null, 0, w.fadeSteps, mint.fx.IsRunning(w.target, "opacity") ? mint.fx.GetElapsedTime(w.target, "opacity") : w.fadeDuration, null,
						function() {
							w.target.innerHTML = content;
							mint.fx.Style(w.target, "opacity", 0, 100, w.fadeSteps, w.fadeDuration);
						});
				}
			}
		}
		
		return w;
	},
	
	CreateTabWidget : function(target, name, link) {
		var w = this.LiveWidget(target, name, link);
		
		w.activeClass = null;
		w.activeImage = null;
		w.inactiveImage = null;
		w.imageClass= null;
		w.imagePosition = "left";
		
		w.$AddItem = function(t) {
			t.img = document.createElement("img");
			
			t.img.style.verticalAlign = "middle";
			
			if(this.imageClass)
				t.img.className = this.imageClass;
			
			this.inactiveImage ? t.img.src = this.inactiveImage : t.img.style.display = "none";
			this.imagePosition == "left" ? t.obj.insertBefore(t.img, t.obj.firstChild) : t.obj.appendChild(t.img);
		};
		
		w.AddTab = function(obj, name, type, link) {
			this.AddItem(obj, name, type, link);
		};
		
		w.Select = function(item) {
			$(item.obj).addClass(this.activeClass);
			
			if(this.activeImage) {
				item.img.src = this.activeImage;
				item.img.style.display = "";
			}
			
			if(this.alwaysUpdate || this.activeItem != item)
				w.GetLiveData(item);
		};
		
		w.Deselect = function(item) {
			$(item.obj).removeClass(this.activeClass);
				
			this.inactiveImage ? item.img.src = this.inactiveImage : item.img.style.display = "none";
		};
		
		this.tabWidgets.push(w);
		
		return w;
	},

	CreateTreeWidget : function(tree, target, name, link) {
		var w = mint.gui.LiveWidget(target, name, link);
		
		w.tree = $(tree);
		w.indent = 25;
		w.newItemUnfold = true;
		w.useClass = true;
		w.useImage = true;
		w.areaClass = null;
		w.imageClass = null;
		w.imagePosition = "left";
		w.foldAnimation = true;
		w.foldDuration = 500;
		w.foldSteps = 25;
		w.selectBeforeOpen = false;
		
		w.itemClass = null;
		w.itemSelectClass = null;
		w.foldClass = null
		w.foldSelectClass = null;
		w.unfoldClass = null
		w.unfoldSelectClass = null;
		
		w.itemImage = null;
		w.itemSelectImage = null;
		w.foldImage = null;
		w.foldSelectImage = null;
		w.unfoldImage = null;
		w.unfoldSelectImage = null;
		
		w.$AddItem = w.AddItem;
		
		w.InsertItem = function(parent, name, type, link, text) {
			this.AddItem(parent, name, type, link, text);
		}
		
		w.AddItem = function(parent, name, type, link, text) {
			parent = this.GetItem(parent);
			
			var t = {
				obj : document.createElement("div"),
				area : document.createElement("div"),
				img : document.createElement("img"),
				parent : parent ? parent : null,
				name : name,
				type : type ? type : null,
				link : link ? link : null,
				cache : null,
				fold : true
			}
			
			t.obj.liveItem = t;
			t.obj.liveWidget = this;
			
			t.obj.innerHTML = text || name || "";

			if(this.imageClass) t.img.className = this.imageClass;
				
			t.img.style.display = "none";
			t.img.style.verticalAlign = "middle";
			t.img.onload = function() {this.style.display = ""};
			t.img.onerror = function() {this.style.display = "none"};
			
			this.imagePosition == "left" ? t.obj.insertBefore(t.img, t.obj.firstChild) : t.obj.appendChild(t.img);
			
			t.area.style.display = "none";
			t.area.style.overflow = "hidden";
			t.area.style.marginLeft = this.indent+"px";
			
			if(parent) {
				parent.area.appendChild(t.obj);
				parent.area.appendChild(t.area);
				
				if(this.newItemUnfold) {
					parent.area.style.display = "block";
					parent.fold = false;
				}
				
				this.UpdateItem(parent);
			}
			else {
				this.tree.appendChild(t.obj);
				this.tree.appendChild(t.area);
			}
			
			AddEvent(t.obj, "click", function() { this.liveWidget.Select(this.liveItem); });
			
			AddEvent(t.obj, "selectstart", function() {return false});
			AddEvent(t.obj, "mousedown", function() {return false});
			
			AddEvent(t.obj, "mouseover", function() {$(this).addClass(this.liveWidget.hoverClass)});
			AddEvent(t.obj, "mouseout", function() {$(this).removeClass(this.liveWidget.hoverClass)});
			
			if(this.selectFirstItem && this.items.length == 0)
				this.Select(t);
				
			w.UpdateItem(t);
			
			this.items.push(t);
			return t;
		}
		
		w.Select = function(item) {
			if(!this.selectBeforeOpen || (this.selectBeforeOpen && this.activeItem == item))
				item.fold ? this.Unfold(item) : this.Fold(item);
			
			if(this.activeItem != item || this.alwaysUpdate) {
				this.GetLiveData(item);
				this.UpdateItem(item);
			}
		}
		
		w.Deselect = function(item) {
			this.UpdateItem(item);
		}
		
		w.Fold = function(item) {
			if(item) {
				if(item.fold) return;
				
				if(item.area.hasChildNodes()) {
					if(this.foldAnimation) {
						mint.fx.Style(item.area, "height", GetHeight(item.area), 0, this.foldSteps, mint.fx.IsRunning(item.area, "height") ? mint.fx.GetElapsedTime(item.area, "height") : this.foldDuration, null, function() {$(item.area).hide()});
						
						if(item.parent) {
							item.parent.area.style.height = GetHeight(item.parent.area);
							item.parent.area.style.height = "";
						}	
					}
					else
						$(item.area).hide();
				}
				
				item.fold = true;
				this.UpdateItem(item);
			}
			else {
				for(var i = 0; i < this.items.length; i++) {
					if(this.items[i].area.hasChildNodes()) this.Fold(this.items[i]);
				}
			}
		}
		
		w.Unfold = function(item) {
			if(item) {
				if(!item.fold) return;
				
				if(item.area.hasChildNodes()) {
					item.area.style.display = "block";
					
					if(this.foldAnimation)
						mint.fx.Style(item.area, "height", null, item.area.scrollHeight, this.foldSteps, mint.fx.IsRunning(item.area, "height") ? mint.fx.GetElapsedTime(item.area, "height") : this.foldDuration, null, function() {item.area.style.height = "";});
					else
						item.area.style.height = "";
				}
					
				item.fold = false;
				this.UpdateItem(item);
			}
			else {
				for(var i = 0; i < this.items.length; i++) {
					if(this.items[i].area.hasChildNodes()) this.Unfold(this.items[i]);
				}
			}
		}
		
		w.UpdateItem = function(item) {
			if(item.area.hasChildNodes()) {
				if(this.activeItem == item) {
					if(item.fold) {
						if(this.useClass) item.obj.className = item.foldSelectClass || item.foldClass || item.itemSelectClass || item.itemClass || this.foldSelectClass || this.foldClass || this.itemSelectClass || this.itemClass || item.obj.className;
						if(this.useImage) item.img.src = item.foldSelectImage || item.foldImage || item.itemSelectImage || item.itemImage || this.foldSelectImage || this.foldImage || this.itemSelectImage || this.itemImage || null;
					}
					else {
						if(this.useClass) item.obj.className = item.unfoldSelectClass || item.unfoldClass || item.itemSelectClass || item.itemClass || this.unfoldSelectClass || this.unfoldClass || this.itemSelectClass || this.itemClass || item.obj.className;
						if(this.useImage) item.img.src = item.unfoldSelectImage || item.unfoldImage || item.itemSelectImage || item.itemImage || this.unfoldSelectImage || this.unfoldImage || this.itemSelectImage || this.itemImage || null;
					}
				}
				else {
					if(item.fold) {
						if(this.useClass) item.obj.className = item.foldClass || item.itemClass || this.foldClass || this.itemClass || item.obj.className;
						if(this.useImage) item.img.src = item.foldImage || item.itemImage || this.foldImage || this.itemImage || null;
					}
					else {
						if(this.useClass) item.obj.className = item.unfoldClass || item.itemClass || this.unfoldClass || this.itemClass || item.obj.className;
						if(this.useImage) item.img.src = item.unfoldImage || item.itemImage || this.unfoldImage || this.itemImage || null;
					}
				}
				
				item.area.className = item.areaClass || this.areaClass || item.area.className;
			}
			else {
				if(this.activeItem == item) {
					if(this.useClass) item.obj.className = item.itemSelectClass || item.itemClass || this.itemSelectClass || this.itemClass || item.obj.className;
					if(this.useImage) item.img.src = item.itemSelectImage || item.itemImage || this.itemSelectImage || this.itemImage || null;
				}
				else {
					if(this.useClass) item.obj.className = item.itemClass || this.itemClass || item.obj.className;
					if(this.useImage) item.img.src = item.itemImage || this.itemImage || null;
				}
			}
		}
		
		this.treeWidgets.push(w);
		
		return w;
	},
	
	CreateAccordionWidget : function(name, link) {
		var w = mint.gui.LiveWidget(null, name, link);
		
		w.fading = true;
		w.alwaysOpen = true;
		w.slideSteps = 15;
		w.slideDuration = 450;
		w.slideWait = 80;
		w.openClass = null;
		w.staticHeight = null;
		w.prevItem = null;
		
		w.OnOpen = function() {};
		w.OnClose = function() {};
	
		w.AddItem = function(header, target, name, type, link) {
			var t = {
				header : $(header),
				target : $(target),
				content : $C("div"),
				name : name ? name : null,
				type : type ? type : null,
				link : link ? link : null,
				open : false,
				cache : null
			}
			
			t.header.liveItem = t.target.liveItem = t.content.liveItem = t;
			t.header.liveWidget = t.target.liveWidget = t.content.liveWidget = this;
			
			while(t.target.firstChild) {
				t.content.appendChild(t.target.firstChild);
			}
			
			t.target.appendChild(t.content);
			t.target.style.overflow = "hidden";
			
			if(GetStyle(t.target, "paddingTop"))
				t.content.style.marginTop = GetStyle(t.target, "paddingTop");
				
			if(GetStyle(t.target, "paddingBottom"))
				t.content.style.marginBottom = GetStyle(t.target, "paddingBottom");
				
			t.target.style.paddingTop = "0px";
			t.target.style.paddingBottom = "0px";
			
			AddEvent(t.header, "click", function() { this.liveWidget.Select(this.liveItem); });
			
			AddEvent(t.header, "selectstart", function() {return false});
			AddEvent(t.header, "mousedown", function() {return false});
			AddEvent(t.header, "mouseover", function() {$(this).addClass(this.liveWidget.hoverClass)});
			AddEvent(t.header, "mouseout", function() {$(this).removeClass(this.liveWidget.hoverClass)});
			
			if(this.selectFirstItem && this.items.length == 0) {
				if(this.staticHeight) SetHeight(t.target, this.staticHeight);
				if(t.link || (this.link && item.name)) this.GetLiveData(t);
			}
			else {
				t.target.style.height = "0px";
				t.height = t.target.scrollHeight;
				
				if(this.fading) SetOpacity(t.content, 0);
				
				$(t.target).hide();
				t.open = false;
			}
			
			this.items.push(t);
			return t;
		}
		
		w.$Update = function(item, response) {
			item.content.innerHTML = response;
			!this.prevItem && !item.open ? w.Open(item) : w.Close(this.prevItem);
		}
		
		w.Select = function(item) {
			if(!this.activeItem || this.activeItem != item) {
				this.prevItem = this.activeItem;
				this.activeItem = item;
				item.link || (this.link && item.name) ? this.GetLiveData(item) : w.Close(this.prevItem);
			}
			else if(!this.alwaysOpen) {
				this.prevItem = this.activeItem;
				this.activeItem = null;
				!item.open ? w.Open(item) : w.Close(item);
			}
		}
		
		w.Open = function(item) {
			if(!item.open) {
				$(item.target).show();
				$(item.header).addClass(this.openClass);
				
				item.height = item.target.scrollHeight;
				item.open = true;
				
				this.OnOpen(item);
				
				if(this.fading)
					mint.fx.Style(item.content, "opacity", null, 100, this.slideSteps, this.slideDuration);
				
				mint.fx.Style(item.target, "height", null, this.staticHeight || item.height, this.slideSteps, mint.fx.IsRunning(item.target, "height") ? mint.fx.GetElapsedTime(item.target, "height") : this.slideDuration);
			}
		}
		
		w.Close = function(item) {
			if(item.open) {	
				item.open = false;
				
				this.OnClose(item);
				
				if(this.fading)
					mint.fx.Style(item.content, "opacity", null, 0, this.slideSteps, this.slideDuration);
					
				mint.fx.Style(item.target, "height", GetHeight(item.target), 0, this.slideSteps, mint.fx.IsRunning(item.target, "height") ? mint.fx.GetElapsedTime(item.target, "height") : this.slideDuration, null, 
					function(obj) {
						$(item.target).hide();
						$(item.header).removeClass(w.openClass);
						
						if(w.activeItem && !w.activeItem.open)
							setTimeout(function() {w.Open(w.activeItem)}, w.slideWait);
					});
			}
		}
		
		this.accordionWidgets.push(w);
		
		return w;
	},

	CreateGridWidget : function(grid) {
		var w = {
			obj : $D(grid),
			desc : false,
			sortIndex : null,
			selectClass : null,
			multiSelect : true,
			selRows : [],
			caseSensitive : true,
			selective : false,
			exclude : null,
			excludeFirstRow : true,
			excludeLastRow : false,
			remoteDataSeparator : ",",
			remoteRowSeparator : "\r\n",
			supportPolishChars : true,
			req : mint.Request(),
			
			OnSelect : function() {},
			OnDeselect : function() {},
			OnSort : function() {},
			OnStopSort : function() {},
			OnAscSort : function() {},
			OnDescSort : function() {},
			OnInsert : function() {},
			OnDelete : function() {},
			OnRemoteLoading : function() {},
			OnRemoteDone : function() {},
			OnRemoteError : function() {},
			
			AddSortCell : function(index) {
				var cell = this.obj.rows[0].cells[index];
				
				cell.gridWidget = this;
				cell.gridSortIndex = index;
				
				AddEvent(cell, "mousedown", function() {return false});
				AddEvent(cell, "selectstart", function() {return false});
				AddEvent(cell, "click", this.Sort);
			},
			
			AddSortCells : function(index) {
			   if(arguments.length > 0) for(var i = 0; i < arguments.length; ++i) this.AddSortCell(arguments[i]);
			   else for(var i = 0; i < this.obj.rows[0].cells.length; ++i) this.AddSortCell(i); 
			},
			
			FixTable : function() {
				if(this.obj.tBodies.length == 0)
					this.obj.appendChild($C("tBody"));
					
				if(!this.obj.tHead && this.excludeFirstRow) {
					this.obj.insertBefore($C("tHead"), this.obj.tBodies[0]);
					if(this.obj.tBodies[0].rows.length > 0) this.obj.tHead.appendChild(this.obj.rows[0]);
				}
				
				if(!this.obj.tFoot && this.excludeLastRow) {
					this.obj.appendChild($C("tFoot"));
					if(this.obj.tBodies[0].rows.length > 0) this.obj.tFoot.appendChild(this.obj.rows[this.obj.rows.length-1]);
				}
			},
			
			Sort : function() {
				var grid = this.gridWidget;
				var rows = [];
				
				for(var r = 0; r < grid.obj.tBodies[0].rows.length; r++)
					rows.push(grid.obj.tBodies[0].rows[r]);
				
				if(grid.sortIndex != this.gridSortIndex) {
					grid.OnStopSort(rows[0].cells[grid.sortIndex]);
					grid.desc = false;
				}
				else
					grid.OnSort(rows[0].cells[grid.sortIndex]);
					
				grid.sortIndex = this.gridSortIndex;
				
				var sortCell = rows[0].cells[grid.sortIndex].innerHTML;
				
				if(/^\d\d\D\d\d\D\d\d\d\d$/.test(sortCell)) {
					var sortFunc = function(a, b) {
						try {
							a = a.cells[grid.sortIndex].innerHTML.replace(/^(\d\d)\D(\d\d)\D(\d\d\d\d)$/, "$3$2$1");
							b = b.cells[grid.sortIndex].innerHTML.replace(/^(\d\d)\D(\d\d)\D(\d\d\d\d)$/, "$3$2$1")
						
							if(a < b) return -1;
							if(a > b) return 1;
						
						} catch(error) {}
						
						return 0;
					}
				}
				else if(/^\d\d\d\d\D\d\d\D\d\d$/.test(sortCell)) {
					var sortFunc = function(a, b) {
						try {
							a = a.cells[grid.sortIndex].innerHTML.split(/\D/).reverse().join("");
							b = b.cells[grid.sortIndex].innerHTML.split(/\D/).reverse().join("");
							
							a = a.replace(/^(\d\d)(\d\d)(\d\d\d\d)$/, "$3$2$1");
							b = b.replace(/^(\d\d)(\d\d)(\d\d\d\d)$/, "$3$2$1");
						
							if(a < b) return -1;
							if(a > b) return 1;
							
						} catch(error) {}
						
						return 0;
					}
				}
				else if(!isNaN(parseInt(sortCell))) {
					var sortFunc = function(a, b) {
						return parseFloat(a.cells[grid.sortIndex].innerHTML) - parseFloat(b.cells[grid.sortIndex].innerHTML);
					}
				}
				else if(typeof sortCell == "string") {
					var sortFunc = function(a, b) {
						try {
							a = a.cells[grid.sortIndex].innerHTML;
							b = b.cells[grid.sortIndex].innerHTML;
							
							if(grid.supportPolishChars) {
								var pl = [261, 263, 281, 322, 324, 243, 347, 378, 380];
								var en = [97, 99, 101, 108, 110, 111, 115, 122, 122];
							}
							
							if(grid.caseSensitive) {
								if(grid.supportPolishChars) {
									pl = [260, 262, 280, 321, 323, 211, 346, 377, 379].concat(pl);
									en = [65, 67, 69, 76, 78, 79, 83, 90, 90].concat(en);
								}
							}
							else {
								a.toLowerCase();
								b.toLowerCase();
							}
							
							if(!a || !b) return 0;
							
							var length = a.length > b.length ? a.length : b.length;
							
							for(var i = 0; i < length; i++) {
								if(isNaN(a.charCodeAt(i))) return -1;
								if(isNaN(b.charCodeAt(i))) return 1;
								
								if(a.charCodeAt(i) == b.charCodeAt(i)) continue;
								
								if(a.charCodeAt(i) > 243 && a.charCodeAt(i) < 380 && b.charCodeAt(i) > 243 && b.charCodeAt(i) < 380) {
									for(var c in pl) {
										if(a.charCodeAt(i) == pl[c]) return -1;
										if(b.charCodeAt(i) == pl[c]) return 1;
									}
								}
								else if((a.charCodeAt(i) > 243 && a.charCodeAt(i) < 380) || (b.charCodeAt(i) > 243 && b.charCodeAt(i) < 380)) {
									for(var c in pl) {
										if((a.charCodeAt(i) == pl[c] && en[c] < b.charCodeAt(i)) || (b.charCodeAt(i) == pl[c] && en[c] > a.charCodeAt(i)))
											return -1;
										else if((a.charCodeAt(i) == pl[c] && en[c] > b.charCodeAt(i)) || (b.charCodeAt(i) == pl[c] && en[c] < a.charCodeAt(i)))
											return 1;
									}
								}
								
								if(a.charCodeAt(i) < b.charCodeAt(i)) return -1;
								if(a.charCodeAt(i) > b.charCodeAt(i)) return 1;
							}
						} catch(error) {}
						
						return 0;
					}
				}
				else {
					var sortFunc = function(a, b) {
						try {
							a = a.cells[grid.sortIndex].innerHTML.toLowerCase();
							b = b.cells[grid.sortIndex].innerHTML.toLowerCase();
						
							if(a < b) return -1;
							if(a > b) return 1;
							
						} catch(error) {}
						
						return 0;
					}
				}
				
				rows.sort(sortFunc);
				
				if(grid.desc) rows.reverse();
				
				grid.desc ? grid.OnDescSort(grid.sortIndex) : grid.OnAscSort(grid.sortIndex);
				grid.desc = !grid.desc;
				
				grid.OnSort(grid.sortIndex);
				
				for(var r = 0; r < rows.length; r++)
					grid.obj.tBodies[0].appendChild(rows[r]);
			},
			
			LoadTextData : function(url) {
				var grid = this;
				
				this.req.OnSuccess = function() {
					var rows = this.responseText.split(grid.remoteRowSeparator);
					
					for(var r in rows)
						grid.InsertRow(rows[r].split(grid.remoteDataSeparator));
					
					if(grid.selective) grid.SetSelective();
					grid.OnRemoteDone(this.responseText);
				}
				
				this.req.OnError = this.OnRemoteError;
				this.req.getJSON = false;
				
				this.req.Send(url);
				this.OnRemoteLoading();
			},
			
			LoadJSONData : function(url) {
				var grid = this;
				
				this.req.OnSuccess = function() {
					for(var d in this.responseJSON)
						grid.InsertRow(this.responseJSON[d]);
					
					if(grid.selective) grid.SetSelective();
					grid.OnRemoteDone(this.responseJSON);
				}
				
				this.req.OnError = this.OnRemoteError;
				this.req.getJSON = true;
				
				this.req.Send(url);
				this.OnRemoteLoading();
			},
			
			Select : function(row) {	
				r = this.GetRow(row);
				
				if(r.gridSelect === true)
					return;
					
				r.gridSelect = true;
				$(r).addClass(this.selectClass);
				
				this.selRows.push(r);
				this.OnSelect(r);
			},
			
			Deselect : function(row) {
				r = this.GetRow(row);
				
				if(r.gridSelect === false)
					return;
					
				for(var i in this.selRows) {
					if(this.selRows[i] == r) {
						this.selRows.splice(i, 1);
						break;
					}
				}
				
				r.gridSelect = false;
				$(r).removeClass(this.selectClass);
				
				this.OnDeselect(r);
			},
			
			SelectAll : function() {
				for(var i = 0; i < this.obj.tBodies[0].rows.length; i++)
					this.Select(this.obj.tBodies[0].rows[i]);
			},
			
			DeselectAll : function() {
				for(var i = this.selRows.length-1; i >= 0; i--)
					this.Deselect(this.selRows[i]);
			},
			
			SetSelective : function() {
				this.selective = true;
				
				this.exclude ? this.exclude.length = 0 : this.exclude = [];
					
				if(arguments.length > 0) {
					for(var i = 0; i < arguments.length; i++)
						this.exclude.push(arguments[i]);
				}
				
				for(var r = 0, row = this.obj.tBodies[0].rows[0]; r < this.obj.tBodies[0].rows.length; row = this.obj.tBodies[0].rows[++r]) {
					if(!row.gridSelective) {
						row.gridWidget = this;
						row.gridSelect = false;
						row.gridSelective = true;
						
						AddEvent(row, "selectstart", function() {return false});
						AddEvent(row, "mousedown", this.$OnSelect);
					}
				}
			},
			
			$OnSelect : function() {
				var w = this.gridWidget;
				
				if(!this.gridSelect) {
					if(!w.multiSelect && w.selRows.length !== 0)
						w.Deselect(w.selRows[0]);
						
					w.Select(this);
				}
				else
					w.Deselect(this);
					
				return false;
			},
			
			IsSelected : function(row) {
				return this.GetRow(index).gridSelect;
			},
			
			GetRow : function(index) {
				if(typeof index =="number" && index >= this.obj.tBodies[0].rows.length)
					return null;
					
				return (typeof index == "number") ? this.obj.tBodies[0].rows[index] : index;
			},
			
			GetSelRows : function() {
				return this.selRows;
			},
			
			DeleteRow : function(row) {
				r = this.GetRow(row);
				
				this.OnDelete(r);
				if(r.gridSelect) this.Deselect(r);
				this.obj.deleteRow(r.rowIndex);
			},
			
			DeleteSelRows : function()  {
				for(var i = this.selRows.length-1; i >= 0; --i)
					this.DeleteRow(this.selRows[i]);
			},
			
			DeleteAllRows : function() {
				for(var i = this.obj.tBodies[0].rows.length-1; i > 0; --i)
					this.DeleteRow(this.obj.tBodies[0].rows[i]);
			},	
			
			InsertRow : function(values) {
				return this.InsertBefore(null, typeof values == "object" ? values : arguments);
			},
			
			InsertBefore : function(before, values) {
				var tr = $C("tr");
				
				this.obj.tBodies[0].insertBefore(tr, before ? this.GetRow(before) : null);
				
				if(typeof values == "object" && values.length) {
					for(var i = 0; i < values.length; i++)
						tr.insertCell(-1).appendChild(document.createTextNode(values[i]));
				}
				else {
					for(var i = 1; i < arguments.length; i++)
						tr.insertCell(-1).appendChild(document.createTextNode(arguments[i]));
				}
				
				if(this.selective) this.SetSelective();
				
				this.OnInsert(tr);
				return tr;
			}
		}
		
		w.FixTable();
		this.gridWidgets.push(w);
		return w;
	}
};

mint.gui.Init();

function $(id) {
	if(!id) return null;
		
	e = typeof id == "string" ? document.getElementById(id) : id;
	
	e.getTagName = function(tag) {
		return this.tagName ? this.nodeName.toLowerCase() : null;
	}
		
	e.next = function(tag, offset) {
		var next = this.nextSibling;
		
		for(var i = 0; next; next = next.nextSibling) {
			if(!$(next).isWhitespace() && ((tag && $(next) && $(next).getTagName() == tag) || (!tag && $(next))))
				if(!offset || ++i == offset)
					break;
		}
			
		return $(next);
	}
	
	e.prev = function(tag, offset) {
		var prev = this.previousSibling;
		
		for(var i = 0; prev; prev = prev.previousSibling) {
			if(!$(prev).isWhitespace() && ((tag && $(prev) && $(prev).getTagName() == tag) || (!tag && $(prev))))
				if(!offset || ++i == offset)
					break;
		}
		
		return $(prev);
	}
	
	e.up = function() {
		return this.parentNode;
	}
	
	e.down = function(tag, offset) {
		var child = this.firstChild;
		
		if(tag || offset) child = $(child).next(tag, offset);
		
		while($(child).isWhitespace())
			child = $(child).next(tag, offset);
			
		return child;
	}
	
	e.getElementsByClass = function(className, tag) {
		var r = [];
		var n = this.getElementsByTagName(tag || '*');
		var p = new RegExp('(^|\\s)'+className+'(\\s|$)');
		
		for(var i = 0; i < n.length; ++i)
			if(p.test(n[i].className))
				r.push(n[i]);
		
		return r;
	}
	
	e.hide = function() {
		if(!this._style) this._style = {};
		this._style.width = GetStyleFast(this, "width");
		this._style.height = GetStyleFast(this, "height");
		this._style.display = GetStyleFast(this, "display");
		this.style.display = "none";
	}
	
	e.show = function() {
		this.style.display = this._style && this._style.display ? this._style.display : "";
	}
	
	e.toggle = function() {
		GetStyleFast(this, "display") == "none" ? this.show() : this.hide();
	}
	
	e.hasClass = function(name) {
		if(!name) return;
		
		var cl = this.className.split(" ");
		
		for(var c in cl)
			if(cl[c] == name) return true;
		
		return false;
	}
	
	e.addClass = function(name) {
		if(!name) return;
		
		if(!this.hasClass(name)) {
			var cl = this.className.split(" ");
			cl.push(name);
			this.className = cl.join(" ");
		}
	}
	
	e.removeClass = function(name) {
		if(!name) return;
		
		var cl = this.className.split(" ");
		
		for(var c in cl) {
			if(cl[c] == name) {
				cl.splice(c, 1);
				break;
			}
		}
		
		this.className = cl.join(" ");
	}
	
	e.isWhitespace = function() {
		return !/\S/.test(this.nodeValue);
	}

	return e;
}

function $C(type, id, className) {
	var c = (type == "#text") ? document.createTextNode(type) : document.createElement(type);
	if(id) c.id = id;
	if(className) c.className = className;
	return c;
}

function IsF(obj) {
	return (typeof obj == "function");
}

function AddEvent(obj, type, handler) {
	obj = $D(obj);

	if(!obj.events)
		obj.events = new Array();
		
	if(!obj.events["on"+type]) {
		obj.events["on"+type] = new Array();
		if(obj["on"+type])
			obj.events["on"+type].push(obj["on"+type]);
	}

	obj.events["on"+type].push(handler);

	obj["on"+type] = function(event) {
		event = event || window.event;
		
		var returnValue = true;
		var eventHandlers = this.events["on"+event.type];
		
		if(eventHandlers) {
			for(var i in eventHandlers) {
				this.$eventHandler = eventHandlers[i];
				returnValue = this.$eventHandler.call(this, event);
			}
		}
		
		return returnValue;
	}
}

function RemoveEvent(obj, type, handler) {
	obj = $(obj);
	
	var eventHandlers = obj.events["on"+type];

	for(var i in eventHandlers) {
		if(eventHandlers[i] === handler) {
			eventHandlers.splice(i, 1);
			return true;
		}
	}
	
	return false;
}

function GenerateID() {
	var id = new Date().getTime().toString();
	
	while($D(id) != null)
		id = new Date().getTime().toString();
		
	return id;
}

function GetPos(obj, ignoreMargins) {
	obj = $D(obj);

	var x = obj.offsetLeft || 0, y = obj.offsetTop || 0;
	
	if(!ignoreMargins) {
		var marginLeft, marginTop;
		
		if(marginLeft = parseInt(GetStyleFast(obj, "marginLeft", "margin-left"))) x -= marginLeft;
		if(marginTop = parseInt(GetStyleFast(obj, "marginTop", "margin-top"))) y -= marginTop;
	}	

	while(obj = obj.offsetParent) {
		x += obj.offsetLeft;
		y += obj.offsetTop;
	}
	
	return {x:x, y:y};
}

function GetX(obj, ignoreMargins) {
	return GetPos(obj, ignoreMargins).x;
}

function GetY(obj, ignoreMargins) {
	return GetPos(obj, ignoreMargins).y;
}

function SetPos(obj, x, y) {
	SetX(obj, x);
	SetY(obj, y);
}

function SetX(obj, x) {
	$D(obj).style.left = x+"px";
}

function SetY(obj, y) {
	$D(obj).style.top = y+"px";
}

function GetSize(obj) {
	return {'width':GetWidth(obj), 'height':GetHeight(obj)};
}

function GetWidth(obj) {
	if(!$D(obj).clientWidth) $D(obj).style.zoom = "1.0";
	return $D(obj).clientWidth;
}

function GetHeight(obj) {
	obj = $D(obj);
	if(!$D(obj).clientHeight) $D(obj).style.zoom = "1.0";
	return $D(obj).clientHeight;
}

function SetSize(obj, width, height) {
	this.SetWidth(obj, width);
	this.SetHeight(obj, height);
}

function SetWidth(obj, width) {
	$D(obj).style.width = width+"px";
}

function SetHeight(obj, height) {
	$D(obj).style.height = height+"px";
}

function GetOpacity(obj) {
	obj = $D(obj);

	if(obj.style.opacity)
		return Math.round(obj.style.opacity*100);
	else if(obj.style.filter)
		return Math.round(/\d+/.exec(obj.style.filter)[0]);
	else
		return 100;
}


function SetOpacity(obj, opacity) {
	$D(obj).style.opacity = opacity*0.01;
	$D(obj).style.filter = "alpha(opacity="+opacity+")";
	$D(obj).style.zoom = "1.0";
}

function IsInside(obj, x, y, ignoreMargins) {
	obj = $D(obj);
	var pos = GetPos(obj, ignoreMargins), size = GetSize(obj);
	
	if(pos.x < x && pos.x+size.width > x && pos.y < y && pos.y+size.height > y)
		return true;

	return false;
}

function GetChildAtPos(obj, x, y, ignoreMargins) {
	var child = $D(obj).childNodes;

	for(var i = child.length-1, ch = child[0]; i >= 0; i--) {
		if(child[i].nodeName != "#text" && IsInside(child[i], x, y, ignoreMargins))
			return child[i];
	}

	return null;
}

function HexToRGB(hex) {
	hex = hex.replace(/#/, "");

	return {	r: parseInt(hex.substring(0, 2), 16),
				g: parseInt(hex.substring(2, 4), 16),
				b: parseInt(hex.substring(4, 6), 16)};
}

function RGBToHex(r, g, b) {
	return ToHex(r)+ToHex(g)+ToHex(b)
}

function ToHex(n) {
	if (!n) return "00";

	n = Math.round(Math.min(Math.max(0,parseInt(n)),255));

	return "0123456789ABCDEF".charAt((n-n%16)/16) + "0123456789ABCDEF".charAt(n%16);
}

function GetStyle(obj, style) {
	obj = $D(obj);
	
	if(style == "opacity")
		return GetOpacity(obj);
		
	if(obj.currentStyle) return obj.currentStyle[style];
	else if(window.getComputedStyle) return getComputedStyle(obj, "").getPropertyValue(style.replace(/[A-Z]/g, function(obj, ch) {return "-"+style.charAt(ch).toLowerCase()}));
}

function GetStyleFast(obj, style, styleCSS) {
	obj = $D(obj);
	
	if(obj.currentStyle) return obj.currentStyle[style];
	else if(window.getComputedStyle) return getComputedStyle(obj, "").getPropertyValue(styleCSS || style);
}

function Timeout(func, time) {
	var params = new Array();
	
	for(var i = 2; i < arguments.length; i++) {
		if(typeof(arguments[i]) == "string")
			params.push("'"+arguments[i]+"'");
		else if(!arguments[i])
			params.push("null");
		else
			params.push(arguments[i])
	}
	
	return setTimeout(func+"("+params.toString()+")", time);
}

function SetCookie(name, value, days, path, domain, secure) {
	if(days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		var expires = "";
		
	document.cookie = name+"="+escape(value)+expires+
		(path ? "; path="+path : "")+
		(domain ? "; domain="+domain : "")+
		(secure ? "; secure="+secure : "");
}

function GetCookie(name) {
	if(document.cookie.length > 0) {
		var start = document.cookie.indexOf(name+"=");
		if(start != -1) {
			start = start+name.length+1;
			var end = document.cookie.indexOf(";",start);
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(start, end));
		}
	}
	return "";
}

function DeleteCookie(name) {
	SetCookie(name, "", -1);
}
function pinguj(lokalizacjaid, target) {

document.getElementById(target).innerHTML="<img src='/img/wait.gif' alt='Czekaj...'>";
var req = mint.Request();
req.AddParam("lokalizacja", lokalizacjaid);
req.Send("/ping.php", target);
}