jQuery(document).ready(function(){
	
	/*
	 * Gallery
	 */
	$("ul.gallery").prettyGallery({
		itemsPerPage : 4,
		animationSpeed : 'normal', /* fast/normal/slow */
		navigation : 'bottom',  /* top/bottom/both */
		of_label: ' van ', /* The content in the page "1 of 2" */
		previous_title_label: 'Vorige pagina', /* The title of the previous link */
		next_title_label: 'Volgende pagina', /* The title of the next link */
		previous_label: 'Vorige', /* The content of the previous link */
		next_label: 'Volgende' /* The content of the next link */
	});
	
	/*
	 * Lightbox
	 */
	 $("a[rel^='lightbox']").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.45, /* Value between 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: false, /* true/false */
			counter_separator_label: ' van ', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
			callback: function(){}
	 });

	/*
	 * TABS
	 */
	$(".tab:not(:first)").hide();
	$(".tab:first").show();
	
	/*
	 * HISTORY
	 */
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	$.historyInit(pageload);
	
	// set onlick event for buttons
	$("a[rel='history']").click(function(){
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		$.historyLoad(hash);
		return false;
	});
});

// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state of tab
		settabstate(hash);
		
		//add achor to all links on the page
		$('a:not(.tablink, a.notablink, #home-btn), #meepraten').each(function(index, link){
			current = $(link);
			currenthref = current.attr("href");
			if(currenthref.match(/^.*#/)){
				//replace the anchor
				current.attr("href", currenthref.replace(/#.*/gi, "#"+hash));
			}else{
				//append the anchor
				current.attr("href", currenthref+"#"+hash);
			}
		});
	}
}

function getCurrentAnchor(){
	var hash = window.location.href;
	hash = hash.replace(/^.*#/, '');
}

//set a active tab
function settabstate(stringref){
	//hide tab content
	$('.tab:not(#tabbody-'+stringref+')').hide();
	
	//set tabs to not active
	$('.tabimage').each(function(index,image){
		current = $(image);
		current.attr("src", current.attr('src').replace("active-", ""));
	});
	
	activeTabImage = $('#tab-'+stringref);
	activeTabImage.attr("src", baseUrl+"images/active-"+activeTabImage.attr('src').split('/').slice(-1)); //set the active tab image
	
	if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") {
		$('.tab#tabbody-' + stringref).show();
	}
	else {
		$('.tab#tabbody-' + stringref).fadeIn();
	}
}

function openphoto(id, type){
	var url = baseUrl+id+'.'+type;
	var hiddenlink = $('#flash_lightbox');
	hiddenlink.attr('href', url);
	link = document.getElementById('flash_lightbox');
	
	if (link.dispatchEvent)
	{
		var e = document.createEvent("MouseEvents");
		e.initEvent("click", true, true);
		link.dispatchEvent(e);
	}
	else
	{
		link.click();
	}
}