// --------------------------------------------------------
// 
// --------------------------------------------------------
$(document).ready(
	function ()
	{
		initNav();
		
		initSearch();
		
		toggle();
		/*toggleAbstract();*/
		
	}
);

// ------------------------------------------------------------
// 
// ------------------------------------------------------------
function initSearch ()
{
	var formEl = $("#search");
	
	var inputEl = $("input.text", formEl);
	
	inputEl.focus(
		function ()
		{
			if ($(this).val() == $(this).attr("defaultvalue"))
			{
				$(this).val("");
			};
		}
	);

	inputEl.blur(
		function ()
		{
			if ($(this).val() == "")
			{
				$(this).val($(this).attr("defaultvalue"));
			};
		}
	);
	
	inputEl.val(inputEl.attr("defaultvalue"));
	
	$("a.submit", formEl).click(
		function ()
		{
			$("#search").submit();
			
			return false;
		}
	);
};

// ------------------------------------------------------------
// 
// ------------------------------------------------------------
function initNav ()
{
	/* top level nav items */
	$("#nav-main a.main").click(
		function ()
		{
			$(this).parent().toggleClass("expanded");
					
			return false;
		}
	);
	
	$("#nav-main a.main").each(
		function ()
		{
			this.onclick = function () { return false; };
		}
	);

	$("#nav-main a.main").focus(
		function ()
		{
			this.blur();
		}
	);
	
	/* second level nav items */
	/*
	$("#nav-main li li a").mouseover(
		function ()
		{
			setActiveSubNavItem($(this));
		}
	);

	$("#nav-main li li a").mouseout(
		function ()
		{
			$(this).parent().parent().parent().removeClass("tracking");
			$("li", $(this).parent().parent()).removeClass("tracking");
			$("li a", $(this).parent().parent()).removeClass("hover");
			
			// reset the active sub nav item
			initActiveSubNavItem();
		}
	);
	
	// set the active sub nav item
	initActiveSubNavItem();
	*/
};

/*
function initActiveSubNavItem ()
{
	$("#nav-main li.expanded li.active a").each(
		function ()
		{
			setActiveSubNavItem($(this));
		}
	);
};

function setActiveSubNavItem (el)
{
	$("li a", el.parent().parent()).removeClass("hover");
	el.parent().parent().parent().addClass("tracking");
	el.parent().parent().parent().addClass("active");
	$("li", el.parent().parent()).removeClass("tracking");
	el.parent().prevAll().addClass("tracking");
	
	// alert(el.parent().parent().parent().parent().html());
	
	el.addClass("hover");
};
*/


function toggle ()
{
var showText='Show Bio&nbsp;&raquo;';
var hideText='Hide Bio&nbsp;&raquo;';

// initialise the visibility check
var is_visible = false;

// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.toggleBio').prev().append(' <a href="#" class="toggleLink">'+showText+'</a>');

// hide all of the elements with a class of 'toggle'
$('.toggleBio').hide();

// capture clicks on the toggle links
$('a.toggleLink').click(
        function() 
		{

// switch visibility
is_visible = !is_visible;

// change the link depending on whether the element is shown or hidden
$(this).html( (!is_visible) ? showText : hideText);

// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next('.toggleBio').toggle();

// return false so any link destination is not followed
return false;	
		}
);
};

/*function toggleAbstract ()
{
var showText='Show Abstract<span>&raquo;</span>';
var hideText='Hide Abstract<span>&raquo;</span>';

// initialise the visibility check
var is_visible = false;

// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.toggleAbstract').prev().append(' <a href="#" class="toggleLink">'+showText+'</a>');

// hide all of the elements with a class of 'toggle'
$('.toggleAbstract').hide();

// capture clicks on the toggle links
$('a.toggleLink').click(
        function() 
		{

// switch visibility
is_visible = !is_visible;

// change the link depending on whether the element is shown or hidden
$(this).html( (!is_visible) ? showText : hideText);

// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next('.toggleAbstract').toggle();

// return false so any link destination is not followed
return false;	
		}
);
};*/



