function fadeHeroImg()
{
	if( current_id != '' )
	{
		// INITIALISATION
		// Number of images
		var img_count = $('#'+current_id).children('.hero_img').length;
		img_count = img_count - 1;
		
		// What is the current image
		var current_img = $('#'+current_id).attr('currentimg');
		current_img = current_img;
		if( current_img < 0 || current_img > img_count )
		{
			current_img = img_count;
			$('#'+current_id).children('.hero_img').fadeIn('fast');
		}
		$('#'+current_id).attr('currentimg',current_img);
		

		if( current_img == 0 )
		{
			$('#'+current_id).children('.hero_img').eq(img_count).fadeIn(650);
			$('#'+current_id).attr('currentimg',img_count);
		}
		else if( current_img == img_count )
		{
			$('#'+current_id).children('.hero_img').show();
			$('#'+current_id).children('.hero_img').eq(current_img).fadeOut(650);
			$('#'+current_id).attr('currentimg',(current_img-1));
		}
		else
		{
			$('#'+current_id).children('.hero_img').eq(current_img).fadeOut(650);
			$('#'+current_id).attr('currentimg',(current_img-1));
		}

	}
	
	setTimeout("fadeHeroImg()", 2000);
}


$(document).ready(function(){
	
	// MAIN NAV
	var config = {    
	     sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)    
	     interval: 100, // number = milliseconds for onMouseOver polling interval    
	     over: function()
		{
			$(this).children('ul').fadeIn(100);
		}, // function = onMouseOver callback (REQUIRED)    
	     timeout: 200, // number = milliseconds delay before onMouseOut    
	     out: function()
		{
			$(this).children('ul').fadeOut(100);
		} // function = onMouseOut callback (REQUIRED)    
	};
	
	$('#main_nav li').hoverIntent(config);
	
	// HERO IMAGES FADE
	$('.hero_item').attr('currentimg',-1).each(function(i){
		$(this).attr('id','hero_item_fade'+(i+1));
	});

	current_id = '';
	fadeHeroImg();
	$('.hero_item').hover(
		function()
		{
			current_id = $(this).attr('id');
		},
		function()
		{
			current_id = '';
		}
	);
	
	
	// SET ALL CONTENT ELEMENTS TO SAME HEIGHT
	var max_height = 0;
	$('.teaser_item').each(function(){
		var this_height = $(this).height();
		if( this_height > max_height )
		{
			max_height = this_height;
		}
	})
	.css('height', max_height+'px');
	
});
