/******************************************************* 
*	2007 ballyhoos.com.au
*	contact scott@ballyhoos.com.au
*
*	DOM 
*
****************************************************** */

var dom = {
	
	/*******************************
	get an element by ID 
	***************************** */
	byId : function(id, obj)
	{
		if(!obj){
			obj = document;
		}
		return obj.getElementById(id);
	},
	
	
	byTag : function(tag, obj)
	{
		if(!obj) obj = document;
		
		return obj.getElementsByTagName(tag);
	},


	
	/* ************************************
	return all tags with this class, SINGLE VALUES ONLY CHANGE
	************************************* */
	byClass : function(classname, obj)
	{
		//	store found class objects
		var classObjs = [];
		
		if(!obj){
			var obj = document;
		}
		// get all elements under passed obj
		var elm = dom.byTag("*", obj);
				
		for (var e = 0; e < elm.length; e ++) {
			if(dom.hasClass(elm[e], classname)){
				classObjs.push(elm[e]);
			}
		}
		return classObjs;
	},
	
	
	/* ************************************
	get all values or class attribute
	************************************* */
	getClass : function(obj)
	{
		// tests for IE naming covention that differs from FF
		var classes = dom.hasAttr(obj, ((document.all) ? "className" : "class"), true);
		if( classes ){
			return classes.split(" ");
		}
		return false;
	},
	
	
	/* ************************************
	tests to see if class exists
	************************************* */
	hasClass : function(obj, classname)
	{
		var classes = dom.getClass(obj);
		if( dom.inArray( classname, classes ) ){
			return true;
		}
		return false;
	},
	
	
	hasAttr : function(obj, type, ret)
	{
		// typical MS IE bug, "for" will return NULL
		// this bug extends IE5 - IE 7, when will this end? 
		if( type == "for" && document.all ){
			return ( !obj.attributes["for"].nodeValue ? false : ((!ret) ? true : obj.attributes["for"].nodeValue)) ;
		}
		return ( !obj.getAttribute(type) ? false : ((!ret) ? true : obj.getAttribute(type))) ;
	},
	
	
	/* **********************************************
	not really a dom event, but a very handy function
	********************************************** */
	inArray : function( value, array, retKeys )
	{
		var keys = [];
		
		for(var i = 0; i < array.length; i++) {
			if(array[i] == value){
				/* return the found keys, if set */
				if(retKeys){
					keys.push(i);
				}else{
					return true;
				}
			}
		}
		return (retKeys) ? keys : false;
	},
	
	trim : function(str)
	{
		return str.replace(/^\s+|\s+$/g, '');
	}


	
}