$(document).ready(function(){	
	
	$('#logo').click(function(){
		location.href= $(this).attr('href');
	});
		
	$('div.subsubcol a.play2').toggle(
	function(){
		$(this).css({
			backgroundImage: 'url(images/play2.gif)'
		});
		height=$(this).parent().find('ul.feeder').outerHeight();
		$(this).parent().animate({
			height: height
		},300);
	},
	function(){
		$(this).css({
			backgroundImage: 'url(images/play.gif)'
		});
		$(this).parent().animate({
			height: 54
		},300)
	}
	);
	
	$('a.play').toggle(
	function(){
		$(this).css({
			backgroundImage: 'url(images/play2.gif)'
		});
		height=$(this).parent().find('ul.feeder').outerHeight();
		$(this).parent().animate({
			height: height+20
		},300);
	},
	function(){
		$(this).css({
			backgroundImage: 'url(images/play.gif)'
		});
		$(this).parent().animate({
			height: 20
		},300)
	}
	);
	
/*
	$('a.hoofdnav:eq(1)').hover(
		function(){
			$('#submenu').show(300);	
		},
		function(){
			$('#submenu').delay(500).hide(300);
		}
	);
*/
	
	$('#submenu').hover(
		function(){
			$(this).stop(true, true).show();
		},
		function(){
			$(this).stop(true, true).hide(300);
		}	
	)	
	
	startticker();
	setInterval(checkTickerPosition,50);
	$("#ticker ul li").hover(function(){ 
					$("#ticker ul").stop(); 
					$(this).attr('id','activeLI');
					var currentItem = $(this);
					var stopped = false;
					var widthPerLI = 0;
					$("#ticker ul li").each(function(){	
						if($(this).attr('id') ==  'activeLI' && stopped == false){
							stopped = true;
							if(parseInt($("#ticker ul").css('left')) < (-widthPerLI)){
								var newpos = (parseInt(widthPerLI)-10);
								$("#ticker ul").animate({ 
									left: -newpos+"px"
								}, 200);
							}
						}
						widthPerLI += $(this).innerWidth(); 
					});
				  }, 
				  function(){ 
					$("#activeLI").attr('id','');
					startticker(); 
		}
	);
	

function checkTickerPosition(){
	var newpos = 0;
	var widthPerLI = 0;
	var totalpos = parseInt($("#ticker ul").css('left'));
	$("#ticker ul li").each(function(){	
		widthPerLI += $(this).innerWidth(); 
		if(widthPerLI < -1 * totalpos){
			$("#ticker ul").stop();
			newpos = totalpos + $(this).innerWidth();
			$(this).appendTo("#ticker ul");
			$("#ticker ul").css('left', newpos+'px');
			totalpos = newpos;
			startticker();
		}
	});
}

/*
 * /*
$('#nieuwsbrief').submit(function(){
		$('#loader').show();
		form = $(this);
		
		$.ajax({
					type: 	form.attr('method'),
					url: 	form.attr('action'),
					data: 	form.serialize(),
					success: function(msg){
							$('#loader').hide();
							$('#'+form.attr('target')).html(msg);
					}
				});
		return false;
	});
		
});
*/

});


function startticker(){
	$("#ticker ul").stop(); 
	var totalwidth = 0;
	$("#ticker ul li").each(function(){	totalwidth += $(this).innerWidth(); })
	$("#ticker ul").animate({ 
		left: "-"+totalwidth+"px"
	  }, totalwidth * 20, "linear");
}


