$(document).ready(function() {
	// acetrand 11-07-11, added word Ref after func names, otherwise they will be called from start.js		
	// acetrand 11-10-06, added check to see if there is a sidebar, dont run otherwise
	if( $(".sidebar li").length > 0) {		   
		setDefaultActiveRef();
		markActiveRef();
	}
});

function setDefaultActiveRef(){
	$(".sidebar li").removeClass('active');
	var firstListItem = $(".sidebar li").first().addClass('active');
	var firstListItemLink = $(".sidebar li").first().children()[0];
	var refId = firstListItemLink.id;
	loadReference(refId);

}

function markActiveRef(){
	$(".sidebar-item").click(function(event) {
		event.preventDefault();
		$(".sidebar li").removeClass('active');
		$(this).parent().addClass('active');
		var refId = this.id;
		loadReference(refId);
	});
}

function loadReference(refId){
	$.ajax({
		url: "/getref/"+refId+"/",
		type: "GET",
		async: false,
		success: function(html){
			$(".section").html(html);
			initGalleries(); // See jquery.main.js
		}
	});
}

