$(document).ready(function(){
 		// Preload all rollovers
		$(".menu a img").each(function() {
			// Set the original src
			rollsrc = $(this).attr("src");
			rollON = rollsrc.replace(/.png$/ig,"-red.png");
			$("<img>").attr("src", rollON);
		});
		
		// Navigation rollovers
		$(".menu a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			matches = imgsrc.match(/-red/);
			
		// don't do the rollover if state is already ON
		if (!matches) {
			imgsrcON = imgsrc.replace(/.png$/ig,"-red.png"); // strip off extension
			$(this).children("img").attr("src", imgsrcON);
			}
		});
		$(".menu a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});
		
		// content fadeout on menu click
		$(".menu a, .werkmenu a").click(function(event){
			event.preventDefault();
			var waarwenaartoegaan = $(this).attr("href");
			$("div.effect").animate({top: "-1000px", opacity: "0"}, 500, function(){
				$("div.effect").hide();
				window.location = waarwenaartoegaan;	
			});
		});
		
		// content hide untill loaded
		$("div.effect").hide();
		$("div.loading").hide();
		$("div.loading").fadeIn();
		
		//laad faceboxes
		jQuery('a[rel*=facebox]').facebox()
		
		//laad twitter
		if ($(".twitter").length > 0) {
			$(".twitter").getTwitter({
				userName: "contonnaer",
				numTweets: 4,
				loaderText: "Loading tweets...",
				slideIn: true,
				showHeading: false,
				headingText: "Twitter"
			});
		}
		
		// cycle

	if ($(".cycle ul").length>0) {
		$('.cycle ul').cycle({
			fx: 'fade',
			timeout: 0,
			next:   '.next', 
			prev:   '.prev'
		});
	}	
}); 

$(window).load(function(){
	$("div.effect").css("top", "2000px").show();
	$("div.home").animate({top: "160px"}, 1000);
	$("div.nieuws").animate({top: "80px"}, 1000);
	$("div.visie").animate({top: "145px"}, 1000);
	$("div.werk").animate({top: "171px"}, 1000);
	$("div.referenties").animate({top: "156px"}, 1000);
	$("div.contact").animate({top: "100px"}, 1000);
	$("div.loading").fadeOut();
	$("div.opdehoogte").delay(2500).fadeOut();
	

});

	$(document).bind('keydown', function(e) { 
		if (e.keyCode == 37)$('.cycle ul').cycle('prev');
		else if (e.keyCode == 39)$('.cycle ul').cycle('next'); 
	});
