//Waypoint one page analytics function
function trackWaypoint(waypoint)
{
      window.clearTimeout(this.track);
      //Track the pageview after 2 seconds
      this.track = window.setTimeout(function() {
         //console.log("/" + waypoint);
         _gaq.push(['_trackPageview', '/' + waypoint])
      }, 2000);
}

jQuery(function($) {
	// Register each section as a waypoint.
	
	opts = {
		offset: '50%'
	};
	
	$('section, footer').waypoint(function(event, direction) {
		
		var $active = $(this);
		
		if (direction === "up") {
			$active = $active.prev();
         if(!$active.attr('id')) {
            $active = $('#zakelijk');
         }
		}
		if (!$active.length) {
		  
		  $active.end();
        }
		
		
		$('.active').removeClass('active');
		$('a[href=#'+$active.attr('id')+']').addClass('active');
		
		//Track waypoints in Google Analytics
        trackWaypoint($active.attr('id'));
		
		
	}, opts);
	
	
	// Negates the flash of non-active nav.
	$('body header nav a').click(function() {
		$(this).addClass('active');
	}).eq(0).addClass('active');
	
	
});

$(document).ready(function() {
	 $('#navigation, article').localScroll({
	     hash: "true"
	 });
	
	 $("#subscribeForm").validate({
 
         messages: {
    	 	naam: "Vergeet niet je naam in te vullen.",
    	 	mail: {
    	 		required: "Vergeet niet je e-mailadres in te vullen.",
    	 		email: "Je e-mailadres is niet geldig."
    	 	}
    	 }
     
     });
     
     $("#contactForm").validate({
 
         rules: {
            telefoon: {
                required: "#belmij:checked"
            }
         },
         messages: {
    	 	naam: "Vergeet niet je naam in te vullen.",
    	 	telefoon: "Vergeet niet je telefoonnummer in te vullen, zodat we je kunnen bellen.",
    	 	mail: {
    	 		required: "Vergeet niet je e-mailadres in te vullen.",
    	 		email: "Je e-mailadres is niet geldig."
    	 	}
    	 }
 
     });
     
     $("#belmij").click(function() {
        $("#contactForm #telefoon").valid();
     });    
     
     $('#contactForm').ajaxForm(function() { 
         $('#formWrapper').slideUp(600,
             function () { $('#formSend').slideDown(600) }
         );    
     });
     
     $('#subscribeForm').ajaxForm(function() { 
         $('#subscribeFormWrapper').slideUp(600,
             function () { $('#subscribeFormSend').slideDown(600) }
         );    
     });
     
     $('#header').stickyfloat({ duration: 1000 });
     
     
     //external links
     jQuery("a[href^='http:']").not("[href*='mfgolf.nl']").attr('target','_blank');
    
    	
            $('.slider').cycle({ 
                pager: '.switch',
                pagerAnchorBuilder: function(idx, slide) { 
                    return '<li><a href="#"></a></li>';
                },
                fit: 'true', 
                fx: 'fade',
                timeout: 7000,
                speed:   1000 
            })
     
}); 




