// All the controls for the NSE site.
$(document).ready(function(){
	//All code dealing with the JS effects for the student type/term pesonalization widget.
	$('#studentTerm').hide();
	$('#studentTermSet').hide();
	if (cookiepresence == 0)
	{
		$('#studentTerm').show();
	}
	else
	{
		$('#studentTermSet').show();
	}
	$('#changeContent').click(function(){
		$('#studentTermSet').slideUp("slow", function() {
			$('#studentTerm').slideDown("slow");										  
		});
	});
	//End student type/term pesonalization widget.
	//
	//set the ajax start and stop functions
	$('#load').ajaxStart(function(){
		$(this).html("<img src='/ucomm/templatedependents/templatecss/images/loading.gif' alt='Loading your request' />");
	});
	$('#load').ajaxStop(function(){
		$(this).empty();
	});
	//End ajax functions
	//
	//Admin page navigation
	$('ul#fileList>li>ul>li>a').click(function() {
		gatherContentTypes($(this).attr("href"));
		return false;
	});
	//$("#fileList").treeview();
})

//A cleanup function to pull out just the pageID
function pullPageIDFromA(href) {
	var pullPageIDSplit = href.split("?PageID_");
	var cleanPageID = pullPageIDSplit[1]; //now we have a number
	return cleanPageID;
}

//This function is used to get the list of content types for each page
function gatherContentTypes(pageID) {
	//alert(pageID);
	$.ajax({
		type: "POST",
		url: "/sharedcode/admin/ajax/getPageContent.php",
		data: "pageID="+pullPageIDFromA(pageID),
		dataType: "html",
		success: function(contentOptions) {
			//alert(contentOptions);
			$("a[@href="+pageID+"]").siblings().remove();
			$("a[@href="+pageID+"]").after(contentOptions);
		}
	});	
}