/**
 * The core of the joink library, this is where the 'magick' happens ;)
 * 
 */
 
 var joink = new Joink();
 
 function Joink(){
 	// singleton class
 	this.cursor = [];
 }
 
 /*
 function $(o){
 	if (typeof o == 'object'){
 		return o;
 	}else if(document.getElementById(o)){
 		return document.getElementById(o);
 	}else{
 		return false;
 	}
 }*/
 
 // getElementsByClassName
 function $$(c, p){
 	var f = [];
 	var e = [];
 	var r = new RegExp(c);
 	if (p){
	 	if (p.tagName){
	 		e = document.getElementsByTagName('a')
	 	}else if (p.parent){
	 		_$$($(p.parent), e);
	 	}else{
	 		_$$(document, e);
	 	}
 	}else{
 		_$$(document, e);
 	}
 	for (var n=0;n<e.length;n++){
 		if (r.test(e[n].className)){
 			f.push(e[n]);
 		}
 	}
 	if (f.length > 0){
 		return f;
 	}else{
 		return false;
 	}
 }
 
 // getChildNodes from o and push in array a
 function _$$(o, a){
 	if (typeof o == 'object'){
	 	var x = o.childNodes;
		for (var n=0;n<x.length;n++){
			a.push(x[n]);
			_$$(x[n], a);
	 	}
 	}
 }
  
 function setStyle(o, p){
    for (var i in p){
	   o.style[i] = p[i];
	}		
 }
 
 function bind(e, f){
    return function() { f.call(e); }
 }
 
 function getPos(o) {
	var curleft = curtop = 0;
	if (o.offsetParent) {
		curleft = o.offsetLeft
		curtop = o.offsetTop
		while (o = o.offsetParent) {
			curleft += o.offsetLeft
			curtop += o.offsetTop
		}
	}
	return [curleft,curtop];
 } 
 
 function getMouseCoords(e){
 	if(!e){
		e = window.event;
	}
    joink.cursor[0] = e.clientX || e.pageX;
    joink.cursor[1] = e.clientY || e.pageY;
 }