var busy = false;
var place = "";
function show_props(obj, objName) {
	var result = "";
	var count = 0;
	for (var i in obj) {
		result += objName + "." + i + " = " + obj[i] + "\n";
		count++;
		if(count > 20) {
			alert(result);
			count = 0;
			result = "";
		}
	}
	alert(result);
	return result;
}


var showTitle = function(ar) {
	var new_title = ar.target.attributes['page_title'].nodeValue;
	$('div.content h1').text(new_title);
	var subtitle = ar.target.attributes['subtitle'].nodeValue;
	$('div.content h2').text(subtitle);
}
var resetTitle = function() {
	/*
	setTimeout(resetTitleExp, 500);
}
var resetTitleExp = function() {
	*/
	var t = $('div.content h1').attr('title');
	if(t == undefined) {
		t = " ";
	}
	$('div.content h1').text(t);
	$('div.content h2').text($('div.content h2').attr('subtitle'));
}
var showMenu = function(place) {
//	busy = true;
	if ($('div#menu #menu_logo_' + place).attr('shown') != 'true') {
		$('div#menu #menu_logo_' + place).hide();
		$('div#menu ul#navigation_' + place).show();
		$('div#menu #menu_logo_' + place).attr('shown', 'true');
	}
//	alert(msg);
}
var hideMenu = function(p) {
	if(p == undefined) {
		var menu_place = place;
	} else {
		var menu_place = p
	}
//	alert('hide: ' + menu_place + ', busy: ' + busy);
	if(busy == true) {
		return;
	}
	if ($('div#menu #menu_logo_' + menu_place).attr('shown') == 'true') {
		$('div#menu ul#navigation_' + menu_place).hide();
		$('div#menu #menu_logo_' + menu_place).show();
		$('div#menu #menu_logo_' + menu_place).attr('shown', 'false');
	}
}

var showMenuRight = function() {
	showMenu('right');
}
var hideMenuRight = function() {
	place = "right";
	setTimeout(hideMenu, 500, 'right');
}

var showMenuLeft = function() {
	showMenu('left');
}
var hideMenuLeft = function() {
	place = "left";
//	hideMenu('left');
	setTimeout(hideMenu, 200, 'left');
}

var tagBusy = function(e) {
	busy = true;
}
var tagNotBusy = function(e) {
	busy = false;
}

$(document).ready(function() {
	var kop = $('div.content h1').text();
	if(kop == undefined || kop == '') {
		var kop = $('div.content').append('<div id="titles"><h1> </h1><h2> </h2></div>');
	}
	
	var kop = $('div.content h1');
	kop.attr('title', kop.text());
	
	var subkop = $('div.content h2');
	subkop.attr('subtitle', subkop.text());
	
	$('ul#quotes li a').mouseover(showTitle);
	$('ul#quotes li a').mouseout(resetTitle);

	/* format menu left*/
	var menu_left = $('div#menu ul#navigation_left');
	
	/* format menu right*/
	var menu_right = $('div#menu ul#navigation_right');

	$('div#menu ul li').mouseover(tagBusy);
	$('div#menu ul li').mouseout(tagNotBusy);

	if($('body#home').length != 1) {
		var logo_links = "menu_logo_links1.gif";
		var logo_rechts = "menu_logo_rechts1.gif";
		if($('body#verhalen').length == 1) {
			var logo_rechts = "menu_logo_rechts3.gif";
		}
		if($('body#contact').length == 1) {
			var logo_rechts = "menu_logo_rechts2.gif";
		}
		if($('body#multimedia').length == 1) {
			var logo_links = "menu_logo_links2.gif";
		}
		if($('body#foto').length == 1) {
			var logo_links = "menu_logo_links3.gif";
		}
		
		menu_left.after('<img src="/gfx/' + logo_links + '" id="menu_logo_left"/>');
		menu_right.after('<img src="/gfx/' + logo_rechts + '" id="menu_logo_right"/>');
		
		if($('div#menu ul#navigation_left li.active').length > 0) {
			$('div#menu #menu_logo_left').hide();
			menu_right.hide();
			$('div#nav').mouseover(showMenuRight);
			$('div#nav').mouseout(hideMenuRight);
		} else {
			$('div#menu #menu_logo_right').hide();
			menu_left.hide();
			$('div#nav').mouseover(showMenuLeft);
			$('div#nav').mouseout(hideMenuLeft);
		}
		
	} else {
		
	}
});