/**
* DOM Library based upon dhtmlcentral.com dhtml library by
* Thomas Brattli.  DOM Library by David Schonztler. Free to
* use. Please include comments. For latest version/updates:
* [ www.stilleye.com | madhatter@pullman.com ]
*/

// check for browsers that support the document object model
function checkDom()
{
	this.name=navigator.appName.toLowerCase()
	this.ver=navigator.appVersion.toLowerCase()
	this.opera=(this.name=="opera")?1:0
	this.dom=(document.getElementById&&!this.opera)?1:0
	this.ie=(document.all)?1:0
	this.mozilla=(document.all)?0:1;
	this.ie6=(this.dom&&this.ie&&this.ver.indexOf('msie 6'))?1:0
	this.ie5=(this.dom&&this.ie&&!this.ie6)?1:0
	this.ns4=(document.layers)?1:0
	this.ns6=(this.dom&&!this.ie)?1:0
	this.ns=(this.ns4||this.ns6)?1:0
	this.bw=(this.dom||this.ie||this.ns||this.opera)?1:0
}
bw = new checkDom()

function getPageSize()
{
	this.x = document.documentElement.offsetWidth||document.body.offsetWidth||innerWidth||0
	this.y = document.documentElement.offsetHeight||document.body.offsetHeight||innerHeight||0
	this.x2 = parseInt(this.x/2)||0
	this.y2 = parseInt(this.y/2)||0
	this.sx = document.documentElement.scrollWidth||0
	this.sy = document.documentElement.scrollHeight||0
}
var pg

function getCoords(e)
{
	if(bw.ie) e = event
	this.x = e.clientX
	this.y = e.clientY
}

// make dom object
function makeDom(name)
{
	if(!document.getElementById) return null
	this.name = name
	this.evnt = document.getElementById(name)
	if(! this.evnt) return null
	this.css = this.evnt.style
	this.x = this.css.pixelLeft || this.evnt.offsetLeft
	this.y = this.css.pixelTop || this.evnt.offsetTop
	this.w = this.css.pixelWidth || this.evnt.offsetWidth
	this.h = this.css.pixelHeight || this.evnt.offsetHeight

	this.id = name
	this.obj = name + 'Object'; eval(this.obj + '=this')

	makeDom.prototype.moveTo = function(x,y)
	{
		x = parseInt(x); y = parseInt(y)
		this.css.left = x+'px'
		this.css.top = y+'px'
		this.x = x
		this.y = y
	}
	makeDom.prototype.moveBy = function(x,y)
	{
		x = parseInt(x); y = parseInt(y)
		this.moveTo(this.x+x,this.y+y)
	}
	makeDom.prototype.centerIt = function(x,y,toDiv)
	{
		pg = new getPageSize()
		bigX = toDiv ? document.getElementById(toDiv).offsetWidth : pg.x
		bigY = toDiv ? document.getElementById(toDiv).offsetHeight : pg.y
		this.moveTo(x?parseInt((bigX-this.w)/2):this.x,y?parseInt((bigY-this.h)/2):this.y)
	}
	makeDom.prototype.show = function()
	{
		this.css.display = 'inline'
	}
	makeDom.prototype.hide = function()
	{
		this.css.display = 'none'
	}
	makeDom.prototype.vis = function()
	{
		this.css.visibility!='visible' ? this.show() : this.hide()
	}
	makeDom.prototype.clipTo = function(t,r,b,l,sW,sH)
	{
		this.cT = t; this.cR = r; this.cB = b; this.cL = l
		a = arguments
		for(k=0;k<a.length;k++) a[k] = a[k]>=0 ? a[k]+'px' : a[k]
		this.css.clip = 'rect('+t+','+r+','+b+','+l+')'
		if(sW) this.size(r,this.h)
		if(sH) this.size(this.w,b)
	}
	makeDom.prototype.clipBy = function(t,r,b,l,sW,sH)
	{
		this.clipTo(t+this.cT,r+this.cR,b+this.cB,l+this.cL,sW,sH)
	}
	makeDom.prototype.bg = function(clr,img,attribs)
	{
		if(img) this.css.background =  (clr ? clr : '') + (img ? ' url('+img+')' : ' ') + (attribs ? ' '+attribs : '')
		else this.css.backgroundColor = clr
	}
	// I know innerHTML is not standard, but there is no better way, and *hopefully* innerHTML becomes a standard
	makeDom.prototype.writ = function(txt,where)
	{
		this.evnt.innerHTML = where ? where>0 ? this.evnt.innerHTML + txt : txt + this.evnt.innerHTML : txt
	}
	makeDom.prototype.size = function(w,h)
	{
//		this.css.width = this.w = w>0 ? w : this.w
		if (bw.mozilla)
			this.css.height = this.h = h>0 ? h+"px" : this.h
		else
			this.css.height = this.h = h>0 ? h : this.h
	}
	makeDom.prototype.sizeBy = function(w,h)
	{
		this.size(this.w+w,this.h+h)
	}
}



/**
* addEvent & removeEvent functions..
* http://ejohn.org/projects/flexible-javascript-events/
*/
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
    obj.attachEvent( "on"+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( "on"+type,obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
//addLoadEvent(function() {
//  /* more code to run on page load */ 
//});


