﻿// Copyright by St. Paulus 2009. Landgraaf

//Functie: eenvoudige functie voor het vergroten van l_container.
function resize() {
    reset_resize();
    
	r_container = document.getElementById("right_container");
	l_container = document.getElementById("left_container");
	
	if(r_container.offsetHeight > l_container.offsetHeight)
		l_container.style.height = r_container.offsetHeight + "px";
}

//Herstelt de grootte van left_container weer. Zodanig dat een nieuwe resize het juiste effect heeft. Dit is handig bij foto's die van formaat wisselen.
function reset_resize() {
    document.getElementById("left_container").style.height = "500px";
}

var contextMenuTop = null;
var contextMenuBottom = null;
		
//Class: klasse voor het aansturen van de highlighter van een contextmenu.
function ContextMenu(menuHighlight, className, imagePath)
{
	this.menu = menuHighlight;
	this.name = className;
	
	this.isVisible = false;
	this.isMoving = false;
	this.position = 0;
	this.nextPosition = 0;
	this.imgpath = imagePath;
	
	this.ShowHighlighter = function(obj)
	{	//Functie: weergeeft de highlighter (of verplaats naar) voor obj.
		if(this.isVisible == false) this.InitHighlighter(obj); else this.MoveHighlighter(obj);			
		//document.getElementById("test").innerHTML = "TEST" + obj.offsetTop;
	}
	
	this.InitHighlighter = function(obj)
	{	//Functie: initialiseert de highlighter als de muis het menu binnenkomt.
		this.position = obj.offsetTop;
		this.menu.style.background = "url('" + this.imgpath + "')";
		this.menu.style.backgroundRepeat = "no-repeat";
		this.menu.style.backgroundPosition = "0px " + this.position + "px";
		
		this.isVisible = true;
	}
	
	this.MoveHighlighter = function(obj)
	{	//Functie: Verplaats de highlighter (aangeroepen door ShowHighlighter).
		this.nextPosition = obj.offsetTop;
		window.setTimeout(className + ".MoveInternal()", 20);
	}
	
	this.MoveInternal = function()
	{	//Functie: Verplaats de highlighter.
		if(this.nextPosition > this.position) 
		{	this.position += 4; if(this.nextPosition < this.position) this.position = this.nextPosition;
		}
		else if (this.nextPosition < this.position)
		{	this.position -= 4; if(this.nextPosition > this.position) this.position = this.nextPosition;
		}

		this.menu.style.backgroundPosition = "0px " + this.position + "px";
		
		if(this.nextPosition != this.position) window.setTimeout(className + ".MoveInternal()", 20);			
	}
	
	this.HideHighlighter = function(ev)
	{	//Functie: Verberg het menu (niet Internet Explorer).
		if(ev.srcElement && ev.srcElement != this.menu) return; //RETURN als browser Internet Explorer is.		
		if(this.isChild(this.menu, ev.relatedTarget)) return;
		
		this.menu.style.background = "none";
		this.isVisible = false;
	}
	
	this.HideHighlighterIE = function(ev)
	{	//Functie: Verberg het menu (Internet Explorer).
		this.menu.style.background = "none";
		this.isVisible = false;
	}
	
	this.isChild = function(e, c)
	{	//Functie: Controleert of c een kind van e is.
		return (e == c) ? true :
			(c.parentNode) ? this.isChild(e, c.parentNode) : false;
	}
}