// browser detection
var ie=document.all;
var nn6=document.getElementById&&!document.all;
var ie8=(document.documentMode==8);

// create useful function that doesnt exist in standard DOM 'insertAfter'
function insertAfter(referenceNode, newNode) {
	referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

// quick reference to document.body 
function body() {
	return initElement(document.body);
}

// returns a unqiue element by its id, or false
function $(id) {
	return initElement(document.getElementById(id));
}

// returns the elements as an array, by type, optionally class name, starting from a given element
function $e(na, cl, el) {
	el = el || body();
	el = el.getElementsByTagName(na);

// check all the elements if they contain the class
	var ea = new Array();
	for(var i=0,j=el.length; i<j; i++) {
		if (cl && !hasClass(el[i], cl))
			continue;

		ea[ea.length]=initElement(el[i]);
	}

// return the subset array
	return ea;
}

// short form for finding all elements with a given class
function $c(cl, el) { return $e('*', cl, el); }

// check if an element has the specified class
function hasClass(el, cl) {
	if (!cl)
		return true;

	var a = el.className.split(' ');

	for(var i=0,j=a.length; i<j; i++)
		if (a[i] == cl)
			return true;

	return false;
}


function addClass(el, cl) {
	if (hasClass(el, cl))
		return;

	el.className += (el.className.length ? ' ' : '') + cl;
}

function remClass(el, cl) {
	var a = el.className.split(' ');

	for(var i=0,j=a.length; i<j; i++)
		if (a[i] == cl)
			a[i] = '';

	el.className = a.join(' ');
}


function initElement(el) {
	if (!el)
		return false;

	el.hasClass = function(cl) { return hasClass(this, cl); }
	el.addClass = function(cl) { addClass(this, cl); }
	el.remClass = function(cl) { remClass(this, cl); }

	el.$e = function(na, cl) {
		return $e(na, cl, this);
	}

	el.$c = function(cl) {
		return $e('*', cl, this);
	}

	el.parent = function() {
		return initElement(this.parentNode);
	}

	return el;
}

function _dom1(n, a) {
	var e = document.createElement(n);

	for(var i=0,j=a.length; i<j; i++)
	for (var i = 0, l = a.length; i < l; ++i) {
		if (a[i].addClass)
			e.appendChild(a[i]);
		else
			for(var b in a[i])
				e[b] = a[i][b];
	}

	return initElement(e);
}

// creats a given node, assigning all the arguemnts to it, ie create('div', {id:'eee'});
function create(n, args) {
	var a = new Array();
	for (var i = 1, l = arguments.length; i < l; ++i)
		a[i-1] = arguments[i];

	var e = _dom1(n, a);

	return e;
}



// loads a new js into the document
function load_js(url) {
	var js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('language', 'JavaScript');
	js.setAttribute('src', url);
	document.getElementsByTagName('head')[0].appendChild(js);
}







function absPos(el) {
// assign inital values
	var x = 0, y = 0;

// check if they have a parent element
	if (el.offsetParent) {
	// loop through each parent element
		while (el.offsetParent) {
		// increment the position by this parent element	
			x += el.offsetLeft - el.scrollLeft;
			y += el.offsetTop - el.scrollTop;

			var position='';

			if (el.style && el.style.position)
				position = el.style.position.toLowerCase();

			if ((position == 'absolute') || (position == 'relative'))
				break;

			while (el.parentNode != el.offsetParent) {
				el = el.parentNode;
				x -= el.scrollLeft;
				y -= el.scrollTop;
			}

			el = el.offsetParent;
		}
	}
	else {
		if (el.x)
			x += el.x;

		if (el.y)
			y += el.y;
	}

	return {'x':x,'y':y};
}

/*



	e.add = function(n) {
		var a = new Array();
		for (var i = 1, l = arguments.length; i < l; ++i)
			a[i-1] = arguments[i];

		var e = _dom1(n, a);

		this.appendChild(e);

		return e;
	};







function initElement(e) {
	e.hasClass = function(c) {
		if (!c)
			return true;

		var a = this.className.split(' ');

		for (var i = 0; i < a.length; ++i) {
			if (a[i] == c)
				return true;
		}

		return false;
	};

	e.addClass = function(c) {
		if (this.hasClass(c))
			return;

		this.className += (this.className.length ? ' ' : '') + c;
	};

	e.remClass = function(c) {
		var a = this.className.split(' ');

		for (var i = 0; i < a.length; ++i)
			if (a[i] == c)
				a[i] = '';

		this.className = a.join(' ');
	};

	e.$e = function(t, c) {
		return $e(t, c, this);
	};

	e.$c = function(c) {
		return $e('*', c, this);
	};

	e.p = function() {
		return initElement(this.parentNode);
	};

	e.add = function(n) {
		var a = new Array();
		for (var i = 1, l = arguments.length; i < l; ++i)
			a[i-1] = arguments[i];

		var e = _dom1(n, a);

		this.appendChild(e);

		return e;
	};

	return e;
};













function $
function addClassName (id, classname) {
   var e;
   if (typeof(id) == 'string') {e = this.getElementById(id);} 
   else {e = id;}

   if (!e || typeof e.className != 'string') {
      throw "Cannot add class to element " + id;
   }

//
   if (!e.className.match(new RegExp('\\b' + classname + '\\b'))) {
      e.className += ' ' + classname;
   }
}
*/


