
/**
 * This function is called from within the HTML tree and recursivly walks through the dom to add the given classname to the given 
 * elements with the exception of the elements (and their childNodes) which ID's are included in the given exclude array.
 * 
 * @param className The name of the CSS class to add to alle child elements of the given ID element.
 * @param startId The ID of the element whose himself and its childNodes will get the given CSS class.
 * @param inclusive Whether the top element should get the class too or not.
 * @param exclude An array (optional) with zero or more ID's of elements to exclude from the process (do not get the given CSS class) 
 * @return nothing
 */
function addClassNames(className, startId, inclusive, exclude)
{
	//zoek de node van de className op, geef verder alles door
	addClassRecursivly(className, document.getElementById(startId), inclusive, exclude);
}


/**
 * Recursive helper function of the above function to recursivly traverse the DOM tree and
 * add classes to the elements. Requires the MOOTOOLS function addClass() 
 * @param className The classname to add.
 * @param startNode The node to start with.
 * @param inclusive Whether the top element should have the class too.
 * @param exclude The node IDs to exclude.
 * @return nothing
 */
function addClassRecursivly(className, startNode, inclusive, exclude)
{
	//als er geen exclude is opgegeven maak dan hier een nieuwe array
	if (exclude == undefined) {
		exclude = new Array();
	}
	
	if (inclusive == undefined)
	{
		inclusive = true;
	}

	//geef node met startId de class className
	var currentNode = startNode;
	
	if (inclusive)
	{
		//to prevent polluting all elements with lots of javascripts, we do not use mootools addClass function (anymore).
		var spacer = "";
		if (currentNode.className != "")
		{
			spacer = " ";
		}
		
		if (currentNode.className.indexOf(className) == -1)
		{
			currentNode.className = currentNode.className + spacer + className;
		}

	}
	
	//dan haal childNodes van node met startId op
	var childNodes2 = null;
	if( currentNode == null )
	{
		alert(currentNode.parentNode.innerHTML);
	}
	if ((currentNode.tagName != "IFRAME") && (currentNode.tagName != "iframe"))
	{
		childNodes2 = currentNode.childNodes;
	}
	else
	{
		try
		{
			var spacer = "";
			if (currentNode.contentWindow.document.body.className != "")
			{
				spacer = " ";
			}
		
			//to prevent polluting all elements with lots of javascripts, we do not use mootools addClass function (anymore).
			//$(currentNode.contentWindow.document.body).addClass(className);
			currentNode.contentWindow.document.body.className = currentNode.contentWindow.document.body.className + spacer + className;
			childNodes2 = currentNode.contentWindow.document.body.childNodes;
		}
		catch( e )
		{
			childNodes2 = new Array();
		}
	}
	
	//tijdens het doorlopen van childNodes, als het ID van een childnode gelijk is aan een ID uit de exclude array.
	for (var i = 0; i < childNodes2.length; i++)
	{			
		if (childNodes2[i].nodeType == 1)
		{
			var isExcluded = false;
			if( childNodes2[i] == null )
			{
				alert(childNodes2[i].parentNode.innerHTML);
				isExcluded = true;
			}
			else
			{
				if (childNodes2[i].id != undefined)
				{
					//doorloop de array met excludes en controleer of de huidige childNode een excluded id heeft.
					for (var ii = 0; ii < exclude.length; ii++)
					{
						if (exclude[ii] == childNodes2[i].id)
						{
							isExcluded = true;
						}
					}
				}
			}
			//per childNodes roep je addClassRecursivly weer opnieuw aan.
			if (!isExcluded) addClassRecursivly(className, childNodes2[i], true, exclude);
		}
	}

}


/**
 * This function is called from within the HTML tree and recursivly walks through the dom to add the given classname to the given 
 * elements with the exception of the elements (and their childNodes) which ID's are included in the given exclude array.
 * 
 * @param className The name of the CSS class to add to alle child elements of the given ID element.
 * @param startId The ID of the element whose himself and its childNodes will get the given CSS class.
 * @param inclusive Whether the top element should get the class too or not.
 * @param exclude An array (optional) with zero or more ID's of elements to exclude from the process (do not get the given CSS class) 
 * @return nothing
 */
function removeClassNames(className, startId, inclusive, exclude)
{
	//zoek de node van de className op, geef verder alles door
	removeClassRecursivly(className, document.getElementById(startId), inclusive, exclude);
}


/**
 * Recursive helper function of the above function to recursivly traverse the DOM tree and
 * add classes to the elements. Requires the MOOTOOLS function addClass() 
 * @param className The classname to add.
 * @param startNode The node to start with.
 * @param inclusive Whether the top element should have the class too.
 * @param exclude The node IDs to exclude.
 * @return nothing
 */
function removeClassRecursivly(className, startNode, inclusive, exclude)
{
	//als er geen exclude is opgegeven maak dan hier een nieuwe array
	if (exclude == undefined) {
		exclude = new Array();
	}
	
	if (inclusive == undefined)
	{
		inclusive = true;
	}

	//geef node met startId de class className
	var currentNode = startNode;
	
	if (inclusive)
	{
		if ($(currentNode).hasClass(className))
		{
			$(currentNode).removeClass( className );
		}

	}
	
	//dan haal childNodes van node met startId op
	var childNodes2 = null;
	if( currentNode == null )
	{
		alert(currentNode.parentNode.innerHTML);
	}
	if (currentNode.tagName != "IFRAME")
	{
		childNodes2 = currentNode.childNodes;
	}
	else
	{
			//to prevent polluting all elements with lots of javascripts, we do not use mootools addClass function (anymore).
			//$(currentNode.contentWindow.document.body).addClass(className);
		$(currentNode.contentWindow.document.body).removeClass( className );
		childNodes2 = currentNode.contentWindow.document.body.childNodes;
	}
	
	//tijdens het doorlopen van childNodes, als het ID van een childnode gelijk is aan een ID uit de exclude array.
	for (var i = 0; i < childNodes2.length; i++)
	{
		if (childNodes2[i].nodeType == 1)
		{
			var isExcluded = false;
			if( childNodes2[i] == null )
			{
				alert(childNodes2[i].parentNode.innerHTML);
				isExcluded = true;
			}
			else
			{
				if (childNodes2[i].id != undefined)
				{
					//doorloop de array met excludes en controleer of de huidige childNode een excluded id heeft.
					for (var ii = 0; ii < exclude.length; ii++)
					{
						if (exclude[ii] == childNodes2[i].id)
						{
							isExcluded = true;
						}
					}
				}
			}
			//per childNodes roep je addClassRecursivly weer opnieuw aan.
			if (!isExcluded) removeClassRecursivly(className, childNodes2[i], true, exclude);
		}
	}

}