
function replaceContent(id, data)
{

	$("#"+id).replaceWith(data);

}

function initFontResize() {
	setFont();
	$("#fontGrootteM").click(function() {
		setFont("");
	});

	$("#fontGrootteL").click(function() {
		setFont("groot");
	});
	
	$("#fontGrootteXL").click(function() {
		setFont("extra_groot");
	});
}
function tabSelect() {
	$('.tabmenu div.tab').hide();
	$('.tabmenu').each(
					function() {
						$(this).find('div.tab:first').show();
					});

	$('.tabmenu li.tabknop:first').addClass('actief');

	$('li.tabknop > a').click(function() {
		$(this).parent().parent().find("li.tabknop").removeClass('actief');

		$(this).parent().addClass('actief');
		var currentTab = $(this).attr('href');
		$(this).parent().parent().parent().find('div.tab').hide();
		$(currentTab).show();
		return false;
	});}

function setFont(fontSize) {

	fontSize = (fontSize != undefined ? fontSize : readCookie("fontType") || "");
	
	createCookie("fontType", fontSize, 366);
	if (fontSize == "") {
		$("#container").removeClass("extra_groot");
		$("#container").removeClass("groot");
	}
	if (fontSize == "groot") {
		$("#container").addClass("groot");
		$("#container").removeClass("extra_groot");
	}else {
		$("#container").removeClass("groot");
	}
	if (fontSize == "extra_groot") {
		$("#container").addClass("extra_groot");
		$("#container").removeClass("groot");
	} else {
		$("#container").removeClass("extra_groot");
	}
}

$(function () {

	initFontResize();
	tabSelect();

	if (document.body.id == 'homepage') {
		initShowCase();
		setShowFadeEventHandlers("#showCase");
	}

	$('ul.sf-menu').superfish({
		autoArrows: false,
		dropShadows: true,
		speed: 1,
		delay: 0
	});

	if (window.initGallery) { initGallery() }

	/* Zoekformulier */
	$('.zoekknop').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 > 1) {
			$("form").submit(function () { return false });
			var searchUrl = searchInputHidden.val();
			searchUrl += searchTerm;
			window.location = searchUrl;
		} else {
			alert('Vul minstens twee tekens in om te zoeken.');
			return false;
		}
	}
	$("#zoek input:text").each(function () {
		$(this).keydown(
			function (e) {
				if (e.keyCode == 13) {
					searchSubmit($(this));
					return false;
				}
			}
		);
		$(this).focus(
			function () {
				this.value = '';
				//				this.className = 'zoekveld';
			}
		);
		$(this).blur(
			function () {
				if (this.value == '') {
					this.value = '';
					//					this.className = 'zoekveld';
				}
			}
		)
	}
	)
	$("div.leesmeer.kleur_onderin_blok:empty").hide();
	$("div#CCIPlaceHolder_Content .afbeelding:empty").remove();
	$("div#CCIPlaceHolder_Content .tekst .afbeelding:empty").remove();
	$("div#CCIPlaceHolder_Content .tekst:empty").remove();
	$("#slide_banner a:empty").remove();
	$(".advertensie:empty").remove();
	$(".inhoud_blok h2:empty").remove();
	$(".inhoud_blok .tekst:empty").remove();
	$(".inhoud_blok .extra:empty").remove();
	$(".inhoud_blok:empty").remove();
	$(".bestuur:empty").remove();
	$("input:radio").addClass("noBorder");
	$("input:checkbox").addClass("noBorder");

	$("h2:empty").remove();
	$(".tekst:empty").remove();
	$(".leesmeer:empty").remove();
	$(".border:empty").remove();
	$(".item:empty").remove();

	$(".poll_archief_knop:empty").remove();
	$("#video_album li:nth-child(3n)").addClass("derde");
	$("#video_album_extern .text:empty").remove();
	$("div#video_album_extern .laatste:empty").remove();
	$("div#video_album_extern .line:empty").remove();
	$("#video_album_extern:empty").remove();

	$(".afbeelding:empty").remove();
	$(".blok.advertentie:empty").remove();

	jQuery.jQueryRandom = 0;
	jQuery.extend(jQuery.expr[":"],
	{
		random: function (a, i, m, r) {
			if (i == 0) {
				jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
			};
			return (i == jQuery.jQueryRandom);
		}
	});
	$("#leden_thuiswinkel b").filter("b:empty").remove();
	$("#leden_thuiswinkel b").filter("b:random").show().css("display", "block");
	setInterval(function () { $("#leden_thuiswinkel b").hide(); $("#leden_thuiswinkel b").filter("b:random").show().css("display", "block"); }, 4000);


	$('li.klikbaar').click(function () {
		window.location = $('a', this).attr('href');
	});


	$("#video_album li").hover(
		function () {
			$(this).addClass("highlight");
		},
		function () {
			$(this).removeClass("highlight");
		}
	);


});


function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}
/*
* Superfish v1.4.8 - jQuery menu widget
* Copyright (c) 2008 Joel Birch
*
* Dual licensed under the MIT and GPL licenses:
* 	http://www.opensource.org/licenses/mit-license.php
* 	http://www.gnu.org/licenses/gpl.html
*
* CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
*/

; (function($) {
	$.fn.superfish = function(op) {

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="', c.arrowClass, '"> &#187;</span>'].join('')),
			over = function() {
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function() {
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer = setTimeout(function() {
					o.retainPath = ($.inArray($$[0], o.$path) > -1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.', o.hoverClass].join('')).length < 1) { over.call(o.$path); }
				}, o.delay);
			},
			getMenu = function($menu) {
				var menu = $menu.parents(['ul.', c.menuClass, ':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a) { $a.addClass(c.anchorClass).append($arrow.clone()); };

		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({}, sf.defaults, op);
			o.$path = $('li.' + o.pathClass, this).slice(0, o.pathLevels).each(function() {
			$(this).addClass([o.hoverClass, c.bcClass].join('sfHover'))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;

			$('li:has(ul)', this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over, out).each(function() {
				if (o.autoArrows) addArrow($('>a:first-child', this));
			})
			.not('.' + c.bcClass)
				.hideSuperfishUl();

			var $a = $('a', this);
			$a.each(function(i) {
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function() { over.call($li); }).blur(function() { out.call($li); });
			});
			o.onInit.call(this);

		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function() {
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity != undefined)
			this.toggleClass(sf.c.shadowClass + '-off');
	};
	sf.c = {
		bcClass: 'sf-breadcrumb',
		menuClass: 'sf-js-enabled',
		anchorClass: 'sf-with-ul',
		arrowClass: 'sf-sub-indicator',
		shadowClass: 'sf-shadow'
	};
	sf.defaults = {
		hoverClass: 'sfHover',
		pathClass: 'overideThisToUse',
		pathLevels: 1,
		delay: 800,
		animation: { opacity: 'show' },
		speed: 'normal',
		autoArrows: true,
		dropShadows: true,
		disableHI: false, 	// true disables hoverIntent detection
		onInit: function() { }, // callback functions
		onBeforeShow: function() { },
		onShow: function() { },
		onHide: function() { }
	};
	$.fn.extend({
		hideSuperfishUl: function() {
			var o = sf.op,
				not = (o.retainPath === true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.', o.hoverClass].join(''), this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility', 'hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl: function() {
			var o = sf.op,
				sh = sf.c.shadowClass + '-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility', 'visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation, o.speed, function() { sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);

var initShowCase = function() {
	var current = $("#showCase .case:first");
	current.find(".item").css("opacity", "1")
	$("#showCase .case").each(
		function() {
			$(this).hover(
				function() {
					current.removeClass("aktief");
					current = $(this);
					$(this).addClass("aktief"); 
				},
				function() { }
			)
			
		}
	);
}

Date.prototype.setISO8601 = function(string) {
	var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
	var d = string.match(new RegExp(regexp));


	var date = new Date(d[1], 0, 1);

	if (d[3]) { date.setMonth(d[3] - 1); }
	if (d[5]) { date.setDate(d[5]); }
	if (d[7]) { date.setHours(d[7]); }
	if (d[8]) { date.setMinutes(d[8]); }
	if (d[10]) { date.setSeconds(d[10]); }
	if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }

	
	time = (Number(date) );
	this.setTime(Number(time));
}




function setShowFadeEventHandlers(containerExpression) {
	// Fade alle contentgebieden instant uit en verwijder alle active classes
	$(containerExpression + " .item").fadeOut(0);
	$(containerExpression + " .item").removeClass("active");
	$(containerExpression + " .case").removeClass("active");

	// Fade content 1 in en voeg een class active toe
	$(containerExpression + " .item:eq(0)").fadeIn(400);
	$(containerExpression + " .item:eq(0)").addClass("active");
	$(containerExpression + " .case:eq(0)").addClass("active");

	// Voeg hover event handlers toe aan de navigaties
	$(containerExpression + " .case").each(function() {
		$(this).hover(function() {
			// Controleer of de betreffende content al is ingefade, zo niet ga verder
			if (!$(this).next(".item:eq(0)").hasClass("active")) {
				// Breng alle lopende animaties op de content elementen instant naar hun eindpositie
				$(containerExpression + " .item").stop(true, true);

				// Fade alle contentgebieden uit en verwijder alle active classes
				$(containerExpression + " .item").fadeOut(400);
				$(containerExpression + " .item").removeClass("active");
				$(containerExpression + " .case").removeClass("active");

				// Fade de betreffende content in en voeg een class active toe
				$(this).next(".item:eq(0)").fadeIn(400);
				$(this).next(".item:eq(0)").addClass("active");
				$(this).addClass("active");
			}
		});
	});
}




Date.prototype.setISO8601 = function (string) {
    var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
    var d = string.match(new RegExp(regexp));

    var offset = 0;
    var date = new Date(d[1], 0, 1);

    if (d[3]) { date.setMonth(d[3] - 1); }
    if (d[5]) { date.setDate(d[5]); }
    if (d[7]) { date.setHours(d[7]); }
    if (d[8]) { date.setMinutes(d[8]); }
    if (d[10]) { date.setSeconds(d[10]); }
    if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
    if (d[14]) {
        offset = (Number(d[16]) * 60) + Number(d[17]);
        offset *= ((d[15] == '-') ? 1 : -1);
    }

    // offset -= date.getTimezoneOffset();
    time = (Number(date) + (offset * 60 * 1000));
    this.setTime(Number(time));
}

Date.prototype.showDate = function(endDate){
	var d = this;
	
	var monthArray = ['jan','feb','mrt','apr','mei','jun','jul','aug','sept','okt','nov','dec'];
	var y = this.getYear();

	var t = "";
	t += this.getDate() + " ";
	t += monthArray[this.getMonth() ] + "  ";
	t += y> 1900 ? y : (y+1900);
	t += ", ";
	var hours = this.getHours();
	if (hours < 10) 
	{
		t += "0";
	}
	t += hours + ":";
	var minutes = this.getMinutes();
	if (minutes < 10) 
	{
		t += "0";
	}
	t += minutes;
	t += "  uur";
	return t;
}
