/**
 * @author giuseppe
 */
try
{ var test = (NETJOHNHENRY.name == 'NETJOHNHENRY'); }
catch (e)
{ NETJOHNHENRY = {}; }


NETJOHNHENRY.dom = new Object();

NETJOHNHENRY.dom.recurseAllChildNodes 	= function ( node , injected_function, params)
{
	if( node )
	{ 
		injected_function( node, params ); 
		for( var i= 0; i< node.childNodes.length; i++ )
		{								
			var childnode = node.childNodes[i];
			if( childnode != undefined && (childnode.nodeType == childnode.ELEMENT_NODE || childnode.nodeType == 1) ){		// <- IE doesn't support node.ELEMENT_NODE therefore || node.nodeType == 1			
				NETJOHNHENRY.dom.recurseAllChildNodes(childnode, injected_function, params);
			}
		}

	}	
}


//The difference between this function and the above is the scope of injected_function
//here the injected function is run within the scope of the object that declares the function
//while the above is run with the scope of the window object.
//The following has also a return of the original node.

NETJOHNHENRY.dom.recurseAllChildNodesWithDelegate 	= function ( node , scope, injected_function, params)
{
	if( node )
	{ 
		NETJOHNHENRY.delegate(scope, injected_function, params);
		for( var i= 0; i< node.childNodes.length; i++ )
		{								
			var childnode = node.childNodes[i];
			if( childnode != undefined && (childnode.nodeType == childnode.ELEMENT_NODE || childnode.nodeType == 1) ){		// <- IE doesn't support node.ELEMENT_NODE therefore || node.nodeType == 1	

				try{params.currentNode = childnode}catch(e){};

				node.replaceChild(NETJOHNHENRY.dom.recurseAllChildNodesWithDelegate(childnode, scope, injected_function, params),node.childNodes[i]);
				//#note: we are using the replace child because IE complains with the following code
				//node.childNodes[i] = NETJOHNHENRY.dom.recurseAllChildNodesWithDelegate(childnode, scope, injected_function, params);
			}
		}

	}
	return node;	
}