$(function () {
	/* Linkerkant en Rechterkant tonen of verbergen + class op id content div */
	if ($('#subnavigatie:has(ul)').length == 0 && $('#CCIPlaceHolder_Rechterkant').is(':empty') || $('#rechterkant').length == 0){
		$('#container').addClass('volledig_breed');
	}
	else if ($('#subnavigatie:has(ul)').length == 0) {
		$('#container').addClass('breed');
	} 
	else if ($('#CCIPlaceHolder_Rechterkant:empty')){
		$('#container').addClass('breed');
	} 
	
	if($('#subnavigatie:has(ul)').length !== 0){
		$("#CCIPlaceHolder_Linkerkant").css("display","block");
	}
	$("#CCIPlaceHolder_Rechterkant:empty").parent().remove();
	
	/* Gallery inladen */	
	if (window.initGallery) { initGallery() }
	
	
    /* Indien ingelogd */
    var showGotoMyProfile = function(id) {
        if (!document.getElementById(id))
            return;
        var el = document.getElementById(id);
        el.innerHTML = 'U bent al ingelogd, klik <a href="/ledennet/homepage">hier</a> om naar het ledennet te gaan.';
        el.style.visibility = "visible";
    }
    showGotoMyProfile('text_loggedin');

    $("#login_form_container:has('#text_loggedin')").addClass("ingelogd");
	
	/* Sitemap in Footer plaatsen */
	$("#sitemap0").children().appendTo($("#sitemap"));
	$("#sitemap0").remove(); 

	$('#btnContentSearch').click(function () {
		searchSubmit($(this));
		return false;
	});
	
	var searchSubmit = function (sNode) {
		var theForm = $(sNode).parent();
		var searchInputText = $(theForm).find('input:text');
		var searchInputHidden = $(theForm).find('input:hidden');
		searchTerm = encodeURIComponent(searchInputText.val());
		if (searchTerm.length > 2) {
			$("form").submit(function () { return false });
			var searchUrl = searchInputHidden.val();
			searchUrl += searchTerm;
			window.location = searchUrl;
		} else {
			alert('Vul minstens drie tekens in om te zoeken.');
			return false;
		}
	}
	$(".zoekformulier input:text").each(function () {
		$(this).keydown(
				function (e) {
					if (e.keyCode == 13) {
						searchSubmit($(this));
						return false;
					}
				}
			);
		$(this).focus(
				function () {
					this.value = '';
				}
			);
		$(this).blur(
				function () {
					if (this.value == '') {
						this.value = 'Vul zoekterm in';
					}
				}
			)
	})
	var removeEmptyOptionalElements = function (s) {
		if (typeof s == "undefined") s = $("body");
		s.find(".blok, .tekst, .extra, .afbeelding, h2, h3, li").each(
			function () {
				var t = "";
				removeEmptyOptionalElements($(this));
				t = $.trim($(this).text().replace(/&nbsp;/g, ' '));
				if (t === "" && $(this).find("img,input,textarea,option,object,embed").length == 0) {
					$(this).remove();
				}
			}
		);
	}
	removeEmptyOptionalElements();
});
