Function.prototype.method=function(name, fn){
	this.prototype[name]=fn;
	return this; 
};
(function(){
	function _$(elems){
		this.elements=[];
		for(var i=0, len=elems.length;i<len;i++){
			var element=elems[i];
			if(typeof element==='string'){
				var element2 = document.getElementById(element);
				
				if (typeof element2 != "undefined") {
					
					if (element2 == null) {
						document.createElementNs ? element = document.createElementNS("http://www.w3.org/1999/xhtml", "html:" + element) : element = document.createElement(element);
					}else{
						element = element2;
						
					}
				}else 
					element = element2;
			}
			this.elements.push(element);
		}
	}
	_$.method('each',function(fn){
		for(var i=0,len=this.elements.length;i<len; i++){
			fn.call(this, this.elements[i]);
		}
	}).method('setClass', function(name, stelle){
		this.each(function(el){
			stelle = stelle || 0;
			var classArr = el.className.split(" ");
			classArr[stelle]=name;
			el.className=classArr.join(" ");
		})
		return this;
	}).method('setAttribute', function(name, value){
		this.each(function(el){
			el.setAttribute(name, value);	   
		})
		return this;
	}).method('removeAttribute', function(name){
		this.each(function(el){
			el.removeAttribute(name, false);	   
		})
		return this;
	}).method('setStyle', function(prop, val){
		this.each(function(el){
			if(val=='NaNpx')
				val = 0;
			
			
			el.style[prop]=val;	   
		})
		return this;
	}).method('removeStyle', function(prop){
		this.each(function(el){
			el.style.removeProperty(prop);	   
		})
		return this;
	}).method('setStyle', function(prop, val){
		this.each(function(el){
			if(typeof el == 'undefined')
				return false;
			if(val=='NaNpx')
				val = 0;

			el.style[prop]=val;	   
		})
		return this;
	}).method('toggleVis', function(type){
		this.each(function(el){
			type = type || 'display';
			type=='visibility'?
				self.DOOM.getStyle(el, type)=='hidden'?$(el).show(type):$(el).hide(type):
				self.DOOM.getStyle(el, type)=='none'?$(el).show(type):$(el).hide(type);
		})
		return this;
	}).method('show', function(type){
		this.each(function(el){
			type=='visibility'?$(el).setStyle('visibility', 'visible'):$(el).setStyle('display', 'block');			   
		})
		return this;
	}).method('hide', function(type){
		this.each(function(el){
			type=='visibility'?$(el).setStyle('visibility', 'hidden'):$(el).setStyle('display', 'none');		   
		})
		return this;
	}).method('append', function(elem){
		this.each(function(el){
			if(typeof elem!="undefined"){
				el.appendChild(this.checkElem(elem));
			}else{
				//alert('PTDOOMLIB says: not defined');
			}
		})
		return this;
	}).method('first', function(elem){
		this.each(function(el){
			el.insertBefore(this.checkElem(elem), el.firstChild);
		})
		return this;
	}).method('before', function(elem){
		this.each(function(el){
			
			el.parentNode.insertBefore(this.checkElem(elem), this.checkElem(el));
		})
		return this;
	}).method('after', function(elem){
		this.each(function(el){
			el.parentNode.insertBefore(this.checkElem(elem), this.checkElem(el).nextSibling);
		})
		return this;
	}).method('remove', function(){
		this.each(function(el){
			el.parentNode.removeChild(el);
		})
		return this;
	}).method('replace', function(elem){
		this.each(function(el){
			this.before(elem);
			this.remove();
		})
		return this;
	}).method('empty', function(){
		this.each(function(el){
			while(el.firstChild) 
				$(el.firstChild).remove();
		})
		return this;
	}).method('checkElem',function(elem){
		return elem && elem.constructor==String?document.createTextNode(elem):elem;
	}).method('get', function(number){
		number=number||0;
		return this.elements[number];
	}).method('getTarget', function(e){
		e=e||window.event;
		return e.target||e.srcElement;
	}).method('setPageX', function(elem){
		this.each(function(el){
			var x = elem.offsetParent ? elem.offsetLeft+self.DOOM.getPageX(elem.offsetParent):elem.offsetLeft;
			$(el).setStyle('left', x+'px');
		})
		return this;
	}).method('setPageY', function(elem){
		this.each(function(el){
			var y = elem.offsetParent ? elem.offsetTop+self.DOOM.getPageY(elem.offsetParent):elem.offsetTop;
			$(el).setStyle('top', y+'px');
		})
		return this;
	}).method('setFullWidth', function(elem){
		this.each(function(el){
			$(el).setStyle('width', self.DOOM.getFullWidth(elem));
		})
		return this;
	}).method('setFullHeight', function(elem){
		this.each(function(el){
			$(el).setStyle('height', self.DOOM.getFullHeight(elem));
		})
		return this;
	}).method('setWPxToPc', function(){
		this.each(function(el){
			var sWidth = parseInt(self.DOOM.getFullWidth(el.parentNode));
			var eWidth = parseInt(self.DOOM.getFullWidth(el));
			var pc = eWidth*100/sWidth;
			$(el).setStyle('width', pc+'%');
		})
		return this;
	})
	//EVENTS
	.method('addEvent', function(type, fn){
		this.each(function(el){
			if(typeof el=='undefined')
				return false;
			
			if(el.addEventListener!=null)
				el.addEventListener(type, fn, false)
			else if(el.attachEvent)
				el.attachEvent('on'+type, fn);
			else
				el['on'+type] = fn;
		})
		return this;					 
	}).method('removeEvent', function(type, fn){
		this.each(function(el){
			if(el.removeEventListener)
				el.removeEventListener(type, fn, false)
			else if(el.detachEvent)
				el.detachEvent('on'+type, fn);
			else
				delete el['on'+type];
		})
		return this;					 
	})
	window.$ = function(){
		return new _$(arguments);	
	}
})();

var tempTo = null;
var Drag = {

	obj : null,
	dragging : false,	

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper, DragEnd, Draggin){
		//o.onmousedown = Drag.start;
		o.hmode = bSwapHorzRef ? false : true ;
		o.vmode = bSwapVertRef ? false : true ;
		
		o.root = oRoot && oRoot != null ? oRoot : o ;
		
		if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px";
		if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		
		o.minX = typeof minX != 'undefined' ? minX : null;
		o.minY = typeof minY != 'undefined' ? minY : null;
		o.maxX = typeof maxX != 'undefined' ? maxX : null;
		o.maxY = typeof maxY != 'undefined' ? maxY : null;
		
		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		
		o.root.onDragStart = new Function();
		o.root.onDragEnd = DragEnd;
		o.root.onDrag = Draggin;
		
		$(o).addEvent('mousedown', Drag.delay);
	},
	delay:function(e){
		var thisObj = this;
		var e = e || window.event;
		var t = self.DOOM.getTarget(e);
		alert(t.className);
		var cX = e.clientX;
		var cY = e.clientY;
		Drag.obj = this;
		$(document).addEvent('mouseup', Drag.end);
		var fn=function(){
			Drag.start(e, t, cX, cY);
		}
		
		if(self.DOOM.getTarget(e).parentNode.nodeName!='OBJECT' && self.DOOM.getTarget(e).nodeName!='OBJECT')
		tempTo = window.setTimeout(fn, 150);
	},
	start : function(e, t, cX, cY){
		self.DOOM.stopBubble(e);
		Drag.dragging=true;
		
		var o = Drag.obj;
				
		
		var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);
		
		o.lastMouseX = cX;
		o.lastMouseY = cY;
		
		if (o.hmode) {
			if (o.minX != null) o.minMouseX = o.lastMouseX - x + o.minX;
			if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + o.lastMouseX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + o.lastMouseX + x;
		}
		
		if (o.vmode) {
			if (o.minY != null) o.minMouseY = o.lastMouseY - y + o.minY;
			if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + o.lastMouseY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + o.lastMouseY + y;
		}

		document.onmousemove = Drag.drag;
		document.onmouseup = Drag.end;
	
		return false;
	},
	
	drag : function(e){
		
		e = Drag.fixE(e);
		var o = Drag.obj;
		
		var ey = e.clientY;
		var ex = e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;
		
		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
		
		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
		
		if (o.xMapper) nx = o.xMapper(y)
		else if (o.yMapper) ny = o.yMapper(x)
		
		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX = ex;
		Drag.obj.lastMouseY = ey;
		
		if(typeof Drag.obj.root.onDrag=='function')
			Drag.obj.root.onDrag(nx, ny);
		return false;
	},
	
	end : function(){
		window.clearTimeout(tempTo);
		tempTo = window.setTimeout(Drag.stDrag, 150);
		document.onmousemove = null;
		document.onmouseup = null;
		$(document).removeEvent('mouseup', Drag.end);
		//if(typeof Drag.obj.root.onDragEnd == "function")
			//Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},
	stDrag:function(){
		Drag.dragging = false;
	},
	fixE : function(e){
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

COMMUNICATION={};
COMMUNICATION.REQUEST = {
	send: function(url, method, vars, type, funktion){
		if (window.XMLHttpRequest) {
			var pt_rq = new XMLHttpRequest();
			if (pt_rq.overrideMimeType && type == "xml") {
				pt_rq.overrideMimeType('text/xml');
			}
		}
		else 
			if (window.ActiveXObject) {
				try {
					pt_rq = new ActiveXObject("Msxml2.XMLHTTP");
				} 
				catch (e) {
					try {
						pt_rq = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (e) {
					}
				}
			}
		if (!pt_rq) {
			return false;
		}
		function load_file(){
			if (method == "POST") {
				vars = encodeURI(vars);
				pt_rq.open('POST', PS + url, true);
				pt_rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				pt_rq.send(vars);
			}
			else {
				vars = encodeURI(vars);
				if (vars != null) 
					url = PS + url + "?" + vars;
				pt_rq.open('GET', url, true);
				pt_rq.send(null);
			}
			
			pt_rq.onreadystatechange = readystatechange;
		}
		function encodeURI(vars){
			//vars = vars.replace(/&nbsp;/gi, "\\t");
			return vars
		}
		function readystatechange(){
			if (pt_rq.readyState == 4) {
				if (pt_rq.status == 200) {
					if (typeof funktion == "function") {
						switch (type) {
							case "t":
								funktion(pt_rq.responseText);
								break;
							case "j":
								var json = JSON.parse(pt_rq.responseText);
								
								if (json.status==='error') {
									//alert('error: '+JSON.stringify(json.content));
									return false;	
								}
								funktion(json.content);
															
								break;
							case "x":
								funktion(pt_rq.responseXML);
								break;
						}
					}
					else {
						alert(pt_rq.responseText);
					}
				}
				else {
					delete pt_rq;
					pt_rq = null;
				}
			}
		}
		load_file(vars);
		return false;
	}
}
PS = '';
rq = COMMUNICATION.REQUEST;
