

function loadPage(pagetoload) {
	//load pagebody and do appropriate fading
	var pb = $("#page_body");
	pb.slideUp(300, function(){ 
		pb.load("/content/" + pagetoload + ".html", function() {
			
			
			//set all .contentBox's to the right css
			$(".contentBox").each( function(n, box) {	
				$(box).replaceWith('<div class="roundedcornr_box" style="margin-bottom: 15px;"><div class="roundedcornr_top"><div></div></div><div class="roundedcornr_content" style="padding: 0px 15px;">' + 
			   	$(box).html() + '</div><div class="roundedcornr_bottom"><div></div></div></div>');
			});
		
		
			//fade out the current selected and remove class
			$("#menu li.selected").stop().animate( { backgroundColor: '#e5e5e5', borderColor: '#e5e5e5'} , 300).removeClass("selected");
			//set class for new page on menu and fade in
			$("#menu li[rel=" + pagetoload + "]").stop().animate( { backgroundColor: '#c9c9c9', borderColor: '#e5e5e5'}, 300).addClass("selected");
			
			
			$("#menu li").unbind('mouseenter');
			$("#menu li").unbind('mouseleave');
			
			//menu hover callbacks
			$("#menu li:not(.selected)").hover(function(){
				$(this).stop().animate( { backgroundColor: '#AAAAAA', borderColor: '#f9f9f9' } , 300);
			}, function(){
				if($(this).hasClass("selected"))
					$(this).stop().animate( { backgroundColor: '#c9c9c9', borderColor: '#e5e5e5'}, 300); 
				else
					$(this).stop().animate( { backgroundColor: '#e5e5e5', borderColor: '#e5e5e5'} , 300);
			});
			
			pb.slideDown(300);
		});
	});	

	

	
} 
//document ready
$(document).ready(function() {
	


	//load news by default
	loadPage("news");
		
	var menuButtonHandler = function(e) {
		//if we are already on the page do nothing
		if($(this).hasClass("selected") )
			return true;
	
		//find the content from the rel tag
		var pagetoload = $(this).attr("rel");
		$(this).stop().animate( { backgroundColor: '#999999', borderColor: '#FFFFFF' } , 30, function() {
			loadPage(pagetoload);
		});
	};
	
	$("#menu li").click(menuButtonHandler);	

});
