
NJ = new function()
{
	
	this.addEventHandler = function(obj,evt,fn)
	{
		if (obj.addEventListener)
			obj.addEventListener(evt,fn,false);
		else if (obj.attachEvent)
			obj.attachEvent('on'+evt,fn);
	}

	this.removeEventHandler = function(obj,evt,fn)
	{
		if (obj.removeEventListener)
			obj.removeEventListener(evt,fn,false);
		else if (obj.detachEvent)
			obj.detachEvent('on'+evt,fn);
	}

	this.autoReload = function(secs)
	{
		if(!secs) secs = 120;
		this.addEventHandler(window,'load',function() {setTimeout('document.location.reload();',secs*1000)});
	}

	/*
	*	calculateOffsetTop(e) - calculates the correct offsetTop value for the specified element.
	*	This should be used instead of e.offsetTop as IE calculates the value incorrectly.
	*/
	this.calculateOffsetTop = function(e)
	{
		var cot = 0;
		do
		{
			cot+=e.offsetTop;
		}
		while(e = e.offsetParent);
		return cot;
	}			

	/*
	*	calculateOffsetLeft(e) - calculates the correct offsetLeft value for the specified element.
	*	This should be used instead of e.offsetLeft as IE calculates the value incorrectly.
	*/
	this.calculateOffsetLeft = function(e)
	{
		var col = 0;
		do
		{
			col+=e.offsetLeft;
		}
		while(e = e.offsetParent);
		return col;
	}			

	this.findPos = function(obj)
	{
		var curleft = curtop = 0;
		if (obj.offsetParent)
		{
			do
			{
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
			return [curleft,curtop];
		}
	}

	this.getStyle = function(e)
	{
		if(e.currentStyle) return e.currentStyle;
		return window.getComputedStyle(e,null);
	}

	this.noPx = function(value)
	{
		if(!value) return 0;
		return new Number( value.replace(/px/,"") );
	}

	this.loadStyleSheet = function(href)
	{
		var l = document.createElement('link');
		l.setAttribute('rel','stylesheet');
		l.setAttribute('type','text/css');
		l.setAttribute('href',href);
		document.getElementsByTagName('HEAD')[0].appendChild(l);
	}
	
	this.css = function(a,o,c1,c2)
	{
		switch (a)
		{
		    case 'swap':
		    	o.className=!this.css('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			    break;
		    case 'add':
		    	if(!this.css('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		    	break;
		    case 'remove':
		    	var rep=o.className.match(' '+c1)?' '+c1:c1;
		    	o.className=o.className.replace(rep,'');
		    	break;
		    case 'check':
		    	return new RegExp('\\b'+c1+'\\b').test(o.className)
		    break;
		}
	}

	this.selectElementsByClass = function(element,className,a)
	{
		// element - element to process
		// className - class to match
		// a - Array to append matching elements to
		
		if(element.className==className) a[a.length]=element;
		
		for(var n=0;n<element.childNodes.length;n++)
		{
			if(element.childNodes[n].nodeType==1) this.selectElementsByClass(element.childNodes[n],className,a);
		}
	}
												
}

