var d;
var u;
var showtime = 1;
var t;
var nummer = 0;
var wachten;
var speed;
var toondezin;

$(function() {
	$('.bel').draggable({stack: '.bel', containment: 'window', scroll: 'false', cursor: 'move'});
	$( "#wittebel" ).draggable( "option", "handle", "h1" );
	$( "#rozebel" ).draggable( "option", "handle", "h3" );
});

nua=navigator.userAgent;
op=(nua.indexOf('Opera')!=-1);
ie=((nua.indexOf('MSIE')!=-1)&&!op);

if (ie) speed = 5; else speed = 1;

function toonZin(zin) {
	// if (toondezin==1) {
		doel = document.getElementById('zin');
		doel.style.backgroundImage="url('../img/zin"+zin+".png')";
		doel.style.display = "block";
		toondezin=0;
	/* } else {
		toondezin=1;
		setTimeout('toonZin('+zin+')',550);
		return;
	} */
}

function verbergZin() {
	doel = document.getElementById('zin');
	doel.style.backgroundImage="none";
	doel.style.display="none";
	toondezin=0;
}
	
function closeParent (kindje) {
	kindje.parentNode.style.display='none';
}

function toonBel (bel) {
	bel.style.display = 'block';
	bel.style.zIndex = '80';
	var menu = document.getElementById('menu');
	menu.style.height = 44 + 'px';
	wachten = 1;
	setTimeout('wachten = 0',550);
}

function toggleDia () {
	if (showtime==0) {
		showtime=1;
	} else {
		showtime=0;
	}
}

function diaShow (scherm, bestandsnaam, interval, willekeurig, aantal) {
	var achtergrond = document.getElementById(scherm);
	if (showtime) {
		t = setTimeout('diaShow(\'' + scherm + '\',\'' + bestandsnaam + '\',' + interval + ',' + willekeurig + ',' + aantal + ')',interval);
		if (willekeurig) {
			nummer = Math.floor(Math.random()*aantal);
		} else {
			nummer++;
			if (nummer >= aantal) {
				nummer = 0;
			}
		}
		achtergrond.style.backgroundImage = 'url('+bestandsnaam+nummer+'.jpg)';		
	} else {
		clearTimeout (t);
	}
}


function slideDown (ding, tot) {
	
	if (wachten == 1) {
		return;
	}
	
	var obj = document.getElementById(ding);
	var stap = 5 * speed;
	
	clearTimeout(u);

	if (Math.abs(obj.clientHeight-tot)>Math.abs(stap)) {
		obj.style.height = obj.clientHeight + stap + 'px';
		d = setTimeout('slideDown(\'' + ding + '\',' + tot + ')', 5);
	} else {
		obj.style.height = tot + 'px';
		clearTimeout(d);
	}
}

function slideUp (ding, tot) {
	var obj = document.getElementById(ding);
	var stap = -10 * speed;
	
	clearTimeout(d);
	
	if (Math.abs(obj.clientHeight-tot)>Math.abs(stap)) {
		obj.style.height = obj.clientHeight + stap + 'px';
		u = setTimeout('slideUp(\'' + ding + '\',' + tot + ')', 5);
	} else {
		obj.style.height = tot + 'px';
		clearTimeout(u);
	}
}

/*********************************************************************
 * No onMouseOut event if the mouse pointer hovers a child element 
 * *** Please do not remove this header. ***
 * This code is working on my IE7, IE6, FireFox, Opera and Safari
 * 
 * Usage: 
 * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
 *		So many childs 
 *	</div>
 *
 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/

function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {
		current_mouse_target = event.toElement;
	} else if( event.relatedTarget ) {
		current_mouse_target = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}


// Name: blur Anchors
// Language: JavaScript
// Author: Travis Beckham ¦ squidfingers.com
// Description: Remove anchor outlines from all links in the document
// --------------------------------------------------
function blurAnchors() {
	if(document.getElementsByTagName) {
		var a = document.getElementsByTagName("a");
		//collect all anchors A
		for (var i = 0; i < a.length; i++) {
			// mouse onfocus, blur anchors
			a[i].onfocus = function(){this.blur();};
		}
	}
}