/*!************************** rbmCore.js *******************************
**** Version 1.05.0002
**** last changed 18.03.2007
**** (c) 2007,2008 Bernd Rudolf, rbm digitaltechnik, www.rbm.de
**********************************************************************/
//
// 14.12.2007 getElementByClassName added
// 10.02.2008 getElementsByName added
// 14.02.2008 getElementByNameStartingWith added
// 18.03.2008 getElementsByClassName now supports multiple classes
//			Attention: matches class by indexOf!!
// 21.03.2008	createEventListener added
// 22.03.2008	$fx() now calls $ to retrieve Element
//************************************************************************


var $A = Array.from = function(iterable) {
if (!iterable) return [];
 if (iterable.toArray) {
 return iterable.toArray();
 } else {
 var results = [];
 for (var i = 0; i < iterable.length; i++)
 results.push(iterable[i]);
 return results;
 }
} 
 
Function.prototype.bind = function() {
 var __method = this, args = $A(arguments), object = args.shift();
 return function() {
 	return __method.apply(object, args.concat($A(arguments)));
 	}
} 



function $(element) {
	element = (typeof(element) == "object") ? element : document.getElementById(element);
	if(element && element.nodeType == 3) return element; 	//extending textNodes sucks in IE

	if(element && typeof (element.debug) == "undefined")	{
		
		element.debug = function()	{
			alert(element.id + ": " + element.innerHTML + "\n" + element.attributes);
		}	
		
		element.styles = function()	{
			var st = "";
			for (var p in this.style)	{
				if(this.style[p] != "" && p.indexOf("get") == -1)
					st = st + " - " + p + ": " + this.style[p];
			}
			return st;
		}


		element.getElementById = function(id)	{
			var allChilds = this.getElementsByTagName("*");
			if(allChilds.length == 0 && this.all)
				allChilds = this.all;
			for(this.i = 0; this.i < allChilds.length; this.i++)	{
				if(allChilds[this.i].id == id)
					return $(allChilds[this.i]);
				
			}
		}


		element.getElementsById = function(id)	{				// searches all Elements with an id starting with id
			var allChilds = this.getElementsByTagName("*");
			var returns = [];
			for(this.i = 0; this.i < allChilds.length; this.i++)	{
				if((allChilds[this.i].id.length > id.length) && (allChilds[this.i].id.substring(1, id.length) == id))
					returns.push($(allChilds[this.i]));
			}
			return returns;
		}

		element.getElementsByIdStartingWith = function(searchName)	{
			var allChilds = this.getElementsByTagName("*");
			var returns = [];
			for(this.i = 0; this.i < allChilds.length; this.i++)	{
				if(!!(allChilds[this.i].id))	{
					if(allChilds[this.i].id.substr(0, searchName.length) == searchName)
						returns.push($(allChilds[this.i]));
				}
			}
			return returns;
		}


		element.getElementByClassName = function(className)	{
			var allChilds = this.getElementsByTagName("*");
			for(this.i = 0; this.i < allChilds.length; this.i++)	{
				var myClasses = allChilds[this.i].className.split(" ");
				for(var x=0; x < myClasses.length; x++)
					if(myClasses[x] == className)
						return $(allChilds[this.i]);
			}
		}


		element.getElementsByClassName = function(className)	{
			var allChilds = this.getElementsByTagName("*");
			var returns = [];
			for(this.i = 0; this.i < allChilds.length; this.i++)	{
				var myClasses = allChilds[this.i].className.split(" ");
				for(var x=0; x < myClasses.length; x++)
					if(myClasses[x] == className)
						returns.push($(allChilds[this.i]));
			}
			return returns;
		}

		element.getElementByName = function(searchName)	{
			var allChilds = this.getElementsByTagName("*");
			for(this.i = 0; this.i < allChilds.length; this.i++)	{
				if(allChilds[this.i].name == searchName)
					return $(allChilds[this.i]);
			}
		}

		element.getElementsByNameStartingWith = function(searchName)	{
			var allChilds = this.getElementsByTagName("*");
			var returns = [];
			for(this.i = 0; this.i < allChilds.length; this.i++)	{
				if(!!(allChilds[this.i].name))	{
					if(allChilds[this.i].name.substr(0, searchName.length) == searchName)
						returns.push($(allChilds[this.i]));
				}
			}
			return returns;
		}


		return element;
		
	}
	return (!!element) ? element: null;
}	
	
	
function $fx(element) {
//	element = (typeof(element) == "object") ? element : document.getElementById(element);

	element = $(element);
	if(element && typeof (element.visibility) == "undefined")	{
	


		element.adjustSize = function(w, h) { return null }
	
		element.setOpacity = function(op)	{
				this.style["filter"] = "alpha(opacity=" + op + ")";
				this.style["opacity"] = op / 100;
				this.op = op;
				return op;
		}
	
		element.show = function(bShow)	{
			if(bShow)	{
				this.style["visibility"] = "visible";
				this.visibility = 1;
			}
			else	{
				this.style["visibility"] = "hidden";
				this.visibility = 0;
			}
		}

		element.setDisplay = function(bDisplay)	{
			if(bDisplay)	{
				this.style["display"] = "block";
//				this.displayed = true;
			}
			else	{
				this.style["display"] = "none";
//				this.displayed = false;
			}
		}

		element.toggleDisplay = function(gVariable)	{
				
			if(this.style["display"] == "" || this.style["display"] == "none")	{
				this.style["display"] = "block"
				gVariable = true;
			}
			else	{
				this.style["display"] = "none";
				gVariable = false;
			}
		
		}

	
		element.move = function(x, y, transition)	{
//			this.style["position"] = "absolute";
			if(!!transition)	{
//XXX	hier moving transition einfügen!
				alert("moving transition not implemented yet");
			}
			else	{
				this.style["left"] = x + "px";
				this.style["top"] = y + "px";
			}
		}

		element.size = function(w, h)	{
				if(w > this.offsetWidth)	{
					this.style["width"] = w + "px";
					if(h)
						this.style["height"] = h + "px";
					this.adjustSize(w, h);
				}
				else	{
					this.adjustSize(w, h);
					this.style["width"] = w + "px";
					if(h)
						this.style["height"] = h + "px";
				}
		}
		
		

		element.wipe = function()	{	// d = + 1: in ; d = -1 : out
			if(this.fxx == 100 ||  this.fxx == 0)	{	//do not reenter function
				this.fxx = 0;
				this.xMax = 100;
				if(this.offsetWidth > 0)	{
					this.delta = this.offsetWidth;
					this.start = this.offsetWidth;
					d = -1;
				}
				else	{
					this.start = 0;
					d = 1;
				}
				this.wiping(d);
			}
		}
		
		element.wiping = function(d)	{
			if(this.fxx < this.xMax)	{
				this.width = this.start + this.delta * d * this.fxfunction() / 100;		//this.margin + d * this.step
				this.style["width"] = this.width + "px";
				if (this.timeStep > 0)
					this.timer = window.setTimeout(this.wiping.bind(this, d), this.timeStep)
				else
					this.wiping(d);
			}
		}

	}		
	return element;
}
	
function $exec(text){
	if (window.execScript){
		window.execScript(text);
	} else {
		var script = document.createElement('script');
		script.setAttribute('type', 'text/javascript');
		script.text = text;
		document.head.appendChild(script);
		document.head.removeChild(script);
	}
	return text;
}


function createEventListener(obj, evt, handler, captures)	{
     if ( obj.addEventListener )	{
       obj.addEventListener(evt, handler, captures);
     }
	else	{	       // IE
       obj.attachEvent(evt, handler);
	}     
}
