Cufon.replace('.nav',{hover:true})('.subnav',{hover:true})('.introlink',{hover:true});
//('.prodanchor',{hover:true})

$(document).ready(function(){
	setScroll();
	$("#maps").maps();
	$('.lb').fancybox({'type':'iframe', width:600, height:600, padding:1});
	setTimeout(function(){startticker();},200);
	setInterval(checkTickerPosition,10);
	$("#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(); 
		}
	);
	
	
	if($(".medewerkersdetail").length > 0){
		$(".medewerkersdetail li").each(function(){
		  $(this).appendTo('.medewerkersdetail:last');
		$(".medewerkersdetail li").hide();
		})
	}
	$(".medewerkersdetail li:first").show();
	$(".medewerkerslijst:first a:first").css('color','#b72727');
	$(".medewerkerslijst a").click(function(e){
		e.preventDefault();
		var rel = $(this).attr("rel");
		$(".medewerkersdetail li").hide();
		$(".medewerkerslijst a").css('color','#000000');
		$(".medewerkersdetail li[rel="+rel+"]").show();
		$(this).css('color','#b72727');
		setScroll();
		
	});
	// window.setTimeout(FrameManager.init, 300);
});

$(window).resize(function(){
	setScroll();
});

function setScroll(){
	if ($('.jScrollPaneContainer').length > 0) {
		$('#content:not(.noscroll)').insertBefore($('.jScrollPaneContainer')).removeAttr('style');
		$('.jScrollPaneContainer').remove();
	}
	$('#content:not(.noscroll)').height(
		$(window).height() - 144 - 85 - 23 - 20
	);
	$('#content:not(.noscroll)').jScrollPane({
		scrollbarWidth: 12,
		scrollbarMargin: 15,
		dragMinHeight: 50,
		dragMaxHeight: 50
	});
}

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();
		}
	});
}

function startticker(){
	$('#ticker a').lightBox({txtImage :'Foto',txtOf :'van'});
	$("#ticker ul").stop(); 
	var totalwidth = 0;
	$("#ticker ul li").each(function(){	totalwidth += $(this).innerWidth(); })
	$("#ticker ul").animate({ 
		left: "-"+totalwidth+"px"
	  }, totalwidth * 20, "linear");
}
