Cufon.replace('#menu > li > a', { fontFamily: 'ITC Franklin Gothic Std MedCd', color: '-linear-gradient(white, 1=#d1d1d1)' });
Cufon.replace('#welcome, h1.pageTitle, .box h2:not(#box11970131 h2), h3, h4, #branchList .branchTitle', { fontFamily: 'ITC Franklin Gothic Std Bk Cd'});

// Google maps
function initializePreviewMap(locationId) {
	$.post('/gateway/route/?localAction=details', {id: locationId}, function(data){
		var latlng, map, marker, i;
		latlng  =new google.maps.LatLng(parseFloat(data.lat), parseFloat(data.lon))
	    map = new google.maps.Map(document.getElementById("mapCanvas"), { zoom: 16, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP });
    	marker = new google.maps.Marker({
    		position: latlng,
    		map: map
    	});
    	google.maps.event.addListener(marker, 'click', function() {
			window.location = $('#location_'+ locationId +' a').attr('href');
		});

		//fill the contactbox and make maillink clickable
		for (i in data) $('#'+ i).html(data[i]);
	}, 'json');
}

function fillContactDetails(locationId) {
	$.post('/gateway/route/?localAction=contactDetails', {id: locationId}, function(data){
		var contact;
		$('#contactDetails').html('');
		if (data.length>0) {
			contact = data[0]; //#12717266 - Contact personenen bij Jouw ideale bijbaan
			$('#contactDetails').append('<div class="contact" id="contact0"></div>');
			$('#contactDetails #contact0').append('<img align="left" src="/download/?id='+ contact['foto'] +'&width=68&height=68&zc=T"/>');
			$('#contactDetails #contact0').append('<span class="contactName">'+ contact['naam'] +'</span>');
			$('#contactDetails #contact0').append('<span class="contactFunction">'+ contact['functie'] +'</span>');
			$('#contactDetails #contact0').append('<a href="mailto:'+ contact['mail'] +'">'+ contact['mail'] +'</a>');
			$('#contactDetails').removeClass('hidden');
		}
	}, 'json');
}

$(document).ready(function() {
	var ol, overlayDiv, accordionTimer;
	$('#searchForm').appendTo('#bottomPage11718806');
	$('.hideMyLabel').labelHider();
	$("#menu, #loggedInMenu > ul").superfish({speed:0, autoArrows: false, dropShadows: false, onBeforeShow: function() { $(this).parent().addClass('open'); }, onHide: function() { $(this).parent().removeClass('open'); } });

	$('#location').append('<div id="messages"></div>');
	$('#signupForm').validate({
		groups: { geboortedatum: 'dag maand jaar' },
		errorPlacement: function(error, element) {
			if (element.attr("name") == "vestiging") {
				error.insertAfter("#location legend");
			} else if (element.attr("name") == "dag" || element.attr("name") == "maand" || element.attr("name") == "jaar" ) {
				error.insertAfter("#jaar");
			} else {
				error.insertAfter(element);
			}
		},
		messages: { vestiging: "Selecteer op z'n minst 1 vestiging" }
	});

	$('#branchList > li').click(function() {
		if ($(this).hasClass('open')) {
			$(this).removeClass('open');
		} else {
			$(this).addClass('open').siblings('li').removeClass('open');
		}
	});
	// all pages but contact index
	$('.contactBox #vestigingId').change(function() {
		if ($(this).val()!='') window.location = $(this).val();
	});

	$('#newsMonth').change(function() {
		if ($(this).val()!='') { window.location = '/nieuws&localAction=month&year='+ $(this).val().split('-')[1] +'&month='+ $(this).val().split('-')[0]; }
	});
	$('#weblogEntryMonth').change(function() {
		if ($(this).val()!='') { window.location = '/pepper-academy&localAction=month&year='+ $(this).val().split('-')[1] +'&month='+ $(this).val().split('-')[0]; }
	});

	//visuals...
	if ($('.visual').length >0 ) {
		$('#visualContainer').show();

		ol = $('<ol></ol>');
		$('.visual').each(function() {
			var link;
			var li = $('<li>'+ $(this).attr('id').split('_')[1] +'</li>');
			li.data('domElement', $(this));
			li.click(function() {
				if (!li.data('domElement').is(':visible')) {
					li.data('domElement').fadeIn('slow');
					$(this).data('domElement').siblings().fadeOut('slow');
					$(this).addClass('active').siblings('li').removeClass('active');
					$('#visualContainerOverlay').unbind('click');
					link = li.data('domElement').find('a');
					if (link.length > 0) {
						$('#visualContainerOverlay').css('cursor', 'pointer').click(function() {
							window.location = link.attr('href');
						});
					} else {
						$('#visualContainerOverlay').css('cursor', 'default');
					}
				}
				return false;
			});
			ol.append(li);
		});
		ol.prependTo('#visualContainerOverlay');
		ol.find('li:first').click();
		if ($('.visual').length == 1) ol.hide();
		else {
			var startAccordionTimer = function() {
				accordionTimer = $.timer(7000, function (timer) {
					var nextItem = $("#visualContainerOverlay li.active").next();
					if (nextItem.length == 0) nextItem =  $("#visualContainerOverlay li:first");
					nextItem.click();
				});
				$('#visuals a').removeClass('hover');
			}
			$('#visualContainerOverlay').hover(function() {
					accordionTimer.stop();
					$('#visuals a').addClass('hover');
				},
				startAccordionTimer
			);
			startAccordionTimer();
		}
	}
});

$(window).load(function() {
	//make sure siteBottom IS at the bottom!
	var newHeight = $(window).height() + $(window).scrollTop() - $('#siteBottom').height() - $('#footer').height() - 20;
	if (newHeight>$('.centerContainer:first').height()) {	$('.centerContainer:first').height(newHeight); }
});