$(document).ready(function() {

	var COOKIE_NAME = 'Expand ' + document.title;
	var options = {
		expires : 10,
		path : '/'
	};

	$(".cHeadSlow, .cHeadFast, .cHeadInstant").each(function() {

		if ($.cookie(COOKIE_NAME + " - " + $(this).attr("id")) == 'X') {

			$("+ .cBody ", this).show();
			$(this).toggleClass("cPlus");
		}
	});

	$(".cHeadSlow").click(function() {

		$("+ .cBody ", this).slideToggle("slow");
		$(this).toggleClass("cPlus");

		if ($(this).attr("id")) {

			if (!$(this).hasClass("cPlus")) {
				$.cookie(COOKIE_NAME + " - " + $(this).attr("id"), 'X', options);
			} else {
				$.cookie(COOKIE_NAME + " - " + $(this).attr("id"), '', options);
			}
		}
	});

	$(".cHeadFast").click(function() {

		$("+ .cBody ", this).slideToggle("fast");
		$(this).toggleClass("cPlus");

		if ($(this).attr("id")) {

			if (!$(this).hasClass("cPlus")) {
				$.cookie(COOKIE_NAME + " - " + $(this).attr("id"), 'X', options);
			} else {
				$.cookie(COOKIE_NAME + " - " + $(this).attr("id"), '', options);
			}
		}
	});

	$(".cHeadInstant").click(function() {

		$("+ .cBody ", this).toggle();
		$(this).toggleClass("cPlus");

		if ($(this).attr("id")) {

			if (!$(this).hasClass("cPlus")) {
				$.cookie(COOKIE_NAME + " - " + $(this).attr("id"), 'X', options);
			} else {
				$.cookie(COOKIE_NAME + " - " + $(this).attr("id"), '', options);
			}
		}
	});
	
	$("a.PeopleUnitsByFaculty").click(function() {
		
        DynaLoad("../PPPUnits/UGPeopleUnitsByFaculty/");		
        
	});
	$("a.PeopleUnitsByCode").click(function() {        
		
        DynaLoad("../PPPUnits/UGPeopleUnitsByCode/");		
        
	});
	$("a.PeopleUnitsByDept").click(function() {
        
        DynaLoad("../PPPUnits/UGPeopleUnitsByDepartment/");		
        
	});
    
	$("a.PlanetUnitsByFaculty").click(function() {        
        
		DynaLoad("../PPPUnits/UGPlanetUnitsByFaculty/");		
        
	});
	$("a.PlanetUnitsByCode").click(function() {
            
		DynaLoad("../PPPUnits/UGPlanetUnitsByCode/");
		
	});
	$("a.PlanetUnitsByDept").click(function() {
        
		DynaLoad("../PPPUnits/UGPlanetUnitsByDepartment/");
		
	});
	$("a.ParticipationUnitsByFaculty").click(function() {
        
		DynaLoad("../PPPUnits/UGParticipationUnitsByFaculty/");
		
	});
	$("a.ParticipationUnitsByCode").click(function() {
        
		DynaLoad("../PPPUnits/UGParticipationUnitsByCode/");
		
	});
	$("a.ParticipationUnitsByDept").click(function() {
        
		DynaLoad("../PPPUnits/UGParticipationUnitsByDepartment/");
		
	});

});

var DynaContentID = "#dyna-contents";
var DynaContentLoadingID = "#dyna-content-loading";
var DynaCurrentPage = "";

function DynaLoad(PageToLoad) {
	//$('#dyna-contents').load(PageToLoad);
	$.get(PageToLoad, function(data) {
		  $(DynaContentID).html(data);
		});

}
function hideAll(count)
{
	for(var i=1; i<count; i++)
		$('#dynaDiv'+i).hide();
}
function display(divname,count)
{
	hideAll(count);
	$(divname).toggle();
	var title = $(divname).attr("title");
	$('h3#People_Units').text("People units by faculty ("+title+")");
	$('h3#People_UnitsDept').text("People units by department ("+title+")");
	$('h3#Planet_Units').text("Planet units by faculty ("+title+")");
	$('h3#Planet_UnitsDept').text("Planet units by department ("+title+")");
	$('h3#Participation_Units').text("Participation units by faculty ("+title+")");
	$('h3#Participation_UnitsDept').text("Participation units by department ("+title+")");
    
    var PageTitle = $('h2#PPPTitle').attr("title");
    $('h2#PPPTitle').text(PageTitle + " (" + title + ")");
}

function PPPHighlighter(element) {
    $("ul.PPPUnits li").each( function (index) {       
       $("a", this).removeAttr('style');
    });
    $(element).css("color","#991218");
    $(element).css("border-bottom", "1px solid #991218");
}

function OUHighlighter(element) {
    $("ul.OUFacultyDept li").each( function (index) {       
       $("a", this).removeAttr('style');
    });
    $(element).css("color","#991218");
    $(element).css("border-bottom", "1px solid #991218");
}
