/* stylesheet generator */

	// generates an empty stylesheet based on the html dom
	var strStyleSheet = "";
	var objBody = document.body;
	
	function isFormElement(node){
		return (('INPUT,SELECT,TEXTAREA,BUTTON').indexOf(node.nodeName)>-1);
	}
	
	function getNodeClasses(objNode, intRecursion, prefix){
		var strTabs = '';
		var idPrefix, classPrefix, tagPrefix, addPrefix;
		var newEntry = '';
		// for every recursion add one tab
		for(var intB=0; intB<intRecursion; intB++) strTabs += '\t';
		// get the child nodes
		var objChildNodes = objNode.childNodes;
		// for every childnode
		for(var intA=0; intA<objChildNodes.length; intA++){
			// reset prefixes
			idPrefix = '';
			classPrefix = '';
			tagPrefix = '';
			addPrefix = '';
			// if it has an id, but is not a form element
			if(typeof(objChildNodes[intA].id)!='undefined' && !isFormElement(objChildNodes[intA])){
				if(objChildNodes[intA].id!=''){
					// add class to stylesheet prototype
					newEntry = strTabs + '#' + objChildNodes[intA].id + ' {}\n'
						// strStyleSheet += strTabs + prefix + '#' + objChildNodes[intA].id + ' {}\n'
					// add this style only if there's not double
					if(strStyleSheet.indexOf(newEntry)<0) strStyleSheet += newEntry;
					// update the prefix
					idPrefix = '#' + objChildNodes[intA].id;
				}
			}
			// if it has a className
			if(typeof(objChildNodes[intA].className)!='undefined'){
				if(objChildNodes[intA].className!=''){
					// split the classnames
					allClasses = objChildNodes[intA].className.split(' ');
					// for all classes
					for(var b=allClasses.length-1; b>=0; b--){
						// add class to stylesheet prototype
						newEntry = strTabs + prefix + objChildNodes[intA].nodeName.toLowerCase() + '.' + allClasses[b] + ' {}\n';
						// add this style only if there's not double
						if(strStyleSheet.indexOf(newEntry)<0) strStyleSheet += newEntry;
						// update the prefix
						classPrefix = objChildNodes[intA].nodeName.toLowerCase() + '.' + allClasses[b];
					}
				}
			}
			// if it has neither
			if(
				objChildNodes[intA].className=='' && 
				(objChildNodes[intA].id=='' || isFormElement(objChildNodes[intA])) && 
				objChildNodes[intA].nodeName.indexOf('text')<0 && 
				objChildNodes[intA].nodeName.indexOf('comment')<0
			){
				// add class to stylesheet prototype
				newEntry = strTabs + prefix + objChildNodes[intA].nodeName.toLowerCase() + ' {}\n';
				// add this style only if there's not double
				if(strStyleSheet.indexOf(newEntry)<0) strStyleSheet += newEntry;
				// update the prefix
				tagPrefix = objChildNodes[intA].nodeName.toLowerCase();
			}
			// if the last entry was a link
			if(newEntry.indexOf(' a {}')>-1){
				// repeat it four times with the mouseover states
				linkEntry = newEntry.replace('a {}','a:link,');
				if(strStyleSheet.indexOf(linkEntry)<0) strStyleSheet += '\t' + linkEntry;
				linkEntry = newEntry.replace('a {}','a:visited {}');
				if(strStyleSheet.indexOf(linkEntry)<0) strStyleSheet += '\t' + linkEntry;
				linkEntry = newEntry.replace('a {}','a:hover,');
				if(strStyleSheet.indexOf(linkEntry)<0) strStyleSheet += '\t' + linkEntry;
				linkEntry = newEntry.replace('a {}','a:active {}');
				if(strStyleSheet.indexOf(linkEntry)<0) strStyleSheet += '\t' + linkEntry;
				// and jump further in
				intRecursion += 1;
			}
			// if it has childNodes
			if(objChildNodes[intA].childNodes.length>0){
				// update the prefix
				if(idPrefix){
					addPrefix = idPrefix + ' ';
				}else if(classPrefix){
					addPrefix = prefix + classPrefix + ' ';
				}else if(tagPrefix){
					addPrefix = prefix + tagPrefix + ' ';
				}
				// recurse
				getNodeClasses(objChildNodes[intA], intRecursion+1, addPrefix);
			}
		}
	}

	function showNodeClasses(){
		document.body.style.textAlign = 'left';
		getNodeClasses(objBody, 0 , '');
		document.body.innerHTML = '<pre>' + strStyleSheet + '</pre>';	
	}

//	document.writeln('<a href="javascript:{showNodeClasses()}" style="position : absolute; left : 0px; top : 0px;">Click here to create an empty stylesheet for this markup.</a>');
	
	
	
	
	
/*
name			: Class Behaviour
update			: 20051129
author			: Xander Bindt, Frank van Rooijen, Maurice van Creij
dependencies		: lib_classbehaviour.js
info				: http://www.woollymittens.nl/content/details.asp?id=20040805133501
*/

	// MAIN
	// main class-behaviour object
	function ClassBehaviour(){
		/* properties */
			this.handlers			=	new Array();
		/* methods */
			// return a parameter from the url's query strings
			this.getQueryParameter 	= 	function(paramName, defaultValue){
											// split the query string at the parameter name
											var queryParameters = document.location.search.split(paramName+"=");
											// split the parameter value from the rest of the string
											var queryParameter = (queryParameters.length>1) ? queryParameters[1].split("&")[0] : null ;
											// return the value
											return (queryParameter!=null) ? queryParameter : defaultValue ;
										}
			// returns a string of parameters found in the classname which can be [eval]uated
			this.getClassParameter	=	function(targetNode, paramName, defaultValue){
											// get the class parameter from the classname
											var classParameter = targetNode.className;
											// split the classname between the parameter name
											classParameter = classParameter.split(paramName + '_');
											// split the second piece between spaces and take the first part,  if there are two pieces
											classParameter = (classParameter.length>1) ? classParameter[1].split(' ')[0] : null ;
											// return the value
											return (classParameter!=null) ? classParameter : defaultValue ;
										}
			// returns the visible display state needed for this element
			this.getVisibleState	=	function(node){
											// what kind of node is this
											switch(node.nodeName.toLowerCase()){
												case 'table' : visibleState='table' ; break;
												case 'thead' : visibleState='table-header-group' ; break;
												case 'tfoot' : visibleState='table-footer-group' ; break;
												case 'tbody' : visibleState='table-row-group' ; break;
												case 'tr' : visibleState='table-row' ; break;
												case 'td' : visibleState='table-cell' ; break;
												case 'th' : visibleState='table-cell' ; break;
												default : visibleState='block';
											}
											// apply the state
											return (document.all && navigator.userAgent.indexOf('Opera')<0) ? 'block' : visibleState;
										}
			// (cross)fader and pseudo event handler
			this.fader				=	new Fader;
			// get the previous node without worrying about text nodes
			this.nextNode			=	function(node){
											// look for the next html node
											do {
												node = node.nextSibling;
											} while(node.nodeName.indexOf('#text')>-1);
											// return it
											return node;
										}
			// get the next node without worrying about text nodes
			this.previousNode		=	function(node){
											// look for the previous html node
											do {
												node = node.previousSibling;
											} while(node.nodeName.indexOf('#text')>-1);
											// return it
											return node;
										}
			// parse the document for classnames
			this.parseDocument		=	function(){
											// get all document nodes
											var allNodes = (document.all) ? document.all : document.getElementsByTagName("*");
											// for all tags
											for(var a=0; a<allNodes.length; a++){
												// if the item has a className
												if(allNodes[a].className){
													// get the classname
													nodeClass = allNodes[a].className;
													// for all behaviours
													for(var b=0; b<this.handlers.length; b++){
														// if the behaviour's name exists in the class name, apply it's events
														if(nodeClass.indexOf(this.handlers[b].name)>-1) this.handlers[b].start(allNodes[a]);
													}
												}
											}
										}
	}
	// create the main class-behaviour object
	var classBehaviour = new ClassBehaviour;
	
	// UTILITIES
		function Fader(){
			/* properties */
			/* methods */
			this.getFade	=	function(node){
									var fadeValue = null;
									// get the fade value using the proper method
									if(typeof(node.style.MozOpacity)!='undefined')	fadeValue = Math.round(parseFloat(node.style.MozOpacity)*100);
									if(typeof(node.style.filter)!='undefined')		fadeValue = parseInt(node.filters.alpha.opacity);
									if(typeof(node.style.opacity)!='undefined')		fadeValue = Math.round(parseFloat(node.style.opacity)*100);
									// return the value
									return fadeValue;
								}
			this.setFade	=	function(node, amount){
									// set the fade value using the proper method
									if(typeof(node.style.MozOpacity)!='undefined')	node.style.MozOpacity = amount/100;
									if(typeof(node.style.filter)!='undefined')		node.style.filter = "alpha(opacity=" + amount + ")";
									if(typeof(node.style.opacity)!='undefined')		node.style.opacity = amount/100;
										/*
										filter:alpha(opacity=50);	imageobject.filters.alpha.opacity=opacity
										-moz-opacity: 0.5;			imageobject.style.MozOpacity=opacity/100
										opacity: 0.5;
										-khtml-opacity: 0.5;
										*/
								}
			this.fadeIn		=	function(idIn, step, delay, evalEvent){
									var cf = classBehaviour.fader;
									// get the fading object
									node = document.getElementById(idIn);
									// get the current fade
									fade = cf.getFade(node) + step;
									// if not 100%
									if((fade)<100){
										// set the new fade
										cf.setFade(node, fade);
										// next step
										cf.timeOut = setTimeout("classBehaviour.fader.fadeIn('"+idIn+"',"+step+","+delay+",'"+evalEvent+"')", delay);
									// else
									}else{
										// set the fade to 100%
										cf.setFade(node, 100);
										// trigger the end event
										eval(evalEvent);
									}
								}
			this.fadeOut	=	function(idOut, step, delay, evalEvent){
									var cf = classBehaviour.fader;
									// get the fading object
									node = document.getElementById(idOut);
									// get the current fade
									fade = cf.getFade(node) - step;
									// if not 100%
									if(fade>0){
										// set the new fade
										cf.setFade(node, fade);
										// next step
										cf.timeOut = setTimeout("classBehaviour.fader.fadeOut('"+idOut+"',"+step+","+delay+",'"+evalEvent+"')", delay);
									// else
									}else{
										// set the fade to 100%
										cf.setFade(node, 0);
										// trigger the end event
										eval(evalEvent);
									}
								}
			this.crossFade	=	function(idIn, idOut, amount, step, delay, evalEvent){
									var cf = classBehaviour.fader;
									// if the amount is not the end value yet
									if(amount<=100){
										// set the fade amounts
										cf.setFade(document.getElementById(idIn), amount);
										cf.setFade(document.getElementById(idOut), 100-amount);
										// unhide the new page
										document.getElementById(idIn).style.display = 'block';
										// construct the fade function
										var evalLoop = "classBehaviour.fader.crossFade('"+idIn+"', '"+idOut+"', "+(amount+step)+", "+step+", "+delay+", '"+evalEvent+"')";
										// repeat the fade
										setTimeout(evalLoop, delay);
									}else{
									// else
										// cancel the opacity style
										var node = document.getElementById(idIn);
										if(typeof(node.style.MozOpacity)!='undefined')	node.style.MozOpacity = 'auto';
										if(typeof(node.style.filter)!='undefined')		node.style.filter = 'none';
										if(typeof(node.style.opacity)!='undefined')		node.style.opacity = 'auto';
										// hide the old page
										document.getElementById(idOut).style.display = 'none';
										// trigger the end event
										cf.onEnd(evalEvent);
									}
								}
			/* events */
			this.onEnd		=	function(evalEvent){
									eval(evalEvent);
								}
		}

	// BEHAVIOURS
	// Add a className to a tag using the query parameter "class"',
		// define this class behaviour
		function AddQueryToClassName(){
			/* properties */
			this.name 		= 	'addQueryToClassName';
			/* methods */
			this.start		=	function(node){
									this.process(node);
								}
			this.process	= 	function(objNode){
									// get the query parameter
									var strQueryParameter = classBehaviour.getQueryParameter("fontsize","normal");
									// add to front of classNames
									if(strQueryParameter!=null) objNode.className = strQueryParameter + ' ' + objNode.className;
								}
		}
		// add this function to the classbehaviour object
		classBehaviour.addQueryToClassName = new AddQueryToClassName;
		classBehaviour.handlers[classBehaviour.handlers.length] = classBehaviour.addQueryToClassName;
		
	// clear a form element filled with a help text
		// define this class behaviour
		function EmptyOnFocus(){
			/* properties */
			this.name 		= 	'emptyOnFocus';
			/* methods */
			this.start		=	function(node){
									node.onfocus = this.clear;
								}
			/* events */
			this.clear		=	function(that){
									var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
									// clear the contents if this is the first time
									if(objNode.className.indexOf('wasEmptied')<0){
										// clear this field
										objNode.value = '';
										// mark this input as cleared
										objNode.className += ' wasEmptied';
									}
								}
		}
		// add this function to the classbehaviour object
//De functie emptyOnFocus staatuit, deze functie is bedoelt om defaultwaarden uit inputvelden te verwijderen op het moment dat je erop klikt
		//classBehaviour.emptyOnFocus = new EmptyOnFocus;
		//classBehaviour.handlers[classBehaviour.handlers.length] = classBehaviour.emptyOnFocus;
		
	// clear a form element filled with a help text
		// define this class behaviour
		function AdjustCols(){
			/* properties */
			this.name 		= 	'adjustCols';
			/* methods */
			this.start		=	function(node){
									// count the columns
									columns = node.getElementsByTagName('div');
									// adjust the classname accordingly
									node.className = node.className.replace('cols_','undefined_');
									node.className += ' cols_' + (columns.length-1);
								}
		}
		// add this function to the classbehaviour object
		classBehaviour.adjustCols = new AdjustCols;
		classBehaviour.handlers[classBehaviour.handlers.length] = classBehaviour.adjustCols;
		
	// STARTUP-SEQUENCE
	// start the parsing of classes
	classBehaviour.parseDocument();