//							----------------------------------------------------- POPUP
//
function pop_mailafriend(src)	 { lib_OpenWindowCentered( src, '', 430, 380, 'Doorsturen naar een kennis');}
function pop_docenten(src)	 	 { lib_OpenWindowCentered( src, '', 486, 442, 'Docentinformatie');}
function pop_belangstelling(src) { lib_OpenWindowCentered( src, '', 560, 390, 'Aanmelden als belangstellende'); }
function pop_medew(src) 	 	 { lib_OpenWindowCentered( src, '', 430, 380, 'Medewerker informatie');}
function pop_vacatures(src)	 	 { lib_OpenWindowCentered( src, '', 530, 200, 'Vacature details');}
function pop_nieuwsbrief(id)	 { lib_OpenWindowCentered( 'http://www.rinogroep.nl/nieuwsbrief.asp?ID=' + id.toString() + '&pageaction=preview&pageDeepLink=Y&intro=No', '', 625, lib_window_height()-80, 'Nieuwsbrief');}
function pop_vimeo_video(id)	 { lib_OpenWindowCentered( 'http://player.vimeo.com/video/' + id.lib_trim() + '?title=0&amp;byline=0&amp;portrait=0&amp;color=e33505&amp;autoplay=1', '', 601, 338, 'Interview');
								   lib_scroll_mode=LIB_SCROLL_MODE_MANUAL; etalage_animation_halt();}

//							----------------------------------------------------- Forms
//
function update_email() {document.getElementById("email_info").innerHTML = document.getElementById("email").value;}

//							----------------------------------------------------- MENU
//
function v(i,b){e=document.getElementById(i);if (e){e.style.display=b?'block':'none'}}
function h(i){v(i,false)}
function s(i){v(i,true)}

function zoek_trefwoord_validatie( strDefault ) {
	var zoek_elt = $("zoek");
	if (zoek_elt.value=='' || zoek_elt.value==strDefault) {
		alert("Vul eerst een trefwoord of code in en druk dan op<br>de Zoek-knop");
		return false;
	} else {
		return true;
	}
}

//							----------------------------------------------------- TABS
//
function tab_set_active( elt ) {
	var tabs_elt = $("pagetabs");
	if (tabs_elt) {
		var tabs = lib_DOM_getElementsByClass( "tab", tabs_elt)
		for (var t=0;t<tabs.length;t++){
			t_elt = tabs[t];
			if (t_elt) {
				t_elt.className = (elt==t_elt ? "tab active" : "tab");
				if (elt==t_elt) {
					inhoud = lib_DOM_getElementsByClass("tab_inhoud", t_elt);
					if (inhoud) {
						$("tabs_content").innerHTML = inhoud[0].innerHTML;
					}
				}
			}
		}
	}
}

function tab_set_first_active() {
	var tabs_elt = $("pagetabs");
	if (tabs_elt) {
		var tabs = lib_DOM_getElementsByClass( "tab", tabs_elt);
		if (tabs) { tab_set_active(tabs[0]) } 
	}
}

//							----------------------------------------------------- ZOEKSCHERM functies
//	if (console) console.log("req_pulldown_activate", objElement.id);

function zoekscherm_toonteller() {
	var frm = document.forms.zoek;
	// ok, down and dirty.
	// move the target of the form to the counting iFrame, post it and return the target back to the original
	frm.save_target=frm.target;
	frm.target="teller";
	frm.save_action=frm.action;
	frm.action="opleidingen_count.asp"
	frm.submit();
	frm.target=frm.save_target;
	frm.action=frm.save_action;
}


//
//	 2do : remove hardcoded formname
//
function pulldown_check_item( item ) {
	var a, the_value, aTmp
	var frm = document.forms.zoek;
	
	// find the checkbox and change setting
	item.className = (item.className=="item" ? "item checked" : "item");

	// try to determine if any item is checked
	a = lib_DOM_getElementsByClass("item checked",item.parentNode.parentNode,"span");
	var bOneChecked=(a.length>0);
	
	var new_value = "";
	for (var fld=0;fld<a.length;fld++) {
		the_value = a[fld].getAttribute("value");
		if (the_value) {
			aTmp = the_value.split("|");
			new_value = (new_value=="" ? "" : new_value + ",") + aTmp[0];
		}
	}
	the_value = item.getAttribute("value");
	if (the_value) {
		aTmp = the_value.split("|");
		frm[aTmp[1]].value = new_value;
	}
	
	// set the checked state of the titel element
	a = lib_DOM_getElementsByClass("item_titel",item.parentNode.parentNode.parentNode,"div");
	a[0].className = (bOneChecked ? "item_titel checked" : "item_titel");
	
	zoekscherm_toonteller();
}

var PULLDOWN_DELAY = 200;
var pulldown_active = null;
var pulldown_new_active = null;		// temporary placeholder for requested activation
var pulldown_req_remove = null;		// requested object to be removed

//	Timer zetten op activeren nieuwe pulldown
//
function req_pulldown_activate( objElement ) {
	if ( pulldown_req_remove==objElement ) {
		pulldown_req_remove = null;				// cancel removal
	} else {
		if ( pulldown_active!=objElement ) {
			pulldown_new_active = objElement;
			window.setTimeout( "do_pulldown_activate()", pulldown_active ? PULLDOWN_DELAY : 0);
		}
	}
}

//	Timer zetten op de-activeren pulldown
//
function req_pulldown_deactivate( objElement ) {	
	pulldown_req_remove = objElement;
	window.setTimeout( "do_pulldown_deactivate()", PULLDOWN_DELAY);
}

//	Feitelijk activeren pulldown menu (na aflopen timer)
//
function do_pulldown_activate(  ) {
	do_pulldown_deactivate()
	if ( pulldown_active!=pulldown_new_active ) {
		if (pulldown_active) pulldown_active.className='caption';
		if (pulldown_new_active) {
			pulldown_new_active.className='caption_actief';
			// vind de inhoud div die 'erin' zit..
			var x = lib_DOM_getElementsByClass("inhoud", pulldown_new_active, "div")
			if (x) {
				// yes: IE6 quirck browser calls again ;-(
				if (x[0].clientHeight>220) {
					x[0].style.height="220px";
				}

				var par = pulldown_new_active.parentNode;
				if (par) {
					if ( (par.offsetLeft + x[0].clientWidth) > 873 ) {
						x[0].style.left = (873 - x[0].clientWidth).toString() + "px";
					}
				}
			}
		}
		pulldown_active = pulldown_new_active;
		pulldown_new_active = null;
		pulldown_req_remove = null;
	}
}

//	Feitelijk de-activeren pulldown menu (na aflopen timer)
//
function do_pulldown_deactivate(  ) {
	if (pulldown_req_remove) {
		if ( pulldown_active==pulldown_req_remove ) {
			pulldown_req_remove.className='caption';
			pulldown_active = null;
			pulldown_req_remove = null;
//			pulldown_new_active = null;
		}
	}
}

//   -			-			-			-			-			MENU'S
// todo make this recurse through an array of menu levels..
var sSubMenuOldLayer = '';
var sSubMenuRequestRemove = '';
var sOldSubvisible = '';
var sMenuOldLayer = '';
var sMenuRequestRemove = '';
var sOldvisible = '';

var MENU_DELAY = 2000;
var MENU_OFFSET_SUBSUBMENU = 80;

// activating a menu is right away 
function menu_activate_submenu( sMenuDiv ) {
    var s;
    
    if (document.getElementById(sMenuDiv)) {
        if (sMenuRequestRemove==sMenuDiv) {
            // prevent removing after timeout: keep alive!
            sMenuRequestRemove = "";
        } else {
            if (sMenuDiv!=sMenuOldLayer) {
	            menu_remove_submenu();
	            if (sMenuOldLayer!="") {
		            MM_showHideLayers(sMenuOldLayer,'','hide');
		            sMenuRequestRemove = "";
		            s = layer_get_style(sMenuOldLayer);
		            if (s) s.zIndex = -1;	
	            }
	            MM_showHideLayers(sMenuDiv,'','show');
	            sMenuOldLayer = sMenuDiv;
	            s = layer_get_style(sMenuOldLayer);
	            if (s) {s.zIndex = 999}
            }
        }
    }
} 

// de-activating a menu is done with a delay, ensuring that this is what the user wants
function menu_deactivate_submenu( ) {
    if (sMenuOldLayer!="") {
        sMenuRequestRemove = sMenuOldLayer;
        window.setTimeout ( "menu_remove_submenu('" + sMenuOldLayer + "')", MENU_DELAY);
    }
} 

// actual removal of a menu, milliseconds after the mouse has left the 'hot-zone' 
function menu_remove_submenu() {
    if (sMenuRequestRemove!="") {
        if (sMenuOldLayer!="") MM_showHideLayers(sMenuOldLayer,'','hide');
        s = layer_get_style(sMenuOldLayer);
        if (s) s.zIndex = -1;	
        sMenuOldLayer="";
        sMenuRequestRemove="";
        
        menu_remove_sub_submenu();
    }
}

// activating a menu is right away 
function menu_activate_sub_submenu( sMenuDiv ) {
    if (sSubMenuRequestRemove==sMenuDiv) {
        // prevent removing after timeout: keep alive!
        sSubMenuRequestRemove = "";
    } else {
        if (sMenuDiv!=sSubMenuOldLayer) {
	        menu_remove_sub_submenu();
	        if (sMenuOldLayer!="") {
		        MM_showHideLayers(sSubMenuOldLayer,'','hide');
		        sSubMenuRequestRemove = "";
		        s = layer_get_style(sSubMenuOldLayer);
		        if (s) s.zIndex = -1;
	        }
	        MM_showHideLayers(sMenuDiv,'','show');
	        sSubMenuOldLayer = sMenuDiv;
	        s = layer_get_style(sSubMenuOldLayer);
	        if (s) s.zIndex = 9999;	
        } 
    }
} 

// de-activating a menu is done with a delay, ensuring that this is what the user wants
function menu_deactivate_sub_submenu( ) {
    if (sSubMenuOldLayer!="") {
        sSubMenuRequestRemove = sSubMenuOldLayer;
        window.setTimeout ( "menu_remove_sub_submenu('" + sSubMenuOldLayer + "')", MENU_DELAY);
    }
} 

// actual removal of a menu, milliseconds after the mouse has left the 'hot-zone' 
function menu_remove_sub_submenu() {
    if (sSubMenuRequestRemove!="") {
        if (sSubMenuOldLayer!="") MM_showHideLayers(sSubMenuOldLayer,'','hide');
        s = layer_get_style(sSubMenuOldLayer);
        if (s) s.zIndex = -1;	
        sSubMenuOldLayer="";
        sSubMenuRequestRemove="";
        // post a delayed message to remove the parent
        menu_deactivate_submenu();
    }
}

function menu_sync_menu(nID) {
    var subm  = document.getElementById( "menu"      + nID.toString() );
    var mainm = document.getElementById( "mainmenu_" + nID.toString() );
    if (subm) {
        subm.style.top  = (mainm.offsetTop + mainm.offsetHeight) + "px";
        subm.style.left = (mainm.offsetLeft + (isIE ? 143 : 142)) + "px";
        if (subm.offsetWidth < mainm.offsetWidth) 
          subm.style.width = (mainm.offsetWidth + 1) + "px";
    }
}

function menu_sync_submenu(nSubmenuID, nSubSubMenuID, regel) {
    var subm     = document.getElementById( "menu"    + nSubmenuID.toString() );
    var sub_subm = document.getElementById( "submenu" + nSubSubMenuID.toString() );
    if (subm && sub_subm) {
        sub_subm.style.top = (regel*22 + 11)+"px";
        sub_subm.style.left  = (subm.offsetLeft + MENU_OFFSET_SUBSUBMENU) + "px"; 
        sub_subm.style.width = '200px';
    }
}   

function setclass( TRElt, className) {
    if (TRElt.childNodes) {
	    for (t=0;t<TRElt.childNodes.length;t++) {
		    TRElt.childNodes[t].className = className; 	
	    }
    }
}

//							----------------------------------------------------- ETALAGE
//
var active_etalage = null;
var etalage_animated = false;
var etalage_mouse_halted = false;	// gestopt omdat de muis eroverheen is?
var etalage_max = 1;
var animatie_percentage = 0.0;
var animatie_totale_tijd = 4000;	// milliseconden!
var etalage_p_div = null;
var prev_timer = null;

function etalage_internal_set_tab( id, bOnOff) {
	var tabje = document.getElementById("etalage_nummer_" + id.toString());
	var tab_inhoud = document.getElementById("etalage_item_" + id.toString());
	
	if (tabje && tab_inhoud) {
		tabje.className = "nummer" + (bOnOff ? "_active" : "");
		tab_inhoud.className = "etalage_inhoud" + (bOnOff ? "_active" : "");
	}
	if (!bOnOff) {
		lib_fade( tab_inhoud, false, 20, 4, 60);
	} else {
		lib_fade( tab_inhoud, true, 20, 4, 100);
	}
}

function etalage_show_percentage( iPerc ) {
	if (etalage_p_div) {
		etalage_p_div.style.width = iPerc.toString() + "%";
	}
}

function etalage_set_tab( id ) {
	if (active_etalage!=id) {
		if (active_etalage) {
			etalage_internal_set_tab( active_etalage, false);
		}
		etalage_internal_set_tab( id, true);
		active_etalage=id;
		if (prev_timer) {
			clearTimeout(prev_timer);
			prev_timer = null
		}
		animatie_percentage = 0.0;
		etalage_animation();
	}
}

function etalage_animation() {
	if (etalage_animated  && !etalage_mouse_halted) {
		if (animatie_percentage>=100) {
			var new_tab = active_etalage < etalage_max ? active_etalage + 1 : 1;
			etalage_set_tab( new_tab );
		} else {
			animatie_percentage = animatie_percentage + 0.5;
			etalage_show_percentage( animatie_percentage );
			if (prev_timer) clearTimeout(prev_timer);
			prev_timer = setTimeout( "etalage_animation()", (animatie_totale_tijd / 200) );
		}
	}
}

function etalage_animation_halt() {
	etalage_animated = false;
	animatie_percentage = 0;
	etalage_show_percentage(100);
}

function etalage_init( start_tab, bAnimate, intMax ) {
	var etal = document.getElementById("etalage");
	if (etal) {
		etalage_max = intMax;
		
		etal.onmouseout  = function() {etalage_mouse_halted=false;etalage_animation()};
		etal.onmouseover = function() {etalage_mouse_halted=true};

		for (var t=1; t<=etalage_max; t++) {
			var i = document.getElementById("etalage_item_" + t.toString());
			i.className = "etalage_inhoud";
			i.style.visibility = 'hidden';		
		}
		etalage_p_div = document.getElementById("etalage_perc_div");
		etalage_set_tab( start_tab );
		if (intMax==1) {
			etalage_animated = false;
		} else {
			etalage_animated = bAnimate;
			etalage_animation();
		}
		
		// install handlers in each form to halt the etalage!
		var node_list = document.getElementsByTagName('form'); 
		for (var i = 0; i < node_list.length; i++) { 
			node_list[i].onclick = function() {etalage_animation_halt()};
			node_list[i].onkeydown = function() {etalage_animation_halt();return true;};
		}
	}
}

//							----------------------------------------------------- DOCENTEN
//
var docent_anim_current = 0;
var docent_anim_auto    = true;
var docent_anim_speed   = 2000;
var docent_anim_count;

function docent_anim_set(id,bOn){
  var e=document.getElementById("docent_anim_details"+id.toString());
  if (e){e.className="docent_anim_detail_elt"+(bOn?"_a":"")}
  e=document.getElementById("docent_anim_title"+id.toString());
  if (e){e.className="docent_anim_title_elt"+(bOn?"_a":"")}
}

function docent_anim_activate(id){
  if (docent_anim_current>0) {
    docent_anim_set(docent_anim_current, false);
  }
  docent_anim_set(id, true);
  docent_anim_current = id;
}

function docent_anim_hover(id) {
  docent_anim_auto = false;
  docent_anim_activate(id);
}

function docent_anim_next() {
  if (docent_anim_auto){
    var docent_anim_next=docent_anim_current<docent_anim_count?docent_anim_current+1:1
    docent_anim_activate( docent_anim_next );
    window.setTimeout( "docent_anim_next()", docent_anim_speed);
  }
}

function docent_anim_restart() {
   docent_anim_auto=true;
   docent_anim_next();
}

function docent_anim_init(count){
   docent_anim_count = count; 
   docent_anim_next();
}

