/**
 * @author Eden design & communication : Johan Huijkman, Mathijs de Jong
 */
//	::::::::::::::::::::::::: start Add javascript specific stylesheet:

if (staticRootPath === undefined) { var staticRootPath = '..';  }

//	::::::::::::::::::::::::: start Add javascript specific stylesheet:
var head = $('<link rel="stylesheet" href="'+ staticRootPath +'/style/js-enabled.css" type="text/css" />').appendTo($('head')[0]);

//var plugin_template = $('<script type="text/javascript" src="../js/lib/jquery.template.js"></script>').appendTo($('head')[0]);
//	::::::::::::::::::::::::: end Add javascript specific stylesheet

	var map;
	var item=new Object;
	var centerLatitude = 20;
	var centerLongitude = -156; 
	var startZoom = 8;
	var xmlhttp;
	var markers;
	var cluster;
	var markersArray=[];
	var visibleMarkers=[];
	var mapItem=[];
	var catcount = [];


//	:::::::::::::::::::::::::::::: start onload function calls

$(document).ready(function() {	
	if ( $('body').hasClass('project') ) {		
		$('<link rel="stylesheet" href="'+ staticRootPath +'/style/project/js-enabled.css" type="text/css" />').appendTo($('head')[0]);
	} 
	
	if ($('.afbeeldingen').length > 0 ) {
		var head_Js = $('<script type="text/javascript" src="../js/lib/jquery.lightbox-0.5mod.pack.js"></script>').appendTo($('head')[0]);
		
		
		
		$('a.toon-overlay-foto').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.7,
			imageLoading: '../images/icons/laden-overlay.gif'
		});
	}
	
	jQuery.easing.def = 'easeOutBounce';
	ProvNHMainMenu.init();
	ProvNHSubNav.init();
	ProvNHSitemap.init();
	ProvNHTextSize.init();
	ProvNHSecondColComponents.init();
	ProvNHTabs.init();
	ProvNHRating.init();
	ProvNHToggleVisibility.init();
	ProvNHFoldingLists.init();
	ProvNHSearchResult.init();
	//ProvNHInputValue.init();
	ProvNHFormHelp.init();
	ProvNHQuoteBlockLink.init();
	
	autoSuggestClassNames = new Array('VeldZoekPlaats','NieuwsRegio','Zoekterm','Locatie'); // id or className of input element to have an autosuggest function
	ProvNHAutoSuggest.init(autoSuggestClassNames);
	
	//ProvNHMagazineItems.init();
	
	ProvNHOverlay.init();
	ProvNHOrderScreen.init();
	ProvNHRefineSearch.init();
	ProvNHResizeIFRAME.init();
	//ProvNHMaps.init();	

	ProvNHSetFlashVisited.init(Essentials.getCookie("FlashVisited"));		
});
//	:::::::::::::::::::::::::::::: end onload function calls

//	:::::::::::::::::::::::::::::: start onUnload function calls
$(document.body).unload(function() {
	
});
//	:::::::::::::::::::::::::::::: end onUnload function calls

//	:::::::::::::::::::::::::::::: Start 'Cookie' functionality
ProvNHSetFlashVisited = {
	init:function (status) {
		var currStatus = "";
		if(!status || status.length==0) { 
			Essentials.setCookie("FlashVisited", "visited");
		} else { currStatus = "visited"; }
				
		return currStatus;
	}	
}
//	:::::::::::::::::::::::::::::: End 'Cookie' functionality

//	:::::::::::::::::::::::::::::: Start 'MainMenu' functionality
ProvNHMainMenu = {
	subdiv:null,
	showTimer:null,
	hideTimer:null,
	showItem:null,
	showItemToo:null,
	mainNavHovered:false,
	//homeHovered:false,
	activeItem:null,
	currentHeight:0,
	init:function(){		
		subdiv = $('body').append('<div id="SubMenuContainer"></div>');
		if($('#SubMenuContainer #SubMenuContent').length == 0) $('#SubMenuContainer').append('<div id="SubMenuContent"></div>')
		if($('#SubMenuContainer #SubMenuBg').length == 0) $('#SubMenuContainer').append('<div id="SubMenuBg"></div>')
		if($('#SubMenuContainer #SubMenuShadow').length == 0) $('#SubMenuContainer').append('<div id="SubMenuShadow"></div>')
		
		if(jQuery.browser.msie && jQuery.browser.version < 7){
			$('#SubMenuContainer').append('<iframe id="SubMenuMaskIE"></iframe>');
		}		
				
		//document.getElementById("VeldZoekwoord").value = 'out';
		$('#Header .hoofdnavigatie ul').hover(function(){
			//	
		}, function(){
			ProvNHMainMenu.mainNavHovered = false;	
		})
		$('#Header .hoofdnavigatie-sub').each(function(){
			$(this).parent('li').hover(function(){			
				clearTimeout(ProvNHMainMenu.hideTimer);				
				showItem = $(this);
				showItemToo = this;
				if (ProvNHMainMenu.mainNavHovered) 
					ProvNHMainMenu.show();
				else {
					ProvNHMainMenu.showTimer = setTimeout(function(){
						ProvNHMainMenu.show()
					}, 250);
				}	
				ProvNHMainMenu.mainNavHovered = true;				
			}, function(){
				clearTimeout(ProvNHMainMenu.showTimer);
				ProvNHMainMenu.hideTimer = setTimeout(function(){ProvNHMainMenu.hide()},250);
			});
		});
		
		
		
		$('#SubMenuContainer').hover(function(){
			clearTimeout(ProvNHMainMenu.hideTimer);
		}, function(){
			ProvNHMainMenu.hideTimer = setTimeout(function(){ProvNHMainMenu.hide()},250);
		});
		$('#Header .hoofdnavigatie li:first').hover(function(){	
			if(ProvNHMainMenu.activeItem != null) ProvNHMainMenu.immediateHide();
			ProvNHMainMenu.activeItem = null;
			$(this).addClass('hover');
			ProvNHMainMenu.mainNavHovered = true;	
			
		}, function(){
			$(this).removeClass('hover');
		});
	},
	show:function(){
		$('#SubMenuContent').css({ left: "0px" });
		clearTimeout(ProvNHMainMenu.hideTimer);
		if(ProvNHMainMenu.activeItem != null) ProvNHMainMenu.activeItem.removeClass('hover');
		//document.getElementById("VeldZoekwoord").value = $(this).children('div.sub-kolom');
		showItem.addClass('hover');
		ProvNHMainMenu.activeItem = showItem;
		$('#SubMenuContainer #SubMenuContent').html(showItem.children('div.hoofdnavigatie-sub').html());
		
		if(jQuery.browser.msie && jQuery.browser.version < 7){
			$('#SubMenuMaskIE').css({ height:($('#SubMenuContainer #SubMenuContent').height()+40)+"px"});
		}	
				
		var leftPadd = showItemToo.offsetLeft-3;
		var rightPadd = leftPadd+180;
		var subWidth = $('#SubMenuContent .sub-kolom').length*184;
		//document.getElementById("VeldZoekwoord").value = $('#SubMenuContent .sub-kolom').length + " *3 = " + subWidth;
		if(leftPadd+subWidth<document.getElementById("SubMenuContainer").offsetWidth){
			$('#SubMenuContent').css({ marginLeft:leftPadd+"px"});
		}else if(rightPadd-subWidth>0){
			$('#SubMenuContent').css({ marginLeft:(rightPadd-subWidth+5)+"px"});
		}
		

		//$('#SubMenuContainer').css({ paddingLeft:leftPadd+"px", width:(965-leftPadd)+"px" });
		var x = Essentials.findElementPosition(document.getElementById('Header'))[0];
		var y = Essentials.findElementPosition(document.getElementById('Header'))[1];
		y += document.getElementById('Header').offsetHeight;
		
		var endHeight = document.getElementById('SubMenuContent').offsetHeight+"px";
		
		if (document.getElementById('SubMenuContainer').offsetLeft < 0) {
			$('#SubMenuBg').css({
				top: "-50px", height:"0px"
			});
			$('#SubMenuContent').css({
				top: "-50px"
			});
		}
		//if(document.getElementById('SubMenuContainer').offsetLeft<0) $('#SubMenuContainer').css({display:"none"});
		
		$('#SubMenuContainer').css({ left:x+"px", top:y+"px", overflow:"hidden" });
		
		$("#SubMenuContent").dequeue("fx");
		$('#SubMenuContent').animate(
			{
				top:"0px"
			},{ duration: 800, easing: 'easeOutExpo' }
		);
		$("#SubMenuBg").dequeue("fx");
		$('#SubMenuBg').animate(
			{
				top:"0px", height:endHeight
			},{ duration: 800, easing: 'easeOutExpo' }
		);
	},
	hide:function(){
		if(ProvNHMainMenu.activeItem != null) ProvNHMainMenu.activeItem.removeClass('hover');
		var endHeight = 0;
		if(document.getElementById('SubMenuContent')) endHeight = document.getElementById('SubMenuContent').offsetHeight;
		
		$("#SubMenuContent").dequeue("fx");
		$('#SubMenuContent').animate(
			{
				top:(-1*endHeight)+"px"
			},{ duration: 800, easing: 'easeOutExpo' }
		);
		$("#SubMenuBg").dequeue("fx");
		$('#SubMenuBg').animate(
			{
				height:"0px"
			},{ duration: 800, easing: 'easeOutExpo', complete:function(){$('#SubMenuContainer').css({ left:"-999em" }); } }
		)
	},
	immediateHide:function(){
		
		clearTimeout(ProvNHMainMenu.hideTimer);
		if(ProvNHMainMenu.activeItem != null) ProvNHMainMenu.activeItem.removeClass('hover');
		var endHeight = 0;
		if(document.getElementById('SubMenuContent')) endHeight = document.getElementById('SubMenuContent').offsetHeight;
		
		$("#SubMenuContent").dequeue("fx");
		$("#SubMenuBg").dequeue("fx");
		$('#SubMenuContent').css({ left:"-999em"});
		$('#SubMenuBg').animate(
			{
				height:"0px"
			},{ duration: 800, easing: 'easeOutExpo', complete:function(){ } }
		)
	}
}
//	:::::::::::::::::::::::::::::: End 'MainMenu' functionality

//	:::::::::::::::::::::::::::::: Start 'SecondColComponents' functionality
ProvNHSecondColComponents = {
	init:function(){
		$("h4.uitklapbaar").click(function(){					
			var h4 = this;
			if(!$(this).hasClass('open')){
				$(h4).next('div').slideDown({
					duration:800, 
					easing:'easeOutExpo', 
					complete:function(){ $(h4).addClass('open'); }
				}); 					
			}
			else {
				$(h4).next('div').slideUp({
					duration: 800,
					easing: 'easeOutExpo',
					complete: function(){ $(h4).removeClass('open'); }
				}); 
			}
			return false;
		});
	}			
}
//	:::::::::::::::::::::::::::::: End 'SecondColComponents' functionality

//	:::::::::::::::::::::::::::::: Start 'Subnav' functionality

ProvNHSubNav = {
	init:function(){
		$('.subnavigatie li').each(function(){
			if($(this).children('ul').length > 0){
				$(this).prepend('<span class="ico-toggle"></span>');
			}else if($(this).parent('ul').parent('li').length==0){
				$(this).prepend('<span class="no-toggle"></span>');
			}
			if($(this).parent('ul').parent('li').length==0 && $(this).children('ul').length > 0){
				$(this).children('span.ico-toggle').click(function(){
					if ($(this).parent('li').hasClass('open')) {						
						$(this).parent('li').children('ul').slideUp({
							duration: 600,
							easing: 'easeOutExpo',
							complete: function(){ $(this).parent('li').removeClass('open'); }
						});
					}
					else {
						$(this).parent('li').children('ul').slideDown({
							duration: 600,
							easing: 'easeOutExpo',
							complete: function(){ $(this).parent('li').addClass('open'); }
						});
					}
				})
			}
		})		
	}
}

//	:::::::::::::::::::::::::::::: End 'Subnav' functionality

//	:::::::::::::::::::::::::::::: Start 'Sitemap' functionality

ProvNHSitemap = {
	state: null,
	init:function(){
		
		initState = ProvNHSitemap.getSavedState();
		if (!initState || initState.length == 0) {
			ProvNHSitemap.state = 'open';
		} else {
			ProvNHSitemap.state = initState;
		}
		
		
		$('#Voet a.verberg-sitemap').each(function(){
			$(this).addClass(ProvNHSitemap.state);
			// set Preferred State
			if (ProvNHSitemap.state=='open') {
				$(this).html($(this).html()+" inklappen");
				$('#Voet .sitemap').show();
				$('#Voet').removeClass('in').addClass('uit');
				
			} else {
				$(this).html($(this).html()+" uitklappen");
				$('#Voet .sitemap').hide();
				$('#Voet').removeClass('uit').addClass('in');
			}
			// handle Click event on Switch Sitemap link
			$(this).click(function(){
				if ($(this).hasClass('open')) {
					$(this).removeClass('open').addClass('gesloten');
					$(this).html('Sitemap uitklappen');
					//$('#Voet .sitemap').slideUp("fast");
					$('#Voet .sitemap').hide();
					$('#Voet').removeClass('uit').addClass('in');
					ProvNHSitemap.state='gesloten';
					ProvNHSitemap.saveState(ProvNHSitemap.state);
				}
				else {
					$(this).removeClass('gesloten').addClass('open');
					$(this).html('Sitemap inklappen');
					//$('#Voet .sitemap').slideDown("fast");
					$('#Voet .sitemap').show();
					$('#Voet').removeClass('in').addClass('uit');
					ProvNHSitemap.state='open';
					ProvNHSitemap.saveState(ProvNHSitemap.state);
				}
				return false;
			})
		})
		
	},
	getSavedState: function() {
		var viewState = Essentials.getCookie("PNHSitemapView");
		return viewState;
	},
	saveState: function(state) {
		Essentials.setCookie("PNHSitemapView", state);
	}
}

//	:::::::::::::::::::::::::::::: End 'Sitemap' functionality

//	:::::::::::::::::::::::::::::: Start 'Tab' functionality
ProvNHTabs = {	
	init:function(){
		// home pages && page 17_DigLoket_Landing.html
		$("ul.tab-navigatie span").click(function(){			
			var listItems = $(this).parent().parent().find("li");								//get list items
			var tab1Link = $(this).parent().parent().find("span.tab1-link");					//get spans
			var tab2Link = $(this).parent().parent().find("span.tab2-link");
			var tab3Link = $(this).parent().parent().find("span.tab3-link");
						
			if($(this).parent().parent().parent().hasClass("blauw-blok")) {							//special tabs blauw blok
				var contentBlokken = $(this).parent().parent().parent().find(".content-blok");		//get all content blocks
				contentBlokken.css("display", "none");		
				listItems.removeClass("actief");
			
				if(this.className.indexOf("tab1-link") != -1) { $(contentBlokken[0]).css("display", "block"); }
				else if(this.className.indexOf("tab2-link") != -1) { $(contentBlokken[1]).css("display", "block"); }
				else if(this.className.indexOf("tab3-link") != -1) { $(contentBlokken[2]).css("display", "block"); }	
				else if(this.className.indexOf("tab4-link") != -1) { $(contentBlokken[3]).css("display", "block"); }
				
				$(this).parent().attr("class", $(this).parent().attr("class") + " actief"); 			
			}
			else if($(this).parent().parent().parent().hasClass("inleiding")) {							//special tabs in page 17_DigLoket_Landing.html
				if(this.className.indexOf("tab1-link") != -1) {
					$("#contentTab1").show();
					$("#contentTab2").hide();
					$(listItems[0]).append(tab1Link);				//move spans
					$(listItems[1]).append(tab2Link);
				}
				else if(this.className.indexOf("tab2-link") != -1) {
					$("#contentTab2").show();
					$("#contentTab1").hide();
					
					$(listItems[0]).append(tab2Link);				//move spans
					$(listItems[1]).append(tab1Link);
				}
			}
			else {																					//general tabs
				var contentBlokken = $(this).parent().parent().parent().find(".content-blok");		//get all content blocks
				contentBlokken.css("display", "none");												//hide all content blocks
				
				if(this.className.indexOf("tab1-link") != -1) {
					$(contentBlokken[0]).css("display", "block");	//show content-blok
					
					$(listItems[0]).append(tab1Link);				//move spans
					$(listItems[1]).append(tab2Link);
					if(tab3Link.length==1) { $(listItems[1]).append(tab3Link); }
				}
				else if(this.className.indexOf("tab2-link") != -1) {
					$(contentBlokken[1]).css("display", "block"); 	//show content-blok
					
					$(listItems[0]).append(tab2Link);				//move spans
					if(tab3Link.length==1) { $(listItems[0]).append(tab3Link); }
					$(listItems[1]).append(tab1Link);
				}
				else if(this.className.indexOf("tab3-link") != -1) {
					$(contentBlokken[2]).css("display", "block");	//show content-blok
				}
			}
		});
		
	}
}

//	:::::::::::::::::::::::::::::: End 'Tab' functionality

//	:::::::::::::::::::::::::::::: Start 'Rating' functionality
ProvNHRating = {
	init:function(){
		$('select.select-waardering').each(function(){
			//define index for this div to gain direct access to elements within:
			var n = $('select.select-waardering').index(this);
			$(this).parent().append('<div class="div-waardering"></div>')
			var aIndex = 1;
			$('select.select-waardering:eq('+n+') option').each(function(){
				if($('select.select-waardering:eq('+n+') option').index(this)==0) return;
				$('div.div-waardering:eq('+n+')').append('<a href="#" class="waardering'+aIndex+'">*</a>');
				aIndex++;
			});	
			$('div.div-waardering:eq('+n+') a').click(function(){
				if($(this).hasClass('geselecteerd')||$(this).parent('div.div-waardering').hasClass('disabled')){
					return false;
				} else{
					$(this).addClass('geselecteerd');
					$(this).siblings('a').each(function(){
						$(this).addClass('disabled');
					});
					var i = $(this).parent('div.div-waardering').children('a').index(this);
					$('select.select-waardering:eq('+n+') option:eq('+(i+1)+')').attr({
						selected: "selected"
					});
					$(this).parent('div.div-waardering').addClass('disabled');
					
					$('.pagina-beoordeling:eq('+n+') div.gesloten').each(function(){
						//alert($(this));
						$(this).removeClass('gesloten').addClass('open');
					})
					
					return false;
				}				
			})
			$('div.div-waardering:eq('+n+') a').hover(function(){
				if($(this).hasClass('geselecteerd')||$(this).parent('div.div-waardering').hasClass('disabled')) return;
				else $(this).addClass('hover');				
			}, function(){
				$(this).removeClass('hover');
			})
		})
	}
}
//	:::::::::::::::::::::::::::::: End 'Rating' functionality

//	:::::::::::::::::::::::::::::: Start 'Toggle visibillity' functionality
ProvNHToggleVisibility = {
	init:function(){
		$('a.toggle').click(function(){
				var hyperlink  = this;
				var panelId = hyperlink.href.substr((hyperlink.href.indexOf("panel=")+6), (hyperlink.href.length - (hyperlink.href.indexOf("panel=")+6)));
				$("#" + panelId).slideDown({
						duration: 1200,
						easing: 'easeOutExpo'
						});
		
				return false; 
			});
			
		$('form.poll input.btn-versturen').click(function(){
				$(this).parent().parent().parent().hide();
				$("div.poll-resultaat").show();		
				return false; 
			});
	}	
}
//	:::::::::::::::::::::::::::::: End 'Toggle visibillity' functionality

//	:::::::::::::::::::::::::::::: Start 'Folding lists' functionality
ProvNHFoldingLists = {
	classMore:'uitklappen',
	classLess:'inklappen',
	stringMore: 'Alle ',
	stringLess: 'Minder ',
	showInit:4,
	init:function(){
		if ($('.kader-blok').length > 0) {
			ProvNHFoldingLists.showInit = 3;
			ProvNHFoldingLists.stringMore = 'Meer '
		}
		
		$('ul.uitklap-lijst').each(function(){
			var thisTitle = this.title;
			if($(this).children('li').length>4){
				$(this).children('li').each(function(){
					if($(this).parent('ul.uitklap-lijst').children('li').index(this)>(ProvNHFoldingLists.showInit-1)) $(this).hide();
				})
				$(this).append('<li><a href#" class="uitklap-link '+ProvNHFoldingLists.classMore+'">'+(ProvNHFoldingLists.stringMore+thisTitle)+'</a></li>');
			}
			$(this).children('li').children('a.uitklap-link').attr('parentTitle',thisTitle);
			$(this).children('li').children('a.uitklap-link').click(function(){
				if($(this).hasClass(ProvNHFoldingLists.classMore)){
					var allLi = Essentials.findParent($(this),'uitklap-lijst').children('li');
					allLi.each(function(){
						if(allLi.index(this)>(ProvNHFoldingLists.showInit-1)) $(this).slideDown({
						duration: 600,
						easing: 'easeOutExpo',
						complete: function(){}
						});
					})				
					$(this).removeClass(ProvNHFoldingLists.classMore).addClass(ProvNHFoldingLists.classLess);
					$(this).html(ProvNHFoldingLists.stringLess+$(this).attr('parentTitle'));
				}else {
					var allLi = Essentials.findParent($(this),'uitklap-lijst').children('li');
					allLi.each(function(){
						if(allLi.index(this)>(ProvNHFoldingLists.showInit-1) && !(allLi.index(this)==allLi.length-1)) $(this).slideUp({
						duration: 600,
						easing: 'easeOutExpo',
						complete: function(){}
						});
					})				
					$(this).removeClass(ProvNHFoldingLists.classLess).addClass(ProvNHFoldingLists.classMore);
					$(this).html(ProvNHFoldingLists.stringMore+$(this).attr('parentTitle'));
				}				
				return false;
			})
		})
	}
}
//	:::::::::::::::::::::::::::::: End 'Folding lists' functionality

//	:::::::::::::::::::::::::::::: Start 'Toggle Searchresult' functionality
ProvNHSearchResult = {
	showString:'Toon',
	hideString:'Verberg',
	init:function(){
		if($('div.filter').length == 0) { return; }
		
		$('div.filter').prepend('<a class="verberg-toelichtingen" href="#">Verberg toelichtingen</a>');
	
		$('div.filter a.verberg-toelichtingen').click(function(){
			if($(this).hasClass('verberg-toelichtingen')){
				var i = $('div.filter a.verberg-toelichtingen').index(this);
				var newString = $(this).html().toString();
				newString = newString.replace(ProvNHSearchResult.hideString, ProvNHSearchResult.showString);
				$(this).html(newString);
				$(this).removeClass('verberg-toelichtingen').addClass('toon-toelichtingen').html();
				//alert($('div.standaard-lijst:eq('+i+') li p').length)
				$('ul.filter-lijst li p').each(function(){ 
					$(this).slideUp({
						duration: 500,
						easing: 'easeOutCirc',
						complete: function(){}
					});
				});
			}else{
				var i = $('div.filter a.toon-toelichtingen').index(this);
				var newString = $(this).html().toString();
				newString = newString.replace(ProvNHSearchResult.showString, ProvNHSearchResult.hideString);
				$(this).html(newString);
				$(this).removeClass('toon-toelichtingen').addClass('verberg-toelichtingen').html();				
				$('ul.filter-lijst li p').each(function(){ 
					$(this).slideDown({
						duration: 500,
						easing: 'easeOutCirc',
						complete: function(){}
					});
				});
			}
			return false;
		})
	}
}
//	:::::::::::::::::::::::::::::: End 'Toggle Searchresult' functionality

//	:::::::::::::::::::::::::::::: Start 'Clear/show initial input value' functionality
ProvNHInputValue = {
	init:function(){	
		$('input:text').each(function(){
			var initValue = $(this).val();
			if(initValue == '' || $(this).attr('id')=='veld-van' || $(this).attr('id')=='veld-tot' ) return;
			$(this).focus(function(){
				if($(this).val() == initValue) $(this).val('');
			})
			$(this).blur(function(){
				if($(this).val() == '') $(this).val(initValue);
			})
		})
		
	}	
}
//	:::::::::::::::::::::::::::::: End 'Clear/show initial input value' functionality

//	:::::::::::::::::::::::::::::: Start ProvNHFormHelp
ProvNHFormHelp = {
	init:function(){	
		$('span.help').click(function(){
			$(this).parent().find("p.toelichting").slideToggle({
					duration: 500,
					easing: 'easeOutQuad'});
		})
		
	}	
}
//	:::::::::::::::::::::::::::::: End ProvNHFormHelp

//	:::::::::::::::::::::::::::::: Start 'Magazine items' functionality
ProvNHMagazineItems = {	
	init:function(){                          
		$('div.magazine').each(function(){
			var itemsLength = $(this).children('div.magazine-item').length;
			$(this).children('div.magazine-item').each(function(){
				$(this).children('div.info-blok').prepend('<ol></ol>');
				$(this).children('div.info-blok').append('<a href="#" class="link-vorige" title="Naar vorig item">Vorige</a><a href="#" class="link-volgende" title="Naar volgend item">Volgende</a>');
					
				var current = $('div.magazine div.magazine-item').index(this);
				for(var i=0; i<itemsLength; i++){
					var classActive = (i==current) ? ' class="actief"' : '';
					$(this).children('div').children('ol').append('<li><a href="#"'+classActive+' index="'+i+'"></a></li>')
				}
				$(this).children('div.info-blok').children('a').each(function(){
					$(this).attr('index',current);
					$(this).attr('complete',itemsLength-1);
				})
			})
			
		});
		$('div.magazine-item ol li a').click(function(){
			var nr = Number($(this).attr('index'));
			var myParent = Essentials.findParent($(this),'magazine');
			ProvNHMagazineItems.show(nr);
			return false;
		});
		$('div.magazine-item a.link-vorige').click(function(){
			var prev = Number($(this).attr('index'))-1;
			if(prev<0) prev = 7;
			ProvNHMagazineItems.show(prev);
			return false;
		});
		$('div.magazine-item a.link-volgende').click(function(){
			var prev = Number($(this).attr('index'))+1;
			if(prev>Number($(this).attr('complete'))) prev = 0;
			ProvNHMagazineItems.show(prev);
			return false;
		});
	},
	show:function(n){
		$('div.magazine-item').each(function(){
			if ($(this).hasClass('open')) {
				//$(this).hide();
				$(this).removeClass('open').addClass('gesloten');
			}
			if($('div.magazine-item').index(this)==n){
				/*$(this).fadeIn({
					duration: 2000,
					easing: 'easeOutExpo',
					complete: function(){$('div.magazine-item:eq('+n+')').removeClass('gesloten').addClass('open')}
				});*/
				$(this).removeClass('gesloten').addClass('open');				
			}
		})
	}
}
//	:::::::::::::::::::::::::::::: End 'Magazine items' functionality

//	:::::::::::::::::::::::::::::: Start modal screen functionality
ProvNHModalScreen = {
	init:function(){
		if($('#Overlay').length>0) return;
		
		//create modal screen
		if($('#ModalScreen').length == 0){
			$('body').append('<div id="ModalScreen"></div>');
			$('#ModalScreen').click(function(){
				ProvNHOverlay.hide();
			});
		} 
		//create iframe mask
		if($('#ModalMask').length == 0) $('body').append('<iframe id="ModalMask" src="'+ staticRootPath +'/images/backgrounds/fake-src.gif"></iframe>');
		
	},
	sizing:function(){
				
		var h = $(window).height()>=$('#PaginaContainer').height() ? $(window).height() : $('#PaginaContainer').height()+30;
				
		if($('#OverlayFrame').length>0){
			h = h >=($('#OverlayFrame').height()+60) ? h : ($('#OverlayFrame').height()+60);
		}
		
		$('#ModalScreen').height(h);
		$('#ModalMask').height(h);
		
		var w = $(window).width()>=$('#PaginaContainer').width() ? $(window).width() : $('#PaginaContainer').width()+40;
		$('#ModalScreen').width(w);
		$('#ModalMask').width(w);
	},
	show:function(){
		ProvNHModalScreen.init();
		ProvNHModalScreen.sizing();
		$('#ModalScreen').show();
		$('#ModalMask').show();
		$(window).bind("resize", function(){
			ProvNHModalScreen.sizing();
		});
	},
	hide:function(){				
		$('#ModalScreen').hide();
		$('#ModalMask').hide();
		$(window).unbind("resize", function(){
			ProvNHModalScreen.sizing();
		});
	}	
}
//	:::::::::::::::::::::::::::::: End modal screen functionality

//	:::::::::::::::::::::::::::::: Start Show Overlay
ProvNHOverlay = {
	iframeWidth: null,
	init:function(){	
		if ($('#Overlay').length > 0) {
			$('#Overlay a.link-terug').hide();
			$('#Overlay div.top').append('<a href="[link]" class="venster-sluiten">sluit venster</a>')
			$('a.venster-sluiten').click(function(){
				ProvNHOverlay.hideFromOverlay();
				return false;
			});
			ProvNHOverlay.position();
			return;
		}	
		$('a.toon-overlay').click(function(){
						
			if ($(this).hasClass('extern')) {
				$('#OverlayFrame').attr('scrolling','yes');
				ProvNHOverlay.iframeWidth= 800;
				ProvNHOverlay.position();
				
			}
					
			ProvNHModalScreen.show();
			var goURL = this.href;	
			ProvNHOverlay.show(goURL);
			
			return false;
		})
		
	},
	show:function(u){	
		document.location = "#top";			
		if($('#OverlayPositioning').length == 0){		
			if ($('a.toon-overlay').hasClass('extern')) {
				$('body').append('<div id="OverlayPositioning"><div id="IframePos"><div id="IframeClose"><a onclick="ProvNHOverlay.hide();" href="#"><img src="'+ staticRootPath +'/images/buttons/closelabel.gif" /></a></div><iframe id="OverlayFrame" src="'+u+'" scrolling="no" frameborder="0"></iframe></div></div>');
			} else {
				$('body').append('<div id="OverlayPositioning"><div id="IframePos"><iframe id="OverlayFrame" src="'+u+'" scrolling="no" frameborder="0"></iframe></div></div>');
			}
		} else {
			$('#OverlayFrame').attr('src',u);
		}
	},
	hide:function(){
		$('#OverlayPositioning').remove();
		ProvNHModalScreen.hide();
		//$('#OverlayFrame').attr('src','');
	},
	hideFromOverlay:function(){
		self.parent.ProvNHOverlay.hide();
	},
	position:function(){
		
		setTimeout(function() {
			
			if ($('#Overlay').length > 0) {
				var h = $('#Overlay').height();
				var w = $('#Overlay').width();
				self.parent.ProvNHOverlay.resizeFrame(h,w);	
			} else {
				if(jQuery.browser.msie)
				{
					// Workaround to solve dissapearing scrollbar issue in IE)
					var u = $('#OverlayFrame').attr('src');
					$('#OverlayFrame').remove();
					$('#IframePos').append('<iframe id="OverlayFrame" src="'+u+'" scrolling="yes" frameborder="0"></iframe>');
				}
				$('#OverlayFrame').addClass('extern');
				$('#OverlayFrame').attr('scrolling','yes');		
				var h = $(window).height() - 120;
				var w = ProvNHOverlay.iframeWidth;
				ProvNHOverlay.resizeFrame(h,w);	
			}
			
		}, 5)		
	},
	resizeFrame:function(h,w){
		$('#OverlayFrame').attr('height',h);
		$('#OverlayFrame').css({height:h+"px"});	
		$('#OverlayFrame').attr('width',w);
		$('#OverlayFrame').css({width:w+"px"});
		$('#IframePos').css({width:w+"px"});	
		ProvNHModalScreen.sizing();	
	}
}
//	:::::::::::::::::::::::::::::: End Show Overlay

//	:::::::::::::::::::::::::::::: Start 'Refine Search' functionality
ProvNHRefineSearch = {	
	init:function(){                          
		if ($('.resultaat-verfijnen').length > 0) {
			if(jQuery.browser.msie && jQuery.browser.version < 7) $('body').append('<div id="WidgetVerfijning"><div class="inner"><a href="#" class="link-verwijderen">Verwijderen</a></div></div>');
			else $('body').append('<div id="WidgetVerfijning"><div class="wrap1"><div class="wrap2"><div class="wrap3"><div class="inner"><a href="#" class="link-verwijderen">Verwijderen</a></div></div></div></div></div>');
		}
		$('.resultaat-verfijnen a.verfijning').each(function(){
			var n = $('.resultaat-verfijnen a.verfijning').index(this);
			if(n != $('.resultaat-verfijnen a.verfijning').length-1) $(this).html($(this).html()+', ');
			$(this).click(function(){
				var x = Essentials.findElementPosition(this)[0]-5;
				var y = Essentials.findElementPosition(this)[1]-5;
				if(jQuery.browser.msie && jQuery.browser.version < 7){
					x -= 1;
					y -= 1;
				}
				$('#WidgetVerfijning span.verfijn-term').remove();
				var inHTML = $(this).html().indexOf(',')>-1 ? $(this).html().substr(0,$(this).html().length-2) : $(this).html();
				$('#WidgetVerfijning div.inner').prepend('<span class="verfijn-term">'+inHTML+'</span>')
				$('#WidgetVerfijning a.link-verwijderen').attr('href',$(this).attr('href'));
				$('#WidgetVerfijning').css({top:y+'px', left:x+'px', display:'block'});
				return false;
			})
		})
		$('#WidgetVerfijning a.link-verwijderen').click(function(){
			$('#WidgetVerfijning').hide();
			return false;
		})
		$(document).click(function(){
			$('#WidgetVerfijning').hide();
		})
	}
}
//	:::::::::::::::::::::::::::::: End 'Refine Search' functionality

//	:::::::::::::::::::::::::::::: Start Text resizing functionality
ProvNHTextSize = {
	
	init: function() {
		$('.metanavigatie a.tekst-groter').click(function() {
			var currentSize = ProvNHTextSize.getTextSize();
			currentSize = Number(currentSize);
			if (currentSize < 5) {
				var newTextSize = 0;
				newTextSize=currentSize+1;
				ProvNHTextSize.setTextSize(newTextSize);
			}
			return false;
		});
		$('.metanavigatie a.tekst-kleiner').click(function() {
			var currentSize = ProvNHTextSize.getTextSize();
			currentSize = Number(currentSize);
			if (currentSize > 1) {
				var newTextSize=currentSize - 1;
				ProvNHTextSize.setTextSize(newTextSize);
			}
			return false;
		});
		
		$('<link rel="alternate stylesheet" type="text/css" href="'+ staticRootPath +'/style/fontsize-1.css" title="1" />').appendTo($('head')[0]);
		$('<link rel="alternate stylesheet" type="text/css" href="'+ staticRootPath +'/style/fontsize-2.css" title="2" />').appendTo($('head')[0]);
		$('<link rel="alternate stylesheet" type="text/css" href="'+ staticRootPath +'/style/fontsize-3.css" title="3" />').appendTo($('head')[0]);
		$('<link rel="alternate stylesheet" type="text/css" href="'+ staticRootPath +'/style/fontsize-4.css" title="4" />').appendTo($('head')[0]);
		$('<link rel="alternate stylesheet" type="text/css" href="'+ staticRootPath +'/style/fontsize-5.css" title="5" />').appendTo($('head')[0]);
		
		var cookie = ProvNHTextSize.handleCookie.get("PNHTextSize");
		var title = cookie ? cookie : ProvNHTextSize.getSavedTextSize();
		if (title!=null) {
			ProvNHTextSize.setTextSize(title);
		} else {
			ProvNHTextSize.setTextSize('3');
		}

		
	},
	setTextSize: function(title) {
		$('link[@rel*=style][@title]').each(function(i) 
		{
			this.disabled = true;
			if ($(this).attr('title') == title) this.disabled = false;
		});
  		ProvNHTextSize.handleCookie.set("PNHTextSize", title, 365);
	},
	getTextSize:function() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
		return null;
	},
	getSavedTextSize: function() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") ) return a.getAttribute("title");
		}
		return null;
	},
	handleCookie: {
		set: function(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=/";	
		},
		get: function(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);
			}			
		}
	}
}
//	:::::::::::::::::::::::::::::: End Text resizing functionality

//	:::::::::::::::::::::::::::::: Start Autosuggest functionality
ProvNHAutoSuggest = {
	id: null,
	isActive: false,
	requestedChar: null,
	touchItem: -1,
	init: function(pointers) {
		if (pointers.length > 0) {
			for (var i=0; i < pointers.length; i++) {
				
				$('input').each(function() {
					if ($(this).hasClass(pointers[i]) || $(this).attr('id')==pointers[i]) {					
						ProvNHAutoSuggest.id = $(this).attr('id');
						$(this).keyup(function(event) {
							var pressedKey = event.keyCode;
							switch (pressedKey) {
								case 38: 
									// key Up
									ProvNHAutoSuggest.touch('up');
									break;
								case 40:
									// key Down
									ProvNHAutoSuggest.touch('down');
									break;
								case 13:
									// enter key
									//alert('enter');
									return false;
									break;
								case 27:
									// escape key
									ProvNHAutoSuggest.hide();
									return false;
									break;
								default: 
									// other keys
									ProvNHAutoSuggest.requestedChar = pressedKey;
									ProvNHAutoSuggest.collectChars();
									break;
							}
							
						});
						$(this).focus(function(){
							ProvNHAutoSuggest.id = $(this).attr('id');
							ProvNHAutoSuggest.collectChars();
						});
						$(this).blur(function(){
							if (!ProvNHAutoSuggest.isActive) {
								ProvNHAutoSuggest.hide();	
							}
						})
					}
				});
				
			}
		}
	},
	collectChars: function() {
		var inputChars = $('#'+ProvNHAutoSuggest.id).val().split('');
		if (inputChars.length > 1) {
			
			ProvNHAutoSuggest.show();
			
		} else {
			ProvNHAutoSuggest.isActive = false;
			ProvNHAutoSuggest.hide();	
		}
	},
	show: function(id) {
		if ($('#suggestedOptions').length < 1) {
			$('#'+ProvNHAutoSuggest.id).parent().css({position: 'relative'});
			var parentWidth = $('#'+ProvNHAutoSuggest.id).width();
			var parentHeight = $('#'+ProvNHAutoSuggest.id).height();
			var parentPosition = $('#'+ProvNHAutoSuggest.id).offset();
			var parentLeft = parentPosition.left;
			var parentTop = parentPosition.top+parentHeight+7;
			var hasBorder = $('#'+ProvNHAutoSuggest.id).hasClass('veld') ? true: false;
			var hasPadding = $('#'+ProvNHAutoSuggest.id).css('padding-left') != '' ? true: false;
			
			
			$('<div id="suggestedOptions"></div>').appendTo($('body'));	
			
			if (hasPadding) {
				newWidth= Number($('#'+ProvNHAutoSuggest.id).css('padding-left').replace('px','')) + Number($('#'+ProvNHAutoSuggest.id).css('padding-right').replace('px',''));
				parentWidth=parentWidth+newWidth;
			} 
			if (!hasBorder) {
				parentLeft = parentLeft-1;
			}
			
			
			$('#suggestedOptions').css({width: parentWidth, left: parentLeft, top: parentTop});
			
			ProvNHAutoSuggest.fill();
			$('#suggestedOptions').mouseover(function() {
				ProvNHAutoSuggest.isActive = true;
			}).mouseout(function(){
				ProvNHAutoSuggest.isActive = false;
			})
			
		} else {
			return false;
		}
		
	},	
	hide: function() {
		if ($('#suggestedOptions').length > 0) {
			$('#suggestedOptions').hide().remove();
			ProvNHAutoSuggest.touchItem = -1;
			$('#suggestedOptions').children().remove();
		}
	},
	fill: function() {
		// you should rewrite the charKey to ASCI plain character in a var (dummy requestedChar)
		if (requestedChar!=null) {
			var requestedChar = String.fromCharCode(ProvNHAutoSuggest.requestedChar);	
		}
		

		// start dummy function
		// fills div#suggestedOptions with dummy options
		// use AJAX call to create a listing (ul > li > strong/txt) of suggested options
		$('<ul>\
			<li><strong>Am</strong>ersfoort</li>\
			<li><strong>Am</strong>sterdam</li>\
			<li><strong>A</strong>lmere</li>\
			<li><strong>A</strong>nders</li>\
			<li><strong>A</strong>nna Paulowna</li>\
		</ul>').appendTo($('#suggestedOptions'));
		// end dummy function
		
		var c=1;
		$('#suggestedOptions ul li').each(function(c){
			$(this).addClass('item-'+c);
			c++
		});
		
		$('#suggestedOptions ul li').click(function(){
			var option = $(this).html().replace(/<\/?[^>]+>/gi, '');
			ProvNHAutoSuggest.select(option);
		});
		$('#suggestedOptions ul li').hover(function(){
			$(this).addClass('hover')
		},
		function(){
			$(this).removeClass('hover')
		});
	},
	touch: function(direction) {
		var nrSuggestedOptions = $('#suggestedOptions ul li').length;
		
		if (direction=='down' &&  ProvNHAutoSuggest.touchItem < nrSuggestedOptions-1) {
			ProvNHAutoSuggest.touchItem++;
		} else if (direction=='up' &&  ProvNHAutoSuggest.touchItem > 0) {
			ProvNHAutoSuggest.touchItem--;
		}
		
		$('#suggestedOptions ul li').each(function(){
			if ($(this).hasClass('item-'+ProvNHAutoSuggest.touchItem)) {
				$(this).addClass('touch');
				var selectedOption = $(this).html().replace(/<\/?[^>]+>/gi, '');
				$('#'+ProvNHAutoSuggest.id).val(selectedOption);
			} else {
				$(this).removeClass('touch');
			}
		});
	},
	select: function(selectedOption) {
		$('#'+ProvNHAutoSuggest.id).val(selectedOption);
		ProvNHAutoSuggest.hide();
		ProvNHAutoSuggest.isActive = false;
	}
	
}
//	:::::::::::::::::::::::::::::: End Autosuggest functionality

//	:::::::::::::::::::::::::::::: Start BestellingFuncties
ProvNHOrderScreen = {

	init: function() {
		if ($('#Overlay').hasClass('overlay-bestelling-afronden')) {
			
			$('div.alternatief-adres').addClass('gesloten');
			$('input.betaalmethode').attr('disabled','disabled');
			$('div.ideal').addClass('gesloten');
			$('div.creditcard').addClass('gesloten');
			
			
			var dId=0;
			var lId=0;
			$('div.extra-box').each(function() {
				$(this).addClass('gesloten');
				var boxId = 'box-'+dId;
				$(this).attr('id', boxId);
				dId++;
				
			});
			$('input#AfleveradresFormulier').click(function(){
				if ($(this).is(':checked')) {
					//$(this).attr('disabled','disabled')
					$('div.alternatief-adres').removeClass('gesloten').addClass('open');
					ProvNHOverlay.position();
				} else {
					$('div.alternatief-adres').removeClass('open').addClass('gesloten');
					ProvNHOverlay.position();
				}
			});
			
			$('input#VoorwaardenFormulier').click(function(){
				if ($(this).is(':checked')) {
					$('input.btn-versturen.betaalmethode').attr('disabled','');
				} else {
					$('input.btn-versturen.betaalmethode').attr('disabled','disabled');
				}
			});
			
			$('input#Creditcard').click(function(){
				if ($(this).is(':checked')) {
					//$(this).attr('disabled','disabled')
					$('div.creditcard').removeClass('gesloten').addClass('open');
					ProvNHOverlay.position();
				} else {
					$('div.creditcard').removeClass('open').addClass('gesloten');
					ProvNHOverlay.position();
				}
			});
			
			$('input#iDeal').click(function(){
				if ($(this).is(":checked")) {
					$('div.ideal').removeClass('gesloten').addClass('open')
					ProvNHOverlay.position();
				} 
			});
			$('input#iDeal').blur(function(){
				if ($('input#iDeal').is(":checked")) {
					$('div.ideal').removeClass('gesloten').addClass('open')
				} else {
					$('div.ideal').removeClass('open').addClass('gesloten')
				}
			})
			
			
			$('a.zoek-adres').each(function(){
				var linkId = 'link-'+lId;
				$(this).attr('id',linkId);
				lId++;
			});
			
			$('a.zoek-adres').click(function(){
				triggerId = $(this).attr('id').replace('link-','');
				$('#box-'+triggerId).removeClass('gesloten').addClass('open');
				ProvNHOrderScreen.searchAddress(triggerId);
				ProvNHOverlay.position();
				return false;
			});
			
		}
	},
	searchAddress: function(id) {
		// AJAX call to fill address fields
		alert('This function is ProvNHOrderScreen.searchAddress');
		
	}
}
//	:::::::::::::::::::::::::::::: End BestellingFuncties


ProvNHResizeIFRAME = {
	iframeElement: new Object,
	init: function() {
		if ($('.iframe-blok').length > 0  ) {
			
			ProvNHResizeIFRAME.iframeElement = document.getElementsByTagName('iframe')[0];			
			// if browser is safari or opera, use different height calculation method
			if ($.browser.safari || $.browser.opera) {
				
				$('iframe').load(function(){
				
					setTimeout(ProvNHResizeIFRAME.resize, 100);
					
					var iSource = ProvNHResizeIFRAME.iframeElement.src;
					ProvNHResizeIFRAME.iframeElement.src = '';
					ProvNHResizeIFRAME.iframeElement.src = iSource;
				
				});
			} 
			// other browsers use this method and trigger load by replacing src by src
			else {			
				$('iframe').load(function(){		
					this.style.height = this.contentWindow.document.body.offsetHeight + 30 + 'px';
					$('.iframe-blok').height($('iframe').height());
				});
				var iSource = ProvNHResizeIFRAME.iframeElement.src;
				ProvNHResizeIFRAME.iframeElement.src = '';
				ProvNHResizeIFRAME.iframeElement.src = iSource;
			
				
			}			
		}		
	},
	resize: function(){		
		ProvNHResizeIFRAME.iframeElement.style.height = ProvNHResizeIFRAME.iframeElement.contentWindow.document.body.offsetHeight + 'px';
	}
	
}

ProvNHQuoteBlockLink = {
	
	init: function() {
		
		if ($('#Content blockquote a').length > 0 )
			var linkTarget = $('#Content blockquote a').attr('href');
			$('#Content blockquote').addClass('klikbaar');
			$('#Content blockquote').hover(
				function(){
					$(this).addClass('hover');
				},
				function(){
					$(this).removeClass('hover');
				}
			);
			$('#Content blockquote').click(function(){
				window.location = linkTarget;
				return false;
			});
	}
	
}

Essentials = {
	findElementPosition : function (elem){
		var curleft = curtop = 0;
		if (elem.offsetParent) {
		
			curleft = elem.offsetLeft
			curtop = elem.offsetTop
			while (elem = elem.offsetParent) {
				curleft += elem.offsetLeft
				curtop += elem.offsetTop
			}
		}
		return [curleft,curtop];
	},
	findParent : function (elem, findClass){
		var parentFound = null;
		if(elem.parent()){
			while (!(elem.hasClass(findClass))) {
				elem = elem.parent();
				//alert(elem.attr('class'));
			}
			parentFound = elem;
		}
		return parentFound;
	},
	setCookie:function (name, value) {  
		var argv = Essentials.setCookie.arguments;  
		var argc = Essentials.setCookie.arguments.length;  
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;  
		var domain = (argc > 4) ? argv[4] : null;  
		var secure = (argc > 5) ? argv[5] : false;  
		document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
	},
	getCookie:function (name) {
		var start = document.cookie.indexOf(name+"="); 
		var len = start+name.length+1; 
		if ((!start) && (name != document.cookie.substring(0,name.length))) { return  null; }
		if (start == -1){ return null; }
		
		var end = document.cookie.indexOf(";",len); 
		
		if (end == -1) { end = document.cookie.length; } 
		return unescape(document.cookie.substring(len,end)); 
	}/*,
	findChild : function (elem, findClass){
		var childFound = null;
		if(elem.children()[0]){
			while (!(elem.hasClass(findClass))) {
				elem = elem.children()[0];
				alert(elem.attr('class'));
			}
			childFound = elem;
		}
		return childFound;
	}*/
}