$(document).ready(function(){
	//References
	var loading = $("#loading");
	var content = $("#switch-content");

	//show loading bar
	function showLoading(){
		loading.css({'visibility':'visible','opacity':'1','display':'block'});
		
		$(document.createElement('div'))
		.attr('id','cover')	
		.width($('#switch-container').width() + 20)
		.height($('#switch-container').height() + 20)
		.css({'backgroundColor':'#FFFFFF', 'opacity':'0.8', 'position':'absolute','left':'-20px', 'top':'-20px', 'zindex':'998'})
		.prependTo($('#switch-container'))

	}
	
	//hide loading bar
	function hideLoading(){
		$('#cover').fadeOut(500, function() { $('#cover').remove(); });
		loading.fadeTo(500, 0);
	}
	
	//Manage click events
	$('a[id^="interest-nav"]').live('click', function(){
													  
		$('a[id^="interest-nav"]').removeClass('active');
												
		var id = $(this).attr('rel');
		
		//show the loading bar
		showLoading();
		//load selected section
		switch(id){
			case "attractions":
				content.load("/includes/local-interests-content.php #attractions", hideLoading);
				$(this).addClass('active');
				break;
			case "theatres":
				content.load("/includes/local-interests-content.php #theatres", hideLoading);
				$(this).addClass('active');
				break;
			case "museums":
				content.load("/includes/local-interests-content.php #museums", hideLoading);
				$(this).addClass('active');
				break;
			case "outdoors":
				content.load("/includes/local-interests-content.php #outdoors", hideLoading);
				$(this).addClass('active');
				break;
			case "railways":
				content.load("/includes/local-interests-content.php #railways", hideLoading);
				$(this).addClass('active');
				break;
			default:
				//hide loading bar if there is no selected section
				hideLoading();
				break;
		}
		
	});
	
});