var submenuClickHandled = false;

var trainer_images = Array();

/*
trainer_images["Alicia Lievens"] = { src : "images/trainers/Alicia.jpg", width : 100, height: 151};
*/
trainer_images["Arie van Prooyen"] = { src : "images/trainers/Arie.jpg", width : 100, height: 151};
trainer_images["Bep van Tatenhove"] = { src : "images/trainers/Bep.jpg", width : 100, height: 151};
trainer_images["Bianca Kroon"] = { src : "images/trainers/Bianca.jpg", width : 104, height: 156};
trainer_images["Chantal Huys"] = { src : "images/trainers/Chantalle.jpg", width : 100, height: 151};
trainer_images["Christiane van Hoecke"] = { src : "images/trainers/Christianne.jpg", width : 100, height: 151};
trainer_images["Sylvia & Frank van Tatenhove"] = { src : "images/trainers/Frank.jpg", width : 100, height: 85};
trainer_images["Melissa Vercauter"] =  { src : "images/trainers/Melissa.jpg", width : 100, height: 151};
trainer_images["Patrick Saelens"] = { src : "images/trainers/Patrick.jpg", width : 100, height: 151};
trainer_images["Saskia van Es"] = { src : "images/trainers/Saskia.jpg", width : 100, height: 151};
trainer_images["Fiona van der Hooft"] = { src : "images/trainers/Fiona.jpg", width : 100, height: 151};
trainer_images["Henny Bolleman"] = { src : "images/trainers/Henny.jpg", width : 100, height: 151};
trainer_images["Greet Vink"] = { src : "images/trainers/Greet.jpg", width : 100, height: 151};
trainer_images["Hanka Jongman"] = { src : "images/trainers/Hanka.jpg", width : 100, height: 151};
trainer_images["Elles Harms"] = { src : "images/trainers/Elles.gif", width : 200, height: 116};
trainer_images["Evie Saelens"] = { src : "images/trainers/Evie.gif", width : 150, height: 150};

function init(){

	var table = document.getElementById("roosters");
	
	if (table){
	
		var lst = table.getElementsByTagName("td");
	
		for (var i = 0; i < lst.length; i++){
	
			var trainer = lst[i];
			
			if (trainer.className == "trainer"){
			
				
				if (trainer.firstChild.href){
				
					trainer.firstChild.onmouseover = showTrainerPopup;
					trainer.firstChild.onmouseout = hideTrainerPopup;
						
				} else {
				
					trainer.onmouseover = showTrainerPopup;
					trainer.onmouseout = hideTrainerPopup;
					
				}
			
			}
	
		}
	
	}
	
	/* initialize the submenu's */

	var mnu = $("menu_left_list");
	
	lst = mnu.getElementsByTagName("ul");
	
	for (var i = 0; i < lst.length; i++){

		var sm = lst[i];

		sm.parentNode.onclick = toggleSubmenu;

		/*
		if (sm.parentNode.parentNode.parentNode == "li"){
		
			sm.parentNode.onclick = toggleSubChildmenu;

		} else {
		
			sm.parentNode.onclick = toggleSubmenu;

		}
		*/
	
	}
	
	expandActiveSubMenu();
	
	setHeightBoxes();
	
}

function toggleSubmenu(e){

	var sms = this.getElementsByTagName("ul");

	if (sms){
	
		var sm = sms[0];
		
		if (sm.style.display == "block"){
		
			sm.style.display = "none";
		
		} else {
		
			sm.style.display = "block";
		
		}
	
		submenuClickHandled = true;
	
	}
	
	//cancel the event!!	
	
	if (window.event){
	
		e = window.event;
		//window.event.cancelBubble = true;
	
	//} else {

		//e.cancelBubble = true;

	}
	
	e.cancelBubble = true;
	
}

function toggleSubChildmenu(){

	var sms = this.getElementsByTagName("ul");

	if (sms){
	
		var sm = sms[0];
		
		if (sm.style.display == "block"){
		
			sm.style.display = "none";
		
		} else {
		
			sm.style.display = "block";
		
		}
	
		submenuClickHandled = true;
	
	}
	
	//cancel the event!!	
	
	if (window.event){
	
		window.event.cancelBubble = true;
	
	}

}

function expandActiveSubMenu(){

	if ((typeof(activeSubMenuId) != "undefined") && (activeSubMenuId)){

		for (var i = 0; i < activeSubMenuId.length; i++){
		
			var asm = $(activeSubMenuId[i]);	

			if (asm){
				
				var sms = asm.getElementsByTagName("ul");
			
				if (sms)
					sms[0].style.display = "block";
					
			}
			
		}

	}

}

function showTrainerPopup(e){

	//var e = window.event;
	var e = window.event || e;
	
	var l = (window.event ? e.x + 10 : e.clientX + 10);
	var t = (window.event ? e.y : e.clientY);
	
	var key = this.firstChild.nodeValue;

	if ((key) && (key != "")){

		var pic = trainer_images[key];
		
		if (pic){
		
			var bx = $("image_popup");
			var im = $("image_popup_image");
		
			if ((bx) && (im)){

				//var l = e.x + 10;
				//var t = e.y;

				im.style.visibility = "visible";

				im.width = pic.width;
				im.height = pic.height;
				im.src = pic.src;

				bx.style.left = l + "px";
				bx.style.top = t + "px";
				bx.style.width = pic.width + "px";
				bx.style.height = pic.height + "px";
				
				bx.style.display = "block";

			}
			
		}
	
	}
	
}

function hideTrainerPopup(){

	var bx = $("image_popup");
	var im = $("image_popup_image");
	
	if ((bx) && (im)){
	
		im.style.visibility = "hidden";
		im.src = "images/trainers/empty.jpg";
		bx.style.display = "none";

	}

}

function setHeightBoxes(){

	var menuBox = $("menu_left");
	var textBox = $("texts");
	var innerTextBox = $("inner-table-box");

	if ((textBox) || (innerTextBox)){
	
		var h = screen.availHeight;
		var newHeight = (h - 400) + "px";
		
		if (menuBox){
		
			menuBox.style.height = newHeight;

		}
	
		if ((textBox) && (innerTextBox)){
		
			innerTextBox.style.height = newHeight;
		
		} else if (textBox){
		
			textBox.style.height = newHeight;

		}
		
	}

}

onload = init;
