$(function(){
	// slider in de content
	$(document).ready(function() {
		jQuery('#mycarousel').jcarousel();
	});
	
	// top slider
	$(document).ready(function() {
		$('#slider-images').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow', 
			timeout: 6000, 
			next:   '#prev', 
			prev:   '#next',
			delay:  -2000
		});
		$('#slider-content').cycle({ 
			fx:     'fade', 
			speed:  'slow', 
			timeout: 6000, 
			next:   '#prev', 
			prev:   '#next',
			delay:  -2000
		});	
	});

	// Sponsor slider
	$(document).ready(function() {
		$('#sub-sponsor').cycle({ 
			fx:     'scrollVert', 
			speed:  'slow', 
			timeout: 6000, 
			next:   '#nav-up', 
			prev:   '#nav-down',
			delay:  -2000
		});
		$('#co').cycle({ 
			fx:     'scrollVert', 
			speed:  'slow', 
			timeout: 6000, 
			next:   '#nav-up-co', 
			prev:   '#nav-down-co',
			delay:  -2000
		});	
		$('#bord').cycle({ 
			fx:     'scrollVert', 
			speed:  'slow', 
			timeout: 6000, 
			next:   '#nav-up-bord', 
			prev:   '#nav-down-bord',
			delay:  -2000
		});			
	});	
	
	// Aankomende wedstrijd
	$(document).ready(function() {
		$('#aankomende-slider ul').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow', 
			timeout: 6000, 
			delay:  -2000,
			next:   '#aan-next'
		});	
	});	
	
	// Content image
	$(document).ready(function() {
		$('#content-image').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow', 
			timeout: 6000, 
			delay:  -2000
		});	
	});		

	// Content image
	$(document).ready(function() {
		$('#banner-image').cycle({ 
			fx:     'fade', 
			speed:  1000, 
			timeout: 6000, 
			delay:  -2000
		});	
	});		
	
	// Content slider
	$(document).ready(function() {
		$('.stand').hide();
		$('.programma').hide();
		$('.wedstrijd').hide();
		
		$('#team').click(function(){
			// Verstop de andere content vakken
			$('.wedstrijd').hide();
			$('.stand').hide();
			$('.programma').hide();	
			
			// Laat de pagina zien
			$('.team').show();	

			return false;
		});
		
		$('#wedstrijd').click(function(){
			// Verstop de andere content vakken
			$('.team').hide();
			$('.stand').hide();
			$('.programma').hide();	
			
			// Laat de pagina zien
			$('.wedstrijd').show();	

			return false;
		});		

		$('#stand').click(function(){
			// Verstop de andere content vakken
			$('.wedstrijd').hide();
			$('.team').hide();
			$('.programma').hide();	
			
			// Laat de pagina zien
			$('.stand').show();	

			return false;
		});		

		$('#programma').click(function(){
			// Verstop de andere content vakken
			$('.team').hide();
			$('.stand').hide();
			$('.wedstrijd').hide();	
			
			// Laat de pagina zien
			$('.programma').show();	

			return false;
		});

		// Standenswitch
		$('#dames').hide();
		
		$('.selectie-heren').click(function(){
			// Verstop de andere content vakken
			$('#dames').hide();
			
			// Laat de pagina zien
			$('#heren').show();	
			
			return false;
		});	
		
		$('.selectie-dames').click(function(){
			// Verstop de andere content vakken
			$('#heren').hide();
			
			// Laat de pagina zien
			$('#dames').show();			

			return false;
		});	
	});

	/* Menu functie */
	$(document).ready(function() {
		function megaHoverOver(){
			$(this).find(".sub").stop().fadeTo('fast', 1).show();
				
			//Calculate width of all ul's
			(function($) { 
				jQuery.fn.calcSubWidth = function() {
					rowWidth = 0;
					//Calculate row
					$(this).find("ul").each(function() {					
						rowWidth += $(this).width(); 
					});	
				};
			})(jQuery); 
			
			$(this).calcSubWidth();
		}
		
		function megaHoverOut(){ 
		  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
			  $(this).hide(); 
		  });
		}

		var config = {    
			 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 0, // number = milliseconds for onMouseOver polling interval    
			 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
			 timeout: 500, // number = milliseconds delay before onMouseOut    
			 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
		};
	 
		$("ul#topnav li .sub").css({'opacity':'0'});
		$("ul#topnav li").hoverIntent(config);
	});	
});

window.onload = function() {
            var links = document.getElementsByTagName("a");
            for (var i = 0; i < links.length; i++) {
                        var rels = links[i].getAttribute("rel");
                        if (rels) {
                                   var testpattern = new RegExp("external");
                                   if (testpattern.test(rels)) {
                                               links[i].onclick = function() {
                                                           return !window.open(this.href);  
                                               }
                                   }
                        }
            }
}


