DOM={
  firstSibling:function(node){
    var obj=node.parentNode.firstChild;
    while(obj.nodeType!=1 && obj.previousSibling!=null) obj=obj.previousSibling;
    return (obj.nodeType==1)?obj:false;
  },
  lastSibling:function(node){
    var obj=node.parentNode.lastChild;
    while(obj.nodeType!=1 && obj.nextSibling!=null) obj=obj.nextSibling;
    return (obj.nodeType==1)?obj:false;
  },
  previousSibling:function(node){
    if(node.previousSibling!=null){
      var obj = node.previousSibling;
      while(obj.nodeType!=1 && obj.previousSibling!=null) obj=obj.previousSibling;
    }
    return (obj.nodeType==1)?obj:false;
  },
  nextSibling:function(node){
    if(node.nextSibling!=null){
      var obj=node.nextSibling;
      while(obj.nodeType!=1 && obj.nextSibling!=null) obj=obj.nextSibling;
      return (obj.nodeType==1)? obj: false;
    } else return false;
  },
  getText:function(node){
    if(!node.hasChildNodes()) return false;
    var regexp=/^s+$/;
    var obj=node.firstChild;
    while(obj.nodeType!=3 && obj.nextSibling!=null || regexp.text(obj.nodeValue) ) obj=obj.nextSibling;
    return (obj.nodeType==3)?obj.nodeValue:false;
  },
  setText:function(node,txt){
    if(!node.hasChildNodes()) return false;
    var regexp=/^s+$/;
    var obj=node.firstChild;
    while(obj.nodeType!=3 && obj.nextSibling!=null || regexp.test(obj.nodeValue)) obj=obj.nextSibling;
    if(obj.nodeType==3) obj.nodeValue=txt; else return false;
  },
  createText:function(elm,txt){
    var obj=document.createElement(elm);
    obj.appendChild(document.createTextNode(txt));
    return obj;
  },
  createLink:function(ref,txt){
    var obj=document.createElement('a');
    obj.appendChild(document.createTextNode(txt));
    obj.setAttribute('href',ref);
    return obj;
  },
  addEvent: function(elm, evType, fn, useCapture){
    if(useCapture==null) useCapture=false;
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent) {
      var r = elm.attachEvent('on' + evType, fn);
      return r;
    } else {
      elm['on' + evType] = fn;
    }
  },
  noBubble:function(e){
    if(window.event && window.event.cancelBubble) window.event.cancelBubble = true;
    if (e && e.stopPropagation) e.stopPropagation();
  },
  noDefaultAct:function(e){
    if(window.event && window.event.returnValue) window.event.returnValue = false;
    if (e && e.preventDefault) e.preventDefault();
  },
  cancelClick:function(e){
    if (window.event){
            window.event.cancelBubble = true;
            window.event.returnValue = false;
    }
    if (e && e.stopPropagation && e.preventDefault){
            e.stopPropagation();
            e.preventDefault();
    }
  }
}

 //CSS Class Functions
css={
  classCheck:function(obj,cssClass){
    var found=false;
    if(!obj.className) return false;
    var classes=obj.className.split(' ');
    for(var i=0; i<classes.length; i++) if(classes[i]==cssClass) found=true;
    return found;
  },
  classAdd:function(obj,cssClass){
    if(!css.classCheck(obj,cssClass) ) obj.className+=obj.className?' ' +cssClass:cssClass;
  },
  classDel:function(obj,cssClass){
    var classMatch=obj.className.match(' '+cssClass)?' '+cssClass:cssClass;
    obj.className=obj.className.replace(classMatch,'');
  },
  classSwap:function(obj,cssClass1,cssClass2){
    obj.className=(!css.classCheck(obj,cssClass1) )? obj.className.replace(cssClass2,cssClass1): obj.className.replace(cssClass1,cssClass2);
  }
}

dBug={
  divID:'debug_console',
  init:function(){
    if(dBug.div) dBug.stop();
    dBug.div=document.createElement('div');
    dBug.div.setAttribute('id',dBug.divID);
    dBug.style();
    dBug.div.className="console";
    dBug.div.ondblclick=function(){
      if(confirm("Close this console?") ) dBug.stop();
    }
    document.body.insertBefore(dBug.div,document.body.firstChild);
  },
  set:function(bug){
    if(!dBug.div) dBug.init();
    dBug.div.innerHTML+=bug+'<br />\n';
  },
  stop:function(){
    if(dBug.div){
      dBug.div.parentNode.removeChild(dBug.div);
      dBug.div=null;
    }
  },
  style:function(){
    var o=dBug.div;
    if(!o)return;
    o.style.position="absolute";
    o.style.backgroundColor="white";
    o.style.color="black";
    o.style.border="4px double red";
    o.style.height="auto";
    o.style.width="auto";
    o.style.zIndex="200";
  }
}

page={
  getX:function(e){
    e = e || window.event;
    return e.pageX || (document.documentElement && document.documentElement.scrollLeft) + e.clientX || e.clientX + document.body.scrollLeft;
  },
  getY:function(e){
    e = e || window.event;
    return e.pageY || (document.documentElement && document.documentElement.scrollTop) + e.clientY || e.clientY + document.body.scrollTop;
  },
  getElmX:function(e){
    return ( e && e.layerX) || window.event.offsetX;
  },
  getElmY:function(e){
    return ( e && e.layerY) || window.event.offsetY;
  },
  getHeight:function(){
    return document.body.scrollHeight;
  },
  getWidth:function(){
    return document.body.scrollWidth;
  },
  getScrollX:function(){
    return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || document.body.scrollLeft;
  },
  getScrollY:function(){
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
  }
}

