$(document).ready(function(){
	
	// Add event delegation on hover for performance
	$('area').live('mouseover mouseout', function(event){
		
		if(event.type == 'mouseover'){
			
			countyname = $(this).attr('alt');

			//Check for county to overcome flickering
			if(countyname != "")
			{
				$('#county-picker').css({'display': 'block'});
			}
			
		}
		else
		{
			$('#county-picker').css({'display': 'none'});
			
		}

	});
	
//		$('#county-picker').css({'display': 'none'});

	
	// Compute mouse position for map hover
	$('map').mousemove(function(e){
		posx =  e.pageX -150;
		posy = e.pageY -60;
		
		$('#county-picker').css({'top': posy + 'px', 'left': posx  + 'px'});
		$('#county-picker #county-picker-bubble').html(countyname);	
		
	});
	
	
	$('#top-menu li').click(function(){
		$('ul', this).toggle();		
	});
	
	$('#cols').equalHeights();
	
	// Refresh to selected site
	
	$('#site-changer').change(function() {
		var site = $(this).val();
		document.location.href= site;
	});

	// Get names from county from alt attributes

/*	$('area').hover(function(){

		var countyname = $(this).attr('alt');
	
		$('#county-picker').empty(this).append('<div class="tooltip">Gemeente ' + countyname + '</div>');

	});*/
	
	$('.gmnoprint').click(function(){
	
		window.location("http://maps.google.com");
		
	});

	// Keep track of current panel
	current_panel = 1;  
	panels = $('.wp_bannerize_sidebar_nl li').size();
    animation_duration = 1000;  
	
    $.timer(2000, function (timer) {  

		// Did we reach the final add? Move back to front, else go to the
		// next panel 
		if(current_panel == panels)
		{
			move = 0;
			current_panel = 0;
		}
		else
		{
			move = current_panel * -300; 
		}
		
		// Move the banner and add one
		$('.wp_bannerize_sidebar_nl ul').stop().animate({left: + move + "px", top: "0px"}, {easing: 'easeOutQuad', duration: animation_duration}); 				
        current_panel = current_panel+1;
		
		// And repeat
		timer.reset(4000);

    });  

});
