var menuActive = false; //  used to determine when the menu dropdown is active
var collapseTimeout = null; // used for the menu collapse timer function
var currentPtype = 0; // contains the current active section (financial prof, operational advisor, strategic relationship)

/*********************************************
 * Function: 	showType()
 * Desc: 		Changes the major section
 *				(financial prof, operational advisor, strategic relationship)
 *********************************************/
function showType(ptype)
{
	// switch out content
	if(currentPtype == 0)
	{
		$("#pplIntro").fadeOut("fast", function(){
			$("#ptype"+ptype).fadeIn("fast");
			$("#posSelector"+ptype).addClass("positionOn");
		});
		
		loadMenu(ptype);
	}
	else
	{
		if(ptype != currentPtype)
		{
			$("li.filterMenu").slideUp("fast", function(){
				loadMenu(ptype);
			});

			$("#posSelector"+currentPtype).removeClass("positionOn");
			$("#ptype"+currentPtype).fadeOut("fast", function(){
				//reset the filter
				filter(0,'');				
				
				//show the new section
				$("#ptype"+ptype).fadeIn("fast");
				$("#posSelector"+ptype).addClass("positionOn");
			});
		}
	}
	
	
	currentPtype = ptype;
}

/*********************************************
 * Function: 	loadMenu() 
 * Desc: 		toggles the menu for operational advisors
 *				and adds appropriate mouse events
 *********************************************/
function loadMenu(ptype)
{
	 if(ptype ==2)
	 {
		$("li.filterMenu").slideDown("fast");

		$('li.filterMenu').hover(function() {
			clearTimeout(collapseTimeout);
			$(".filterMenuItems").slideDown("fast");
		}, function() {
			collapseTimeout = setTimeout(collapseMenu, 500);
		});
		 

	 $(".filterMenu a").click(function(){
		$(".filterMenuItems").slideUp("fast");
	 });
	}
}

/*********************************************
 * Function: 	collapseMenu() 
 * Desc: 		closes the menu dropdown
 *********************************************/
function collapseMenu()
{
		$(".filterMenuItems").slideUp("fast");
}

/*********************************************
 * Function: 	filter() 
 * Desc: 		changes which people have active links
 *********************************************/
function filter(spec, label)
{
	var showClass = "spec" + spec;
	
	$.each($(".pplCol").contents(),function(){
		if($(this).hasClass(showClass) || spec == 0)
		{
			if(!$(this).contents().is("a"))
			{
				// insert 'a' tag, only if it doesnt exist
				$(this).wrapInner("<a class='person' href=\"details.php?pid="+$(this).attr("pid")+"\" onclick=\"return $.showAkModal('details.php?pid="+$(this).attr("pid")+"','',720,390);\"></a>");
				$(this).removeClass("inactivePerson");
				$(this).animate({ opacity:1.0 }, 500);
			}
		}
		else
		{
			// strip 'a' tag from div
			$(this).html($(this).children("a").html());
			$(this).addClass("inactivePerson");
			$(this).animate({ opacity:0.4 }, 500);
		}
	});
}