$(function() {
	selectTab();
	if (window.initGallery) { initGallery() }
	$(".formbuilder_formpanel input:radio").addClass("noBorder");
	$(".formbuilder_formpanel input:checkbox").addClass("noBorder");
	$("input.SNOS_FileUpload:file").attr("size", "68");
	$("#siteprofiel input").each(function() {
		if ($(this).attr('readonly')) {
			$(this).addClass('readonly');
		}
	});
	$("input.SN-Form-PictureEdit-Profile-NewPicture-InputFile:file").attr("size", "60");
	$("h3:empty").remove();
	$("h2:empty").remove();
	$(".afb:empty").remove();
	$(".item:empty").remove();
	$("#homepage .BlokRoze:empty").remove();
	$(".afbeelding").each(function(){
		if( $(this).html().trim() == '')
		{
			$(this).remove();
		}
	});

	$(".tekst").each(function(){
		if( $(this).html().trim() == ' 						 						 						 					' || $(this).html().trim() == '')
		{
			$(this).remove();
		}
	});
	$(".tekst.oranje").each(function(){
		if( $(this).html().trim() == ' 							' || $(this).html().trim() == '')
		{
			$(this).remove();
		}
	});

	$(".bericht").each(function(){
		if( $(this).html().trim() == '')
		{
			$(this).remove();
		}
	});		
	

	$("div.bg_if_text:empty").remove();
	$("div#onderkant:empty").remove();
	$(".banner:empty").remove();
	$("span#formulier1:empty").remove();
	$("div.formulier:empty").remove();
	$(".ledenlijst .item a:first-child").click(function() {
		$('.open').removeClass('open');
		$('.zichtbaar').removeClass('zichtbaar');
		$(this).next().addClass("zichtbaar");
		$(this).addClass('open');
	});

	$(window).trigger("hashchange");

	/*$("#overzicht_leden .item").hover(function(){
	$(this).addClass("mouseover");
	}, function() {
	$(this).removeClass("mouseover");
	});*/

	$(".tekst:empty").remove();
	$(".tekst.oranje:empty").remove();
	$(".nieuwsArchief select,#doelSelect").change(function() {

		var selected = $(this).find("option:selected ");
		if (selected.val() != 0) {
			window.location = selected.val();
		}
	});

	$('#navigatie_box_6').change(
		function() {
			$('#navigatie_box_6 option:selected').each(
				function() {
					var location = this.value;
					if (location.match(/http:\/\//)) {
						window.open(location, '_blank', '');
					} else if (location > "") {
						window.location = location;
					}
				}
			);
		}
	);


	/* 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';
				}
			}
		)
	}
	)
});


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.showStart = 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;
	return t;
}
Date.prototype.showEnd = function(endDate){
	var d = this;
	var t = " tot ";

	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;
}


var addEvent = function(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent)
		obj.attachEvent('on' + type, function() { return fn.apply(obj, new Array(window.event)); });
}

var website = function() {
	{	// Private functions
		var initOnLoad;

		showGotoMyProfile = function(id) {
			if (!document.getElementById(id))
				return;
			var el = document.getElementById(id);
			el.innerHTML = '<a id="text_loggedin_vervanging" href="\/ledennet">Ga naar het ledennet</a>';
			el.style.visibility = "visible";
		}

		initOnLoad = function() {
			showGotoMyProfile('text_loggedin');
			$("#txtContentSearch").focus(); 
		}
	}
	{	// Public functions
		return ({
			onLoad: function() {
				addEvent(window, "load", initOnLoad);
			}
			,
			submitFormToSendmail: function(fn) {
				var submitFormHasErrors = false;
				if (typeof fn == 'function') {
					submitFormHasErrors = fn();
				}
				if (submitFormHasErrors == false) {
				}
			}
		});
	}
} ();
website.onLoad();
function selectTab() {
	var browser = navigator.userAgent;
	var ie_version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	
	if ($(".SNOS_WorkgroupMyWorkgroupNotificationsForm").length == 0) {
		$("#content").addClass("geen_os");
		$('.tabs a:attr[href="#discussies"]').parent().remove();
		$('.tabs a:attr[href="#shared"]').parent().remove();
		$('.tabs a:attr[href="#alerts"]').parent().remove();
	}
	var activeFragment = window.location.hash || $(".localtabs li:first span a").attr("href");
	var activeTab = "#algemeen";
	var activeTabDiv = "#tab_algemeen";
	$('.localtabgroup div.tab').hide();
	$(".localtabs li span a").each(
		function() {
			if (activeFragment == $(this).attr("href")) {
				activeTab = activeFragment;
				activeTabDiv = "#tab_" + activeFragment.toString().substring(1);
				$(this).parent().parent().parent().find("li.tabknop").removeClass('actief');
				$(this).parent().parent().addClass('actief');
				$('.tabgroup ' + activeTabDiv).show();
				if (browser === "MSIE" && ie_version <= 7) {
					window.location.hash = $(this).attr('href');
				}
				return false;
			}
		});
	$('.localtabs li.tabknop span > a').click(function() {
		window.location.hash = $(this).attr('href');
		return false; 
	});
	$(window).bind( 'hashchange', function(event) {
		if ($(".localtabs li").length > 0) {
			var hash = window.location.hash;
			if (browser !== "MSIE" || ie_version > 7) {
				if (hash === ''){hash = $(".localtabs li:first span a").attr("href");}
			}
			$('.tabs a:attr[href="'+hash+'"]').parent().parent().parent().find("li.tabknop").removeClass('actief');
			$('.tabs a:attr[href="' +hash+ '"]').parent().parent().addClass('actief');
			activeTabDiv = "#tab_" + hash.toString().substring(1);
			$(activeTabDiv).parent().find('.tab').hide();
			$(activeTabDiv).show();
		}
	});
}

/*
 * jQuery BBQ: Back Button & Query Library - v1.3pre - 8/26/2010
 * http://benalman.com/projects/jquery-bbq-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,r){var h,n=Array.prototype.slice,t=decodeURIComponent,a=$.param,j,c,m,y,b=$.bbq=$.bbq||{},s,x,k,e=$.event.special,d="hashchange",B="querystring",F="fragment",z="elemUrlAttr",l="href",w="src",p=/^.*\?|#.*$/g,u,H,g,i,C,E={};function G(I){return typeof I==="string"}function D(J){var I=n.call(arguments,1);return function(){return J.apply(this,I.concat(n.call(arguments)))}}function o(I){return I.replace(H,"$2")}function q(I){return I.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(K,P,I,L,J){var R,O,N,Q,M;if(L!==h){N=I.match(K?H:/^([^#?]*)\??([^#]*)(#?.*)/);M=N[3]||"";if(J===2&&G(L)){O=L.replace(K?u:p,"")}else{Q=m(N[2]);L=G(L)?m[K?F:B](L):L;O=J===2?L:J===1?$.extend({},L,Q):$.extend({},Q,L);O=j(O);if(K){O=O.replace(g,t)}}R=N[1]+(K?C:O||!N[1]?"?":"")+O+M}else{R=P(I!==h?I:location.href)}return R}a[B]=D(f,0,q);a[F]=c=D(f,1,o);a.sorted=j=function(J,K){var I=[],L={};$.each(a(J,K).split("&"),function(P,M){var O=M.replace(/(?:%5B|=).*$/,""),N=L[O];if(!N){N=L[O]=[];I.push(O)}N.push(M)});return $.map(I.sort(),function(M){return L[M]}).join("&")};c.noEscape=function(J){J=J||"";var I=$.map(J.split(""),encodeURIComponent);g=new RegExp(I.join("|"),"g")};c.noEscape(",/");c.ajaxCrawlable=function(I){if(I!==h){if(I){u=/^.*(?:#!|#)/;H=/^([^#]*)(?:#!|#)?(.*)$/;C="#!"}else{u=/^.*#/;H=/^([^#]*)#?(.*)$/;C="#"}i=!!I}return i};c.ajaxCrawlable(0);$.deparam=m=function(L,I){var K={},J={"true":!0,"false":!1,"null":null};$.each(L.replace(/\+/g," ").split("&"),function(O,T){var N=T.split("="),S=t(N[0]),M,R=K,P=0,U=S.split("]["),Q=U.length-1;if(/\[/.test(U[0])&&/\]$/.test(U[Q])){U[Q]=U[Q].replace(/\]$/,"");U=U.shift().split("[").concat(U);Q=U.length-1}else{Q=0}if(N.length===2){M=t(N[1]);if(I){M=M&&!isNaN(M)?+M:M==="undefined"?h:J[M]!==h?J[M]:M}if(Q){for(;P<=Q;P++){S=U[P]===""?R.length:U[P];R=R[S]=P<Q?R[S]||(U[P+1]&&isNaN(U[P+1])?{}:[]):M}}else{if($.isArray(K[S])){K[S].push(M)}else{if(K[S]!==h){K[S]=[K[S],M]}else{K[S]=M}}}}else{if(S){K[S]=I?h:""}}});return K};function A(K,I,J){if(I===h||typeof I==="boolean"){J=I;I=a[K?F:B]()}else{I=G(I)?I.replace(K?u:p,""):I}return m(I,J)}m[B]=D(A,0);m[F]=y=D(A,1);$[z]||($[z]=function(I){return $.extend(E,I)})({a:l,base:l,iframe:w,img:w,input:w,form:"action",link:l,script:w});k=$[z];function v(L,J,K,I){if(!G(K)&&typeof K!=="object"){I=K;K=J;J=h}return this.each(function(){var O=$(this),M=J||k()[(this.nodeName||"").toLowerCase()]||"",N=M&&O.attr(M)||"";O.attr(M,a[L](N,K,I))})}$.fn[B]=D(v,B);$.fn[F]=D(v,F);b.pushState=s=function(L,I){if(G(L)&&/^#/.test(L)&&I===h){I=2}var K=L!==h,J=c(location.href,K?L:{},K?I:2);location.href=J};b.getState=x=function(I,J){return I===h||typeof I==="boolean"?y(I):y(J)[I]};b.removeState=function(I){var J={};if(I!==h){J=x();$.each($.isArray(I)?I:arguments,function(L,K){delete J[K]})}s(J,2)};e[d]=$.extend(e[d],{add:function(I){var K;function J(M){var L=M[F]=c();M.getState=function(N,O){return N===h||typeof N==="boolean"?m(L,N):m(L,O)[N]};K.apply(this,arguments)}if($.isFunction(I)){K=I;return J}else{K=I.handler;I.handler=J}}})})(jQuery,this);
/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
