$(document).ready(function() {
	
	
	/* if contentitem poll is defined */
	$("#slider").slider({ 
	value: 50,
	change: function(event, ui) { 
		document.getElementById('poll-answer').value = $('#slider').slider('option', 'value');		
		}
	});
	
	$("#tickerlist").newsticker();
	
	/* if accordion agenda is defined */
	$("#agenda").accordion({
			autoHeight: false
	});
	
	/* if accordion carousel-pers is defined */
	$("#carousel-pers").accordion({
			autoHeight: false
	});
	
	/* if accordion carousel-relaties is defined */
	$("#carousel-relaties").accordion({
			autoHeight: false
	});
	
	/* carousel start */
	var playSlideshow =  setInterval( "slideSwitch()", 8000 );
	
	$('#carousel').hover(function() {
    clearInterval(playSlideshow);
	},
	function() {
    	playSlideshow =  setInterval( "slideSwitch()", 8000 );
	});
	
	$("#carousel .btn-next").click(function(){
		slideSwitch(null);
	});
	
	$("#carousel .btn-prev").click(function(){
		slideSwitch("prev");
	}); 
	
	/* hover image for higher lvl mainnav change */
	$("li.forensische-dienstverlening a").mouseover(function(){
		$("li.bedrijfsrecherche a").removeClass("selected");	
	});
	$("li.forensische-dienstverlening a").mouseout(function(){
		$("li.bedrijfsrecherche a").addClass("selected");	
	});
	$("li.strategisch-risk-management a").mouseover(function(){
		$("li.bedrijfsrecherche a").removeClass("selected");	
	});
	$("li.strategisch-risk-management a").mouseout(function(){
		$("li.bedrijfsrecherche a").addClass("selected");	
	});

});

/* carousel transitions based on JQuery */
function slideSwitch(action) {

	var $active 	= $('#items .item.active');
	var $listitem 	= $('#carousel ul li.active');
	
	if ( action == "prev" ) {
		
		var $prev =  $active.prev().length ? $active.prev()
        : $('#items .item:last');
		
		var $prevlist =  $listitem.prev().length ? $listitem.prev()
        : $('#carousel ul li:last');
	
		$active.addClass('last-active');
		
		$prev.css({opacity: 0.0})
        	.addClass('active')
        	.animate({opacity: 1.0}, 800, function() {
            	$active.removeClass('active last-active');
				
        });
		$prevlist.addClass('active');
		$listitem.removeClass('active');
		
	}
	
	else {
		
		if ( $active.length == 0 ) $active = $('#carousel .item:last');

    	var $next =  $active.next().length ? $active.next()
        	: $('#items .item:first');
		
		var $nextlist =  $listitem.next().length ? $listitem.next()
        : $('#carousel ul li:first');

    	$active.addClass('last-active');

		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 800, function() {
				$active.removeClass('active last-active');
				
		});
		$nextlist.addClass('active');
		$listitem.removeClass('active');
		
	}
}

