if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	var isMoz=true;
	HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
		case 'BeforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
		case 'AfterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
 		case 'BeforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
		case 'AfterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function (where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}

	HTMLElement.prototype.__defineGetter__( "runtimeStyle", function ()
		{
			return this.style;
			// dit werkt niet, getOverrideStyle bestaat niet
			// this/ownerDocument.defaultView.getOverrideStyle( this, null );
		} );
	
	HTMLElement.prototype.__defineGetter__("parentElement", function ()
		{
			return this.parentNode;
		});


	vdAttachEvent = function(eventName, handlerName) 
	{
		if (eventName.substr(0,2)=='on') {
			eventName=eventName.substr(2, eventName.length-2);
		}
		if (eventName.substr(0,3)=='key') {
			// it seems mozilla only listens to these in the document object
			document.addEventListener(eventName, handlerName, true);
		} else {
			this.addEventListener(eventName, handlerName, true);
		}
	}
	HTMLElement.prototype.attachEvent=vdAttachEvent;
	document.attachEvent=vdAttachEvent;
	window.attachEvent=vdAttachEvent;
} else {
	var isMoz=false;
}

function getNextElementByTagName(element, tagName, notfirst) {
	// starts at the given element, and walks depth first through
	// the dom. It doesn't walk up the dom tree, it stays in the 
	// current level.
	var tempEl;
	if (element) {
		if ((element.tagName==tagName) && notfirst) {
			return element;
		} else {
			tempEl=getNextElementByTagName(element.firstChild, tagName, true);
			if (!tempEl) {
				if (element.nextSibling) {
					return getNextElementByTagName(element.nextSibling, tagName, true);
				} else {
					return false;
				}
			} else {
				return tempEl;
			}
		}
	}
}

function getFirstChildByTagName(element, tagName) {
	// starts at the firstChild of the given element
	// doesn't walk up, so the element itself and its siblings
	// are never returned
	var tempEl;
	if (element) {
		return getNextElementByTagName(element.firstChild, tagName, true);
	} else {
		return false;
	}
}

function getNextSiblingByTagName(element, tagName) {
	var found=false;
	if (element) {
		while (!found && (element=element.nextSibling)) {
			if (element.tagName==tagName) {
				found=element;
			}
		}
	}
	return found;
}

function getPreviousSiblingByTagName(element, tagName) {
	var found=false;
	if (element) {
		while (!found && (element=element.previousSibling)) {
			if (element.tagName==tagName) {
				found=element;
			}
		}
	}
	return found;
}

function getParentElementByTagName(element, tagName) {
	var found=false;
	if (element) {
		while (!found && (element=element.parentNode)) {
			if (element.tagName==tagName) {
				found=element;
			}
		}
	}
	return found;
}

function getEvent(evt) {
	return (evt) ? evt : ((window.event) ? window.event : null);
}

if (!window.vdCancelEvent) {
	function vdCancelEvent(evt) {
		evt.cancelBubble=true;
		if (evt.returnValue) {
			evt.returnValue=false;
		} else if (evt.preventDefault) {
			evt.preventDefault();
		} else {
			return false;
		}
	}
}

if (!window.addEvent) {
	function addEvent(el, name, method) {
		if (el.attachEvent) {
			return el.attachEvent('on'+name, method);
		} else {
			return el.addEventListener(name, method, false);
		}
	}
}

if (!window.removeEvent) {
	function removeEvent(el, name, method) {
		if (el.detachEvent) {
			return el.detachEvent('on'+name, method);
		} else {
			return el.removeEventListener(name, method, false);
		}
	}
}

function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
}

// DF1.1 :: domFunction 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
//******************************************************

//DOM-ready watcher
function domFunction(f, a)
{
	//initialise the counter
	var n = 0;
	
	//start the timer
	var t = setInterval(function()
	{
		//continue flag indicates whether to continue to the next iteration
		//assume that we are going unless specified otherwise
		var c = true;

		//increase the counter
		n++;
	
		//if DOM methods are supported, and the body element exists
		//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] 
		//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
		{
			//set the continue flag to false
			//because other things being equal, we're not going to continue
			c = false;

			//but ... if the arguments object is there
			if(typeof a == 'object')
			{
				//iterate through the object
				for(var i in a)
				{
					//if its value is "id" and the element with the given ID doesn't exist 
					//or its value is "tag" and the specified collection has no members
					if
					(
						(a[i] == 'id' && document.getElementById(i) == null)
						||
						(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
					) 
					{ 
						//set the continue flag back to true
						//because a specific element or collection doesn't exist
						c = true; 

						//no need to finish this loop
						break; 
					}
				}
			}

			//if we're not continuing
			//we can call the argument function and clear the timer
			if(!c) { f(); clearInterval(t); }
		}
		
		//if the timer has reached 60 (so timeout after 15 seconds)
		//in practise, I've never seen this take longer than 7 iterations [in kde 3 
		//in second place was IE6, which takes 2 or 3 iterations roughly 5% of the time]
		if(n >= 60)
		{
			//clear the timer
			clearInterval(t);
		}
		
	}, 250);
};


