// JavaScript Document

$(document).ready(function(){
	active_menu( 'top_menu' );
	active_menu( 'navigatie_menu' );
	active_menu( 'sub_menu' );
	active_menu( 'footer' );
});

function active_menu( containerID ){
	var container = document.getElementById( containerID );
	if( container ){
		var anchors = container.getElementsByTagName( 'a' );
		for( var i = 0; i < anchors.length; i++ ){
			var a_href = anchors[i].href;
			var huidige_pagina = location.href;
			//php gets verwijderen...
			huidige_pagina = huidige_pagina.split( '?' );
			huidige_pagina = huidige_pagina[0];
			//anchor id's verwijderen
			huidige_pagina = huidige_pagina.split( '#' );
			huidige_pagina = huidige_pagina[0];
			
			var last_char = huidige_pagina.substring( huidige_pagina.length - 1 );
			if(  last_char == '/' ){
				huidige_pagina += 'index.php';
			}
			if( a_href == huidige_pagina ){
				anchors[i].className = 'active';
			}
		}
	}
}

function trim (str, charlist) {
    var whitespace, l = 0,
	  i = 0;
    str += '';
 
    if (!charlist) {        // default list
	  whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
	  // preg_quote custom list
	  charlist += '';        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
    }
 
    l = str.length;
    for (i = 0; i < l; i++) {        if (whitespace.indexOf(str.charAt(i)) === -1) {
		str = str.substring(i);
		break;
	  }
    } 
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
	  if (whitespace.indexOf(str.charAt(i)) === -1) {
		str = str.substring(0, i + 1);            break;
	  }
    }

    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
