function findPreviousSibling ( base, nodeName ) {
	ptr = base;
	while ( ptr ) {
		ptr = ptr.previousSibling;
		if ( ptr && ptr.nodeName.toLowerCase()== nodeName.toLowerCase () ) {
			break;
		}
	}
	return ptr;
}

function findNextSibling ( base, nodeName ) {
	ptr = base;
	while ( ptr ) {
		ptr = ptr.nextSibling;
		if ( ptr && ptr.nodeName.toLowerCase()== nodeName.toLowerCase () ) {
			break;
		}
	}
	return ptr;
}


function initNav () {
    var images = {
        navigationCon: ['url(/gfx/nav/menu_line_darkgrey.gif)','url(/gfx/nav/menu_line_orangegrey-dashed.gif)'],
        //navigationTargetGroupCon: ['none','url(/gfx/nav/menu_line_darkgrey.gif)']
		navigationTargetGroupCon: ['url(/gfx/nav/menu_line_darkgrey.gif)','url(/gfx/nav/menu_line_black.gif)']
    };
    var all = {};

    ['navigationCon','navigationTargetGroupCon'].each ( function ( mainNav ) {
        var lis = $ES('li.main-item', $(mainNav));
	    var image      = images[mainNav][1];
	    var hoverImage = images[mainNav][0];
	    all[mainNav]= [];
    
	    lis.each(function ( li, i ) {
	        all[mainNav][i] = li;
	        if ( all[mainNav][i].hasClass('active') ) {
	            if ( $type(all[mainNav][i-1]) ) {
	                all[mainNav][i-1].setStyle('background-image', hoverImage );
	            }
	        } else {
		        all[mainNav][i].addEvent('mouseover', function () {
			        if ( $type(all[mainNav][i-1]) && !all[mainNav][i-1].hasClass('active') ) {
		               all[mainNav][i-1].setStyle('background-image', hoverImage );
			        }
			        all[mainNav][i].setStyle('background-image', hoverImage );
		        } );
		        all[mainNav][i].addEvent('mouseout', function () {
		            if ( $type(all[mainNav][i-1]) && !all[mainNav][i-1].hasClass('active')) {
		                all[mainNav][i-1].setStyle('background-image', image );
		            }
		            if ( !$type(all[i+1]) || !all[i+1].hasClass('active') ) {
		                all[mainNav][i].setStyle('background-image', image );
		            }
		        } );
	        }
	    } );
    } );
}
/*

//---- Navigation 
// function to swap border from the elements surrounding the hovered or active navigation-item
//----

function nav_highlight( element, highlight_status ) {

	var image_src_off;
	var image_src_on;
	var element_up   = findPreviousSibling ( element, 'li' );
	var element_down = findNextSibling ( element, 'li' );
	
	// Define the target image according to the level of the navigation element in the navigation
	// 1: Main menu = orange/brown      2: Sub menu = grey/dark_grey
	// tg1: Target group menu = white/gray     tg2: Targetgroup submenu = grey/dark_grey
  	if( element.className.match ( /\bmain-item\b/ ) ) {
		image_src_off = "url(/gfx/nav/menu_line_orange.gif)";
		image_src_on  = "url(/gfx/nav/menu_line_brown.gif)";
	}else if( element.className.match ( /\bsub-item\b/ ) ) {
		image_src_off = "url(/gfx/nav/menu_line_grey.gif)";
		image_src_on  = "url(/gfx/nav/menu_line_darkgrey.gif)";
	}else if( element.className.match ( /\btarget-item\b/ ) ) {
		image_src_off = "url(/gfx/nav/menu_line_grey.gif)";
		image_src_on  = "none";
	} else {
		image_src_off = null;
		image_src_on  = null;
	}
	
	// Change the background image of the element that is above the element that 
	// activated the mouseover action
	
	if( element_up ){
		if( highlight_status == 'on' ){
			if( image_src_on != ''){
				element_up.style.backgroundImage = image_src_on;
			}
		}else{
			if( image_src_on != ''){
				element_up.style.backgroundImage = image_src_off;
			}
		}
	}
	
	// Change the background image of the element that activated the mouseover action
	// Note: only give it a background image when there is another element below it (only then 
	// the last element won't get a line on its bottom side)
	if( element_down ){
	
		if( highlight_status == 'on' ){
			element.style.backgroundImage = image_src_on;
		}else{
			// put back the original dotted line 
			// Note: only put the line back when the element below the mouse-over element isn't active
			if( !element_down.className.match ( /\bactive\b/ ) ){
				element.style.backgroundImage = image_src_off;
			}
		}
	}
}
*/


// This function makes the search field empty only when the search value "zoeken" is in it.
function search_field_empty( element ){
	var search_string = document.getElementById( element ).value;
	
	if( search_string.toLowerCase() == 'zoeken' ){
		document.getElementById( element ).value = '';
	}
}
