$(document).ready(function(){
	if ( $('.breadcrumb_desc .desc').text() == '' )
	{
		$('.breadcrumb_desc').css( 'background-image', 'none' ).css( 'margin-bottom', '10px' );
	}
	
	var interval;

	$('#people_carrousel>ul')
		.roundabout({duration:1000})
		.hover(
			function() {
				// oh no, it's the cops!
				clearInterval(interval);
			},
			function() {
				// false alarm: PARTY!
				interval = startAutoPlay();
			}
		);

	// let's get this party started
	interval = startAutoPlay();

	//diensten hovers
	$('.service').hover(function(){
		$('> .pop', this).fadeIn( 100 );
	}, function(){
		$('> .pop', this).fadeOut( 200 );
	});
	
	$( '.service_item > a' ).each(function(){
		var href = $(this).attr( 'href' );
		var patterns = [
			{
				pattern: /diensten\/onderzoek/i,
				classToAdd: 'onderzoek'
			},
			{
				pattern: /diensten\/publiceren/i,
				classToAdd: 'publiceren'
			},
			{
				pattern: /diensten\/opleiding/i,
				classToAdd: 'opleiding'
			},
			{
				pattern: /diensten\/advies/i,
				classToAdd: 'advies'
			},
		];
		
		for ( var i = 0; i < patterns.length; ++i )
		{
			if ( patterns[ i ].pattern.test( href ) )
			{
				$(this).parent().addClass( patterns[ i ].classToAdd );
			}
		}
	});
	
	$( '.service_item a' ).hover( function() {
		$('img', this).css( 'border-width', '4px' ).css( 'padding', '1px' );
	}, function() {
		$('img', this).css( 'border-width', '1px' ).css( 'padding', '4px' );
	});

	// Breadcrumb
	$('h2.breadcrumb a > span:last').css('display', 'none');

	//Backbuttons
	$('.goback').bind('click', function(){
		history.go(-1);
		return false;
	});
});

function startAutoPlay() {
	return setInterval(function() {
		$('#people_carrousel>ul').roundabout_animateToNextChild();
	}, 4000);
}
