$(document).ready(function() {

	$.history.go = function(params) {
		$.history.load(buildUrl(params));
	};
	
	$.cookie('hasJS', true);
	
	$('#wrapper a.zoom, a[rel="lightbox"]').lightbox();
	
	$('a[href^="#category_"]').click(function() {
		evt.preventDefault();
		$.history.load(this.href.replace(/https?:\/\/.*?(?=[\/#]{1,2})/, ''));
	});
	
	$('#informatie_aanvraag_form').validate();
	
	if (/\/informatie/.test(location.href)) {
		$('html,body').animate({scrollTop: $('.arrangement_info_aanvraag').offset().top});
	}
	
	initCycle();
	
	initOldMSIEhacks();
	
});

function buildUrl(params) {
	
	var url = '';
	if (params.category) {
		url += 'category_' + params.category;
		if (params.arrangement) {
			url += '_arrangement_' + params.arrangement;
			if (params.regio) {
				url += '_regio_' + params.regio;
				if (params.locatie) {
					url += '_locatie_' + params.locatie;
				}
			}
		}
	}
	return url;
}


function sendToAnalytics(url) {
	try {
		var pageTracker = _gat._getTracker('UA-1408571-1');
		pageTracker._trackPageview(url);
	} catch(err) {}
}

function Arrangementen(categoriesByParent) {

	// ook categoriseren op ID
	var categoriesById = {};
	for (var iParentId in categoriesByParent) {
		for (var iCatId in categoriesByParent[iParentId]) {
			categoriesById[iCatId] = categoriesByParent[iParentId][iCatId];
		}
	}
		
	// privates
	var submenu_collapsed_height 	= 3;
	var submenu_height 				= 30;
	var submenu_animation_time 		= 100;
	var tab_deactivate_time			= 50;
	var submenustate 				= 'closed';
	var header_has_mouse			= false;
	var submenu_container			= $('#events div.subcategories').get(0);
	var tabs						= $('#events div.categories ul li');
	var eventlist_container			= $('#events div.eventlist').get(0);
	var title_container				= $('#events div.eventlist div.titlebar').get(0);
	var loader						= $('#events div.eventlist div.loader').show();
	var event_details_container 	= $('#eventDetailsContainer').get(0);
	var tab_shadow_elements			= tabs.find('span b');
	var previous_class				= '';
	
	var obj = {
			
		Header: {
			
			/**
			 * Zet de standaard tab. Dit is de tab die actief is wanneer idle.
			 * 
			 * @param {Element} element
			 */
			setDefaultTab: function(element) {
				
				// catID
				if (typeof(element) == 'number') {
					// hij wordt nu verder afgehandeld als een string zijnde
					element = '#cat_'+element;
				}
				// op basis van selector
				if (typeof(element) == 'string') {
					element = $(element);
					if (element.length == 0) {
						return;
					}
					element = element.get(0);
				}
				this.defaultTab = element;
				
				// als de default tab wordt gezet en de header heeft de muis niet
				if (!header_has_mouse) {
					// dan mag die tab direct geactiveerd worden
					this.setActiveTab(this.defaultTab);
				}
			},
			
			/**
			 * Kijkt of de opgegeven tab de standaard tab is.
			 * 
			 * @param {Element} element
			 * @return {Boolean}
			 */
			isDefaultTab: function(element){
				return this.defaultTab && this.defaultTab == element;
			},
			
			/**
			 * Verkrijgt de tab die bij het opgegeven tabid behoort.
			 * 
			 * @param {Number} iCatId
			 * @return {Element}
			 */
			getTabFromCatId: function(iCatId) {

				return $('#cat_'+this.getRootCatId(iCatId)).get(0);
			},
			
			/**
			 * Verkrijgt de root catid.
			 * 
			 * @param {Number} iCatId
			 * @return {Number}
			 */
			getRootCatId: function(iCatId) {
				
				return (categoriesById[iCatId] && categoriesById[iCatId].item_parent && categoriesById[iCatId].item_parent != 0)
					? categoriesById[iCatId].item_parent
					: iCatId;
			},
			
			/**
			 * Verkrijgt de categorie ID op basis van de opgegeven tab.
			 * 
			 * @param {Element} element
			 * @return {Number}
			 */
			getCatIdFromTab: function(element) {
				
				if (!element.iCatId) {
					element.iCatId = element.id.split('_')[1];
				}
				
				return element.iCatId;
			},
			
			/**
			 * Zet de actieve tab.
			 * 
			 * @param {Element} element
			 */
			setActiveTab: function(element) {
				
				// lopende aanvraag tot activeren annuleren
				this.clearDelayedDeactivateCurrentTab();
				
				// als er al een tab gezet is
				if (this.currentTab) {
					
					// als de huidige geactiveerde tab de te activeren tab is hoeft er niets te gebeuren
					if (this.currentTab == element) {
						return;
					}
					
					// de huidige tab deactiveren
					this.deactivateCurrentTab();
				}
				
				var iCatId = this.getCatIdFromTab(element);
				
				$(element).addClass('hover');
				
				this.currentTab = element;
			},
			
			/**
			 * Deactiveert de huidig actieve tab.
			 */
			deactivateCurrentTab: function() {

				// als er geen geactiveerde tab is
				if (!this.currentTab) {
					return;
				}
				
				$(this.currentTab).removeClass('hover');
				
				this.currentTab = null;
			},
			
			/**
			 * Stelt een vertraagde aanroep van het deactiveren van de huidige tab in.
			 * Deze aanvraag wordt overschreven bij het opnieuw aanroepen van deze functie binnen de ingestelde tijd.
			 * Verder wordt hij geannuleerd als je met de muis over het submenu gaat.
			 * 
			 * @param {Element} de tab waar de aanvraag vandaan komt
			 */
			delayedDeactivateCurrentTab: function(tab) {

				// huidige aanvraag annuleren (indien aanwezig)
				this.clearDelayedDeactivateCurrentTab();
				
				this.deactivateCurrentTabTimeout = setTimeout(function() {
					// als er een standaard tab is
					if (obj.Header.defaultTab) {
						// als er geen tab op is gegeven of als de opgegeven tab niet de standaard tab is
						if (!tab || !obj.Header.isDefaultTab(tab)) {
							obj.Header.setActiveTab(obj.Header.defaultTab);
						}
					} else if (tab) {
						// als de opgegeven tab niet de huidige tab is, mag die gedeactiveerd worden
						if (obj.Header.currentTab != tab) {
							obj.Header.deactivateCurrentTab();
						}
					}
				}, tab_deactivate_time);
			},
			
			/**
			 * Annuleert de vertraagde aanroep van het deactiveren van de huidige tab.
			 */
			clearDelayedDeactivateCurrentTab: function() {
				
				if (this.deactivateCurrentTabTimeout) {
					clearTimeout(this.deactivateCurrentTabTimeout);
				}
			},
			
			/**
			 * Verbergt het huidige submenu.
			 */
			hideSubMenu: function(){
			
				if (submenustate == 'hiding' || submenustate == 'closed') {
					return;
				}
				
				$(submenu_container).stop(true).animate({
					height: submenu_collapsed_height + 'px'
				}, submenu_animation_time, function(){
					submenustate = 'closed';
				});
				
				submenustate = 'hiding';
			},
			
			/**
			 * Toont het opgegeven menu.
			 * 
			 * @param {String} subCat
			 */
			showSubMenu: function(subCat){
			
				$(submenu_container).queue(function(){
				
					$(this).animate({
							height: submenu_height + 'px'
						}, submenu_animation_time, function(){
							submenustate = 'opened';
						})
						.find('ul')
							.hide()
						.end()
						.find(subCat)
							.show()
						.end()
						.dequeue();
				});
				
				submenustate = 'opening';
			}
		},
		
		Events: {
			
			// hier worden de referenties naar de eerder opgehaalde lijsten / details in opgeslagen
			lists: {},
			details: {},
			
			/**
			 * Verkrijgt de arrangement ID op basis van het opgegeven element.
			 * 
			 * @param {Element} element
			 * @return {Number}
			 */
			getArrIdFromEl: function(element) {
				
				if (!element.iArrId) {
					element.iArrId = element.id.split('_')[1];
				}
				
				return element.iArrId;
			},
			
			/**
			 * Bouwt de lijst op op basis van de opgegeven categorie.
			 * 
			 * @param {Number} iCatId
			 * @param {Function} callback
			 * @return {Element}
			 */
			buildList: function(iCatId, callback) {

				var eventWrapper = document.createElement('DIV');
				
				$(eventlist_container).queue(function() {
					$(eventWrapper)
						.addClass('eventsWrapper')
						.load('/arrangementen/overzicht/'+iCatId+'/', null, function() {

							// standaard waarden (verborgen)
							$(eventWrapper)
								.find('img.bgimg')
									.css({
										opacity: 0
									})
								.end()
								.find('div.event')
									.css({
										marginTop: '-'+(eventlist_container.offsetHeight)+'px',
										marginLeft: '-'+(eventlist_container.offsetWidth)+'px'
									})
									// deze links zijn slechts bedoeld als fallback voor wanneer js uit is geschakeld + voor zoekrobots
									.find('a.event_detail')
										.click(function() {
											$(this).closest('div.event').click();
											return false;
										})
									.end()
									.mouseenter(function() {
										$(this).addClass('hover');
									})
									.mouseleave(function() {
										$(this).removeClass('hover');
									})
									.click(function() {
										$.history.load('category_'+obj.Events.currentList+'_arrangement_'+obj.Events.getArrIdFromEl(this));
										return false;
									})
								.end()
								.find('div.default_text, div.homeItems')
									.css({
										opacity: 0
									})
									.hide()
								.end();
								
							$(eventWrapper).find('img').preload({
								onFinish: function() {
									$(eventlist_container).dequeue();
									if (callback) callback();
								}
							});
						});
				});
				
				return eventWrapper;
			},
			
			/**
			 * Geeft de lijst weer op basis van de opogegeven categorie.
			 * 
			 * @param {Number} iCatId
			 * @param {Function} callback
			 */
			showList: function(iCatId, callback) {
				var currentCat = categoriesById[iCatId].item_naam.toLowerCase();
				var isHome = currentCat == 'home';
				var list = obj.Events.lists[iCatId];
				var listEvents;
				
				// als er al een lijst zichtbaar is, die eerst verbergen
				if (this.currentList) {
					obj.Events.hide();
				}
				
				obj.Events.currentList = iCatId;
				
				$(eventlist_container).queue(function() {
					
					listEvents = $(list).find('div.event');

					if (isHome) {
						if (this.wasHome == undefined || !this.wasHome) {
							$(eventlist_container).switchClass(previous_class, 'home', 1000);
							previous_class = 'home';
							this.wasHome = true;
						}
					} else {
						
						var rows = Math.ceil(listEvents.length / 4);
						if (rows < 3) {
							rows = 3;
						}
						
						var targetClass = 'rows-' + rows;
						if (this.wasHome == undefined || this.wasHome) {
							$(title_container).hide(1000);
							$(eventlist_container).switchClass(previous_class, targetClass, 1000);
							this.wasHome = false;
						} else {
							if (previous_class != targetClass) {
								$(eventlist_container).switchClass(previous_class, targetClass, 1000);
							}
						}
						previous_class = targetClass;
					}
					
					$(eventlist_container).queue(function() {
						
						obj.Loader.hide();
						
						$(list).find('img.bgimg').animate({opacity: 1}, 500);
						
						if (isHome) {
							//=- Show titlebar
							$(title_container).show(1000);
						}
						
						// een functie die uitgevoerd dient te worden nadat de animatie voltooid is
						var  f = function() {
							$(eventlist_container).dequeue();
							if (callback) callback();
						};
						
						// als de eventlijst leeg is
						if (listEvents.length == 0) {
							
							// kijken of er een standaard tekst aanwezig is
							var defaultText = $(list).find('div.default_text');
							if (!defaultText.length) {
								
								// kijken of er een lijst met de home items aanwezig is
								var homeItems = $(list).find('div.homeItems');
								
								if (!homeItems.length) {
									// niets te doen -> direct voltooid
									f();
								} else {
									
									// na 500 ms de home items infaden
									setTimeout(function() {
										homeItems
										.show()
										.animate({opacity: 1}, 500, function() {
											f();
										});
									}, 500);
									
								}
								
							} else {
								// na 500 ms de standaard tekst infaden
								setTimeout(function() {
									defaultText
									.show()
									.animate({opacity: 1}, 500, function() {
										f();
									});
								}, 500);
							}
						} else {
							listEvents.each(function(i) {
								$(this).animate({
									marginTop: '0',
									marginLeft: '0'
								}, 1500 + (i * 100), function() {
									if (i + 1 == listEvents.length) {
										f();
									}
								});
							});
						}
					});
					
					$(this).dequeue();
				});
			},
			
			/**
			 * Verbergt de huidige lijst.
			 * 
			 * @param {Function} callback
			 */
			hide: function(callback) {
				
				if (!this.currentList) {
					return;
				}
				
				var list = obj.Events.lists[this.currentList];
					
				$(eventlist_container).queue(function() {

					$(this).find('img.bgimg').animate({opacity: 0}, 500);
					
					var f = function() {
						$(eventlist_container).dequeue();
						if (callback) callback();
					};
					
					var listEvents = $(list).find('div.event');
					if (listEvents.length == 0) {

						var defaultText = $(list).find('div.default_text');
						if (!defaultText.length) {

							// kijken of er een lijst met de home items aanwezig is
							var homeItems = $(list).find('div.homeItems');
							
							if (!homeItems.length) {
								// niets te doen -> direct voltooid
								f();
							} else {

								homeItems.animate({opacity: 0}, 500, function() {
									$(this).hide();
									f();
								});
							}
						} else {
							defaultText.animate({opacity: 0}, 500, function() {
								$(this).hide();
								f();
							});
						}
					} else {
						listEvents.each(function(i) {
							$(this)
								.animate({
									marginTop: '-'+(eventlist_container.offsetHeight)+'px',
									marginLeft: '-'+(eventlist_container.offsetWidth)+'px'
								}, 1000 + (i * 100), function() {
									if (i == 0) {
										f();
									}
								});
						});
					}
				});
			},
			
			buildDetails: function(iArrId, callback) {
				
				var detailsWrapper = document.createElement('DIV');

				$(eventlist_container).queue(function() {
					$(detailsWrapper)
						.load('/arrangementen/detail/'+iArrId+'/', null, function() {
							
							detailsWrapper.infoaanvraagWrapper = $(detailsWrapper).find('div.infoaanvraag');
							
							$(detailsWrapper)
								.find('.picturelist')
						    		.css({'overflow': 'visible'})
						    		.cycle({
										fx: 'fade',
										//speed:  'fast',
										timeout: 4500,
										pager:  $(detailsWrapper).find('.nav'),
										slideExpr: 'img'
								    })
							    .end()
								.find('a[href*="#category_"]')
									.click(function(evt) {
										evt.preventDefault();
										$.history.load(this.href.replace(/https?:\/\/.*(?=[\/#]{1,2})/, ''));
									})
								.end()
								.find('a.informatie_aanvragen_trigger')
									.click(function() {
										obj.Events.showInformatieAanvraag(iArrId, $(this).attr('data'));
										return false;
									})
								.end()
								.find('.locatie_afbeelding a')
									.click(function() {
										accordeonActivate($(this).closest('.locatie'));
										return false;
									})
								.end()
								.find('.combi a')
									.click(function(evt) {
										evt.preventDefault();
										$.history.load(this.href.replace(/^.*#/, ''));
									})
								.end()
								.css({marginTop: (detailsWrapper.offsetHeight * -1)+'px'})
								.hide()
								.find('img')
									.preload({
										onFinish: function() {
											
											$(detailsWrapper)
												.find('a.zoom').lightbox();
											if (callback) callback();
										}
									}) 
								.end()
								.find('form.informatie_aanvraag_form')
									.validate({
										submitHandler: function(form) {

											$(form).prepend($('<p />').text('Een ogenblik geduld...').slideUp(500));
											
											$(form).ajaxSubmit({
												url: '/reactieform/verzenden/',
												success: function(responseText) {
													$(form).slideUp(500).queue(function(){
														$(this).html(responseText);
														$(this).dequeue();
													}).slideDown(500);
												}
											});

											$(form)
												.find('input[type=submit]')
													.slideUp(500)
												.end()
												.find('input, select, textarea')
													.css('border', '1px solid #ffffff')
													.each(function() { this.disabled = true; });
										}
									});
							
							$(eventlist_container).dequeue();
						});
				});
				
				return detailsWrapper;
			},
			
			showDetails: function(iArrId, callback) {
				if (obj.currentArrangementId == iArrId) {
					if (callback) {
						try {
							callback();
						} catch (e) {
							console.log(e);
						}
					}
					return;
				}
				
				obj.Loader.show();
				
				// queue van huidige animaties / acties verwijderen
				$(event_details_container).stop(true);
				
				var detailsWrapper;
				
				// als hij nog niet geinitialiseerd is
				if (!obj.Events.details[iArrId]) {
		
					// details opbouwen
					detailsWrapper = obj.Events.buildDetails(iArrId);
					$(event_details_container).append(detailsWrapper);
					
					// voor latere referentie
					obj.Events.details[iArrId] = detailsWrapper;
					
				} else {
					detailsWrapper = obj.Events.details[iArrId];
				}

				// eerst verbergen
				if (obj.Events.currentDetails) {
					this.hideDetails();
				}
				$(eventlist_container).queue(function() {
					
					obj.currentArrangementId = iArrId;

					// Hack: content verwijderen
					if ($('#content_inner').height() > 10) {
						$('#content_inner').slideUp(400);
					}
					
					obj.Loader.hide();
					obj.Events.currentDetails = detailsWrapper;
					
					$(obj.Events.currentDetails)
						.show()
						.animate({marginTop: 0}, 500, function() {
							
							var detailsPosition = $(obj.Events.currentDetails).offset();
							detailsPosition.bottom = detailsPosition.top + $(obj.Events.currentDetails).height();
							
							if ($('body').attr('scrollTop') + $('body').height() < detailsPosition.bottom) {
								$('body').animate({scrollTop: detailsPosition.bottom - $('body').height()});
							}
						
							$(eventlist_container).dequeue();
							if (callback) {
								try {
									callback();
								} catch (e) {
									console.log(e);
								}
							}
						});
					
				});
			},
			
			showInformatieAanvraag: function(iArrId, callback) {
				
				var detailsWrapper = obj.Events.details[iArrId];
				
				if (!detailsWrapper || !detailsWrapper.infoaanvraagWrapper) {
					return false;
				}
				
				var aanvraagWrapper = detailsWrapper.infoaanvraagWrapper;

				$(eventlist_container).queue(function() {
					$(detailsWrapper).find('div.informatie_aanvragen_button').slideUp(500);
					$(aanvraagWrapper).slideDown(500, function() {
						
						var aanvraagPosition = $(aanvraagWrapper).offset();
						aanvraagPosition.bottom = aanvraagPosition.top + $(aanvraagWrapper).height();
						
						if ($('body').attr('scrollTop') + $('body').height() < aanvraagPosition.bottom) {
							$('body').animate({scrollTop: aanvraagPosition.bottom - $('body').height()});
						}
						
						$(eventlist_container).dequeue();
					});
				});
			},
			
			hideDetails: function(callback) {
				
				if (!obj.Events.currentDetails) {
					return;
				}

				$(eventlist_container).queue(function() {
					
					$(obj.Events.currentDetails).animate({marginTop: (obj.Events.currentDetails.offsetHeight * -1)+'px'}, 500, function() {
						$(this).hide();
						$(eventlist_container).dequeue();
						if (callback) callback();
					});
				});
			}
		},
		
		Loader: {
			show: function() {
				loader
					.stop()
					.animate({opacity: 1}, 10);
			},
			
			hide: function() {
				loader
					.stop()
					.animate({opacity: 0}, 100);
			}
		}
	};
	
	// events koppelen aan header
	tabs
		.bind('mouseenter', function() {
			
			header_has_mouse = true;
			obj.Header.setActiveTab(this);
		})
		.bind('mouseleave', function() {
			
			header_has_mouse = false;
			obj.Header.delayedDeactivateCurrentTab(this);
		});
	
	// events koppelen aan submenu
	$(submenu_container)
		.bind('mouseenter', function() {
			
			header_has_mouse = true;
			
			obj.Header.clearDelayedDeactivateCurrentTab();
		})
		.bind('mouseleave', function() {
			
			header_has_mouse = false;
			
			obj.Header.delayedDeactivateCurrentTab();
		});
	
	// gezien niet alle browsers (IE inderdaad) max-wdith ondersteunen
	$(tabs).find('a').each(function() {
		if (this.offsetWidth > 130) {
			$(this).width(130);
		}
	});
	
	$.history.init(function(hash) {
		var iCatId;
		var iArrId;
		var selectedRegio;
		var locatie;
		
		var activeTab = tabs.find('.hover');
		
		var hashMatch = /(?:category_|arrangementen\/overzicht\/)(\d+)(?:.+arrangement_(\d+))?(?:.+regio_(no|nw|zw|zo)(?:_locatie_(\d+))?)?/.exec(hash) || [];
		
		// geen hash in combinatie met geen huidige lijst, dan moet de eerste tab geladen worden
		if ((!hashMatch || !hashMatch[1]) && !obj.Events.currentList) {
			iCatId = $.cookie('ccid') || obj.Header.getCatIdFromTab(tabs.get(0));
		} else {
			iCatId = hashMatch[1] || null;
		}

		if (hashMatch) { 
			if (hashMatch[2]) {
				iArrId = hashMatch[2];
				if (hashMatch[3]) {
					selectedRegio = hashMatch[3];
					if (hashMatch[4]) {
						locatie = hashMatch[4];
					}
				}
			}
		}
		
		if (!iCatId) {
			return;
		}

		// tab ophalen
		var tab = obj.Header.getTabFromCatId(iCatId);

		// instellen als default
		obj.Header.setDefaultTab(tab);

		if (obj.Events.currentList != iCatId) {

			obj.Loader.show();
			
			// queue van huidige animaties / acties verwijderen
			$(eventlist_container).stop(true);
			
			// als hij nog niet geinitialiseerd is
			if (!obj.Events.lists[iCatId]) {
	
				// lijst opbouwen
				var list = obj.Events.buildList(iCatId);
				$(eventlist_container).prepend(list);
				
				// voor latere referentie
				obj.Events.lists[iCatId] = list;
			}
			
			obj.Events.showList(iCatId);
			
			var iRootCatId = obj.Header.getRootCatId(iCatId);
			if ($('ul#subcat_'+iRootCatId).length > 0) {
				$(eventlist_container).queue(function() {
					obj.Header.showSubMenu('ul#subcat_'+iRootCatId);
				});
			} else {
				
				if (submenustate != 'closed') {
					obj.Header.hideSubMenu();
				}
			}
			
			// huidige lijst onthouden
			$.cookie('ccid', iCatId);
		}
		
		if (iArrId) {
			obj.Events.showDetails(iArrId, function() {
				if (selectedRegio) {
					var regioWrap = $(event_details_container).find('.regio');
					showRegio(selectedRegio, regioWrap);
					
					if (locatie) {
						var selectedRegioInfoWrap = regioWrap.find('.locatie_' + locatie);
						accordeonActivate(selectedRegioInfoWrap);
					} else {
						if (previousActivated) {
							accordeonActivate(previousActivated);
						}
						$('html,body').animate({scrollTop: regioWrap.offset().top});
					}
					
				}
			});
		}
		
		sendToAnalytics(document.location.href);
		
	});
	
	$('div.categories a, div.subcategories a').click(function(evt) {
		
		evt.preventDefault();
		
		if ($(this).hasClass('home')) {
			document.location.href = '/';
		}
		else {
			$.history.load(this.href.replace(/https?:\/\/.*?(?=[\/#]{1,2})/, ''));
		}
	});
	
	if ($.browser.msie) {
		tab_shadow_elements.each(function() {
			$(this).dropShadow({
				left: -this.offsetLeft
			});
		});
	} else {
		tab_shadow_elements.dropShadow();
	}

	return obj;
}

function initCycle() {
    $('.picturelist').each(function() {
    	
    	if ($(this).data('cycle-initiated') != '1') {
	    	$(this)
	    		.data('cycle-initiated','1')
	    		.css({'overflow':'visible'})
	    		.cycle({
					fx: 'fade',
					//speed:  'fast',
					timeout: 4500,
					pager:  '.nav',
					slideExpr: 'img'
			    });
    	}
    });
}

function showRegio(regio, obj) {
	
	var regioText;
	if (regio == 'no') {
		regioText = 'Noord oost nederland';
	} else if (regio == 'zo') {
		regioText = 'Zuid oost nederland';
	} else if (regio == 'zw') {
		regioText = 'Zuid west nederland';
	} else if (regio == 'nw') {
		regioText = 'Noord west nederland';
	}
	
	obj = $(obj);
	
	var regioWrap = obj.is('.regio') ? obj : obj.closest('.regio');
	var regioText = regioWrap.find('.regio_text').html(regioText);
	Cufon.replace(regioText, {
		fontFamily: 'Eurostile'
	});
	
	regioWrap
		.find('.locatie').addClass('hidden').end()
		.find('.locatie.regio_'+regio).removeClass('hidden');
	
}

var previousActivated;

function accordeonActivate(element) {
  var sameElement = ((previousActivated != undefined) && (element.get(0) == previousActivated.get(0)));
  
  if (!element.data('lightboxInitialized')) {
	  element.find('.locatie_afbeelding a').unbind('click').lightbox();
  }
  
  if (previousActivated != undefined) {
  	//=-- Disable previously activated
  	previousActivated.find('.omschrijving_lang').hide();
  	previousActivated.find('a.corners_anchor').addClass('hidden');
  	previousActivated.find('a.locatieimg_1').removeClass('hidden');
  	previousActivated.find('.accordeon_seperator').html('<img src="/img/btn_leesmeer.jpg">');
  	}

	if (previousActivated == undefined || !sameElement) {
	//=-- Activate new locatie
	element.find('.omschrijving_lang').show();
	element.find('.accordeon_seperator').html('<img src="/img/btn_leesminder.jpg">');
	element.find('a.corners_anchor').removeClass('hidden');
	}
	previousActivated = (sameElement) ? undefined : element ;

}

function initOldMSIEhacks() {
	if ($.browser.msie && $.browser.version <= 7) {
		$('body').addClass('msie7');
	}
}


