document.write('<script src="Design.js" type="text/javascript"></script>');
/********************************************************************************
Algemene functies instellingen
********************************************************************************/
var doelgroepid = 0;
var themaid = 0;
var PageTitle = '';
var ItemTitle = '';
var bedrijfsnaam = '';

var overzichtTextMaxLength = 580;

function limitStrLength(str, maxlen) {
	if (maxlen > 0 && (str.length > maxlen)) {
		var toNextBoundary = -1;
		var tmp1 = -1;
		var tmp2 = -1;
		var tmp3 = -1;

		tmp1 = str.indexOf(" ", maxlen) - maxlen;
		tmp2 = str.indexOf(".", maxlen) - maxlen;
		tmp3 = str.indexOf(",", maxlen) - maxlen;

		(tmp1 < -1) ? tmp1 = 100000 : tmp1;
		(tmp2 < -1) ? tmp2 = 100000 : tmp2;
		(tmp3 < -1) ? tmp3 = 100000 : tmp3;

		toNextBoundary = Math.min(tmp1, tmp2);
		toNextBoundary = Math.min(toNextBoundary, tmp3);

		return ((toNextBoundary > -1) && (toNextBoundary < str.length)) ? (str.substr(0, (maxlen + toNextBoundary)) + "...") : str;
	}
	return str;
}

function queryStr(key) {
	qs = window.location.search.substring(1);
	pairs = qs.split("&");
	for (i = 0; i < pairs.length; i++) {
		sp = pairs[i].split("=");
		if (sp[0].toUpperCase() == key.toUpperCase()) {
			return sp[1];
		}
	}
	return "";
}

/* Menu bij mouse-out langer (2 sec.) in beeld houden */
/* omdat het met alleen CSS direct verdwijnt, wat ook onbedoeld kan gebeuren. */
var overMenu = false;
var hideTimeout = null;
var menuIndex = -1;
function hideMenu() {
	if (!overMenu && menuIndex > -1) {
		$("ul").eq(menuIndex).css("display", "");
	}
}
$(document).ready(function() {
	$("div#menuh > ul > li")
  .bind("mouseenter", function() {
  	$("ul", this).css("display", "");
  });

	$("div#menuh ul.submenu")
   .bind("mouseenter", function() {
   	overMenu = true;
   	clearTimeout(hideTimeout);
   })
   .bind("mouseleave", function() {
   	$(this).css("display", "block");
   	overMenu = false;
   	menuIndex = $("ul").index(this);
   	hideTimeout = setTimeout("hideMenu()", 1250);
   })
   .parent().bind("mouseenter", function() {
   	if (menuIndex) hideMenu();
   });

	// Uitgelicht foto's ook aanklikbaar maken, met dezelfde href als de hyperlink.  
	$("td.uitgelichtTabelCel").click(function() {
		location.href = $(this).find("a").attr("href");
	});
});

$(document).ready(onReady_BreadCrumb);

function showButtons() {
	if (!showContact) {
		$("#ContactLink").hide();
	}
	if (!showDisclaimer) {
		$("#DisclaimerLink").hide();
	}
	if (!showCopyright) {
		$("#CopyrightLink").hide();
	}
	if (!showPrivacy) {
		$("#PrivacyLink").hide();
	}
}

/********************************************************************************
Breadcrumb functionaliteit
********************************************************************************/
function onReady_BreadCrumb() {
	var huidige_pageid = 0;
	var huidige_selectedid = 0;
	var vorige_pageid = 0;
	var vorige_selectedid = 0;
	var vorige_itemtitle = '';
	var vorige_pagetitle = '';
	var cookie_pageid = 0;
	var cookie_selectedid = 0;
	var cookie_pagetitle = '';
	var cookie_itemtitle = '';
	var trail = '';
	var trailTitle = '';
	var debugstr = '';

	if (queryStr("pageId")) {
		huidige_pageid = parseInt(queryStr("pageId"));
	}

	if (queryStr("selectedId")) {
		huidige_selectedid = parseInt(queryStr("selectedId"));
	}

	if (!(($.cookie('Breadcrumb_Selectedid') == '') || ($.cookie('Breadcrumb_Selectedid') == null))) {
		if (!(isNaN(parseInt($.cookie('Breadcrumb_Selectedid'))))) {
			vorige_selectedid = parseInt($.cookie('Breadcrumb_Selectedid'));
		}

		vorige_itemtitle = $.cookie('Breadcrumb_ItemTitle');
	}

	if (!(($.cookie('Breadcrumb_Pageid') == '') || ($.cookie('Breadcrumb_Pageid') == null))) {
		if (!(isNaN(parseInt($.cookie('Breadcrumb_Pageid'))))) {
			vorige_pageid = parseInt($.cookie('Breadcrumb_Pageid'));
		}

		vorige_pagetitle = $.cookie('Breadcrumb_PageTitle');
	}

	debugstr += 'HuidigePageID ' + huidige_pageid + '\n';
	debugstr += 'HuidigeSelectedID ' + huidige_selectedid + '\n';
	debugstr += 'VorigeSelectedID ' + vorige_selectedid + '"' + vorige_itemtitle + '" \n';
	debugstr += 'VorigePageID ' + vorige_pageid + '"' + vorige_pagetitle + '" \n';
	//alert(debugstr);

	trail += '<a href="default.asp" class="BreadcrumbItem">HOME</a>';

	if (huidige_pageid != 0) {
		trail += ' &gt; <a href="#" class="BreadcrumbItem">' + PageTitle + '</a>';
		if (PageTitle != '')
			trailTitle += ' - ' + PageTitle;
	}
	else {
		if ((vorige_pageid != 0) && (vorige_pageid > 1)) {
			trail += ' &gt; <a href="javascript:history.go(-1);" class="BreadcrumbItem">' + vorige_pagetitle + '</a>';
			trail += ' &gt; <a href="#" class="BreadcrumbItem">' + ItemTitle + '</a>';
			if (vorige_pagetitle != '')
				trailTitle += ' - ' + vorige_pagetitle;
			if (ItemTitle != '')
				trailTitle += ' - ' + ItemTitle;
		}
		else {
			if (ItemTitle != '') {
				trail += ' &gt; <a href="#" class="BreadcrumbItem">' + ItemTitle + '</a>';
				trailTitle += ' - ' + ItemTitle;
			}
			else {
				trail += ' &gt; <a href="#" class="BreadcrumbItem">' + PageTitle + '</a>';
				trailTitle += ' - ' + PageTitle;
			}
		}
	}

	debugstr = '';
	debugstr += 'ItemTitle ' + ItemTitle + '\n';
	debugstr += 'PageTitle ' + PageTitle + '\n';
	debugstr += 'SelectedID ' + huidige_selectedid + '\n';
	debugstr += 'PageID ' + huidige_pageid + '\n';
	//alert(debugstr);

	if ((huidige_pageid == 0) && (vorige_pageid != 0)) {
		cookie_pagetitle = vorige_pagetitle;
		cookie_pageid = vorige_pageid;
	}
	else {
		cookie_pagetitle = PageTitle;
		cookie_pageid = huidige_pageid;
	}

	if ((huidige_selectedid == 0) && (vorige_selectedid != 0)) {
		cookie_selectedid = vorige_selectedid;
		cookie_itemtitle = vorige_itemtitle;
	}
	else {
		cookie_selectedid = huidige_selectedid;
		cookie_itemtitle = ItemTitle;
	}

	// Bijwerken van het cookie (alleen als pagina of itemid anders is dan huidige)
	$.cookie('Breadcrumb_ItemTitle', cookie_itemtitle);
	$.cookie('Breadcrumb_Selectedid', cookie_selectedid + '');
	$.cookie('Breadcrumb_PageTitle', cookie_pagetitle);
	$.cookie('Breadcrumb_Pageid', cookie_pageid + '');

	// Breadcrumb tonen
	$('div#breadcrumbTrail').html(trail);

	// PageTitle tonen
	document.title = bedrijfsnaam + trailTitle;
}

/********************************************************************************
Hoofdpagina
********************************************************************************/

function fillLanguageChoice() {
	if (arrLanguages) {
		var sHTML = "";

		for (var i = 0; i < arrLanguages.length; i++) {
			var sImg = "<a href='" + arrLanguages[i].lanURL + "' title='" + arrLanguages[i].lanNaam + "'>"
			sImg += "<img class='LanguageImg' src='" + arrLanguages[i].lanImg + "' alt='" + arrLanguages[i].lanNaam + "' />";
			sImg += "</a>";
			sHTML += sImg;
		}

		sHTML = "";

		for (var i = 0; i < arrLanguages.length; i++) {
			var sImg = "";
			sImg += " | <a class='copyrightlink' href='" + arrLanguages[i].lanURL + "' title='" + arrLanguages[i].lanNaam + "'>"
			sImg += arrLanguages[i].lanAfk;
			sImg += "</a>";
			sHTML += sImg;
		}

		$("#LanguageChoice").html(sHTML);
	}
}


/********************************************************************************
Overzichtspagina's
********************************************************************************/
var aantalPerPagina;
var huidigePagina;
var overzichtspagina;
var metFoto;
var jBlokNaam;

metFoto = false;

function onReady_Overzichtspagina() {
	/* max. tekstlengte (aantal tekens) in kolom vergroten als er geen foto is */
	if ($("img#overzichtGroot").get(0) === undefined) {
		overzichtTextMaxLength += 500;
	}

	if (queryStr("npag")) {
		var overzichtspagina = parseInt(queryStr("npag"));
		if ((overzichtspagina > 0) && (overzichtspagina <= Math.ceil(arrOverzicht.length / aantalPerPagina))) {
			huidigePagina = overzichtspagina;
		}
	}

	/* tekstlengte beperken, uitgaand van instelling overzichtTextMaxLength (zie boven) */
	$("span#pageNumTotal").text(Math.ceil(arrOverzicht.length / aantalPerPagina));
	$("span#pageNumCurrent").text(' ' + huidigePagina);
	vulOverzichtsBlokken();
	var contentHTML = $("div#editorContent").hide().html();
	var re = /<\/?div.*?>/gi;
	contentHTML = contentHTML.replace(re, "").split("[pagebreak]")[0];
	$("div#editorContent").html(contentHTML);
	contentText = $("div#editorContent").text();
	var newLength = overzichtTextMaxLength + (contentHTML.length - contentText.length);
	var lastLT = contentHTML.substr(0, newLength).lastIndexOf("</");
	var closeGT = contentHTML.indexOf(">", lastLT);
	if (closeGT == -1) closeGT = newLength;
	contentPart = contentHTML.substr(0, closeGT + 1);
	$("div#editorContent").html(contentPart);
	tempText = $("div#editorContent").text();
	/*if (tempText.length < overzichtTextMaxLength) {
	$("div#editorContent").append(" "+contentText.substr(tempText.length, (overzichtTextMaxLength-tempText.length)));
	}*/
	if (contentText.length > overzichtTextMaxLength) $("div#editorContent").append("...");
	$("div#editorContent").show();

}

function vulOverzichtsBlokken() {
	var startIndex = (aantalPerPagina * (huidigePagina - 1));
	var jBlok = new Object();
	var j = 0;
	for (var i = 0; i < aantalPerPagina; i++) {
		j = i + startIndex;
		jBlok = $("td#" + jBlokNaam + (i + 1));
		jBlok.html("");
		if (arrOverzicht[j] != null) {
			if (metFoto) {
				fotoURL = (arrOverzicht[j].foto != "") ? ("showpicture.asp?vid=" + arrOverzicht[j].foto) : "images/spacer.gif";
				jBlok.hide().append('<a class="nieuwsArtikelLink" href="default.asp?pageid=' + pageid + '&themaid=' + themaid + '&doelgroepid=' + doelgroepid + '&selectedid=' + arrOverzicht[j].id + '&npag=' + huidigePagina + '" title="' + arrOverzicht[j].titel + ' - ' + arrOverzicht[j].subtitel + '"><img src="' + fotoURL + '" width="62" height="71" border="0" /><b>' + limitStrLength(arrOverzicht[j].titel, 33) + '</b>' + ((arrOverzicht[j].titel != "") ? '<br />' : '') + limitStrLength(arrOverzicht[j].subtitel, 30) + '</a>');
			}
			else {
				jBlok.hide().append('<a class="artikelLink" href="default.asp?pageid=' + pageid + '&themaid=' + themaid + '&doelgroepid=' + doelgroepid + '&selectedid=' + arrOverzicht[j].id + '&npag=' + huidigePagina + '" title="' + arrOverzicht[j].titel + ' - ' + arrOverzicht[j].subtitel + '">' + limitStrLength(arrOverzicht[j].titel, 33) + ((arrOverzicht[j].titel != "") ? '<br />' : '') + '<b>' + limitStrLength(arrOverzicht[j].subtitel, 30) + '</b></a>');
			}
			jBlok.fadeIn("fast");
		}
	}
	$("span#pageNumCurrent").text(' ' + huidigePagina);
}

function volgendeOverzichtsPagina() {
	if (++huidigePagina > Math.ceil(arrOverzicht.length / aantalPerPagina)) {
		huidigePagina = Math.ceil(arrOverzicht.length / aantalPerPagina);
	}
	else {
		vulOverzichtsBlokken();
	}
}

function vorigeOverzichtsPagina() {
	if (--huidigePagina < 1) {
		huidigePagina = 1;
	}
	else {
		vulOverzichtsBlokken();
	}
}

function openDetailpage(itemId) {
	document.location = 'default.asp?item=' + itemId + '&amp;pag=1&themaid=' + themaid + '&doelgroepid=' + doelgroepid;
}

/********************************************************************************
Detailpagina's
********************************************************************************/
var contentArray = [];

function onReady_Detailpagina() {
	var contentHTML = $("div#editorContent").html();

	$("div#editorContent").hide();
	$("div#leesVerder").hide();

	var re = /<\/?div.*?>/gi;
	if (contentHTML != null) {
		contentHTML = contentHTML.replace(re, "");
		contentArray = contentHTML.split("[pagebreak]");
		re = /^ ?<br>/i;
		for (var i = 0; i < contentArray.length; i++) {
			contentArray[i] = contentArray[i].replace(re, "");
		}
		if (queryStr("pag")) {
			var pag = parseInt(queryStr("pag"));
			if ((pag > 0) && (pag < contentArray.length + 1)) {
				huidigePagina = pag;
			}
		}
		$("span#pageNumTotal").text(contentArray.length);
		$("span#pageNumCurrent").text(' ' + huidigePagina);
		$("div#editorContent").html(contentArray[huidigePagina - 1]);
	}
	$("div#editorContent").show();
	/*if ( contentArray.length > 1 ) {
	$("div#leesVerder").show();
	}*/
}

function volgendePagina() {
	if (++huidigePagina > contentArray.length) {
		huidigePagina = contentArray.length;
	}
	else {
		bladerPagina();
		if ((huidigePagina + 1) > contentArray.length) {
			$("div#leesVerder").hide();
		}
	}
}

function vorigePagina() {
	if (--huidigePagina < 1) {
		huidigePagina = 1;
	}
	else {
		bladerPagina();
		/*$("div#leesVerder").show();*/
	}
}

function bladerPagina() {
	$("div#editorContent").hide();
	$("span#pageNumCurrent").text(' ' + huidigePagina);
	$("div#editorContent").html(contentArray[huidigePagina - 1]);
	$("div#editorContent").fadeIn("fast");
	if (afbeeldingen != null) {
		var afbId = (huidigePagina > 6 || afbeeldingen[huidigePagina].id == "") ? afbeeldingen[1].id : afbeeldingen[huidigePagina].id;
		var afbAlt = (huidigePagina > 6 || afbeeldingen[huidigePagina].id == "") ? afbeeldingen[1].alt : afbeeldingen[huidigePagina].alt;
		$("img#afbeelding").attr("src", "showpicture.asp?vid=" + afbId);
		$("img#afbeelding").attr("alt", afbAlt);
		$("img#afbeelding").attr("title", afbAlt);
	}
}

/********************************************************************************
 *IN BEELD PAGINA
********************************************************************************/

function onReady_inBeeld() {
  $("span#pageNumTotal").text( Math.ceil(inbeeldItems.length/aantalPerPagina) );
  $("span#pageNumCurrent").text(' ' + huidigePagina );

  $("a#knopVergroot").click(vergrootKlik);
  $("img#itemFoto").click(vergrootKlik);

  $("td.inBeeldItem").each( function(index, domElement) {
    
    $(this).find("img")
      .load(function () {
        // set the image hidden by default    
        $(this).hide();
      
        $(this).fadeIn("slow");
      })
      
      // if there was an error loading the image, react accordingly
      .error(function () {
        // notify the user that the image could not be loaded
      })
     });
            
     vulInbeeldBlokken();
}

function vulInbeeldBlokken() {
  $("span#pageNumCurrent").text(' ' + huidigePagina );
  $("td.inBeeldItem").each( function(index, domElement) {
    tempIndex = ((huidigePagina-1)*aantalPerPagina) + index;

    if (inbeeldItems[tempIndex] != null) {

      $(this).find("a.fotoLink")
        .attr("href", "showpicture.asp?vid="+inbeeldItems[tempIndex].groteFotosID[0])
        .attr("title", inbeeldItems[tempIndex].titel)
        .click(function(e){toonItemDetails(((huidigePagina-1)*aantalPerPagina) + index); actiefItem=((huidigePagina-1)*aantalPerPagina) + index; return false});
      
      $(this).find("img")      
        // *finally*, set the src attribute of the new image to our image
        .attr("src", "showpicture.asp?vid="+inbeeldItems[tempIndex].fotoKleinID)
        .attr("alt", inbeeldItems[tempIndex].bijschrift)
        .attr("title", inbeeldItems[tempIndex].bijschrift);
        
      strThumbTitel = String(inbeeldItems[tempIndex].titel);
      $(this)
        .find("div.fotoThumbTekst > span.fotoThumbTitel")
          .text(strThumbTitel.substr(0,37) + ((strThumbTitel.length>37)?"...":""))
          .parent().find("span.fotoThumbFotograaf")
          .text("Foto: " + inbeeldItems[tempIndex].fotograaf +" "+ inbeeldItems[tempIndex].datumKort)
          .parent().show();
    }
    else {
      $(this).find("a.fotoLink")
        .removeAttr("href")
        .removeAttr("title")
        .unbind();
      $(this).find("img")
        .attr("src", "images/spacer.gif")
        .attr("alt", "")
        .attr("title", "");
      $(this).find("div.fotoThumbTekst")
        .hide();
    }
  });
  // Toon automatisch eerste item op pagina
  actiefItem=((huidigePagina-1)*aantalPerPagina);
  toonItemDetails((huidigePagina-1)*aantalPerPagina);
}

/*function toonItemGroot(titel, urlFoto, groepNaam, itemIndex) {
    $("#TB_window").remove();
    $("body").append("<div id='TB_window'></div>");
    tb_show(titel, urlFoto, groepNaam, itemIndex);        
    return false;
}*/

function toonItemDetails( itemIndex ) {
  // detail info vullen
  $("img#itemFoto").hide().attr("src", "showpicture.asp?vid="+inbeeldItems[itemIndex].fotoMiddelID).fadeIn("slow");
  $("div#itemTitel").html(inbeeldItems[itemIndex].titel);
  $("div#itemSubtitel").html(inbeeldItems[itemIndex].subtitel);
  $("div#itemFotograaf").html("Foto: " + inbeeldItems[itemIndex].fotograaf);
  $("div#itemDatum").html(inbeeldItems[itemIndex].datum);
}

function volgendeInbeeldPagina() {
  if (++huidigePagina > Math.ceil(inbeeldItems.length/aantalPerPagina)) {
    huidigePagina = Math.ceil(inbeeldItems.length/aantalPerPagina);
  }
  else {
    vulInbeeldBlokken();
  }
}

function vorigeInbeeldPagina() {
  if (--huidigePagina < 1) {
    huidigePagina = 1;
  }
  else {
    vulInbeeldBlokken();
  }
}

function vergrootKlik(event) {
  //tb_show(inbeeldItems[actiefItem].titel, "showpicture.asp?vid="+inbeeldItems[actiefItem].groteFotosID[0], "gallery-inbeeld", actiefItem);
  tb_show(inbeeldItems[actiefItem].titel, "showpicture.asp?vid="+inbeeldItems[actiefItem].groteFotosID[0], "gallery-inbeeld", 0);
  return false;
}

/********************************************************************************
 *Routebeschrijving
********************************************************************************/

function initialize() {
						geocoder = new google.maps.Geocoder();
						var myOptions = {
						  zoom: 15,
						  mapTypeId: google.maps.MapTypeId.SATELLITE
						}
						map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

						geocoder.geocode( { address: address}, function(results, status) {
						  if (status == google.maps.GeocoderStatus.OK && results.length) {
							// You should always check that a result was returned, as it is
							// possible to return an empty results object.
							if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
							  map.setCenter(results[0].geometry.location);
							  var marker = new google.maps.Marker({
								  position: results[0].geometry.location,
								  icon: 'images/tbi.png',
								  map: map
							  });
							}
						  } else {
							alert("Het adres was niet gevonden vanwege de volgende fout: " + status);
						  }
						});
					}

/********************************************************************************
********************************************************************************/
var themas = new Array();
var themaIdx = new Array();

function btnDoelgroepMenuclick(iDoelgroepid) {
	if (themaid != '') {
		document.location = 'default.asp?pageid=subhomepage&themaid=' + themaid + '&doelgroepid=' + iDoelgroepid;
	}
}

function btnThemaMenuclick(iThemaid) {
	if (doelgroepid != '') {
		document.location = 'default.asp?pageid=subhomepage&themaid=' + iThemaid + '&doelgroepid=' + doelgroepid;
	}
}


function CreateFlowPlayer(sDivName, sShowControlbar) {
	if (sShowControlbar) {
		$f(sDivName, { src: 'flowplayer.swf' }, {
			key: keys[location.host] || '',
			clip: {
				autoPlay: false,
				autoBuffer: true
			},
			play: {
				url: 'images/play.png',
				width: 83,
				height: 83
			}
		});
	}
	else {
		$f(sDivName, { src: 'flowplayer.swf' }, {
			key: keys[location.host] || '',
			clip: {
				autoPlay: false,
				autoBuffer: true
			},
			play: {
				url: 'images/play.png',
				width: 83,
				height: 83
			},
			plugins: {
				controls: null
			}
		});
	}
}

function PrintWindow(sIframe, sUrl) {
	$("#" + sIframe).get(0).src = sUrl;
}