/*
	Common custom javascript functions implemented for the site-wide
	template/look and feel.	
	
	Requires: jQuery 1.3.2+
*/

/*
	Add these functions to the list of functions called when
	the DOM is ready to be manipulated.
	
	Do not use $(document).ready() function because it only allows
	for one ready event handler; this *appends* our anonymous function
	to the list of ready event handlers.
*/
$(document).bind("ready", function() {
	// Construct the navigation drop-down menus 
	// (replaces "loadNav" function from original templates)
	menus();
})

function menus(){
	setupMenu("#about_menu_anchor","#about_menu");
	setupMenu("#help_menu_anchor","#help_menu");
	setupMenu("#account_menu_anchor", "#account_menu", true);
}

function setupMenu(nav, menu, rightAlign) {
	if( $(menu).size() > 0 && $(nav).size() > 0 ) {
		if(!rightAlign)
			$(menu).css("left",($(nav).position().left - 10) + "px");
		else
			$(menu).css("right", '-10px'); // a bit hackish; not based on position of nav
			
		$(menu).css("top",($(nav).position().top + 30) + "px");

		//Set up menu visibility hover
		$(nav).hover(
			 function() {
				 $(menu).css("visibility","visible");
			 },
			 function() {
				 $(menu).css("visibility","hidden");
			 }
		);
		
		$(menu).hover(
			 function() {
				 $(menu).css("visibility","visible");
				 $(nav).addClass("hover");
			 },
			 function() {
				 $(menu).css("visibility","hidden");
				 $(nav).removeClass("hover");
			 }
		);
	}
}

function setRollover(id,rollImage) {
	// Check to see if image should stay in rollover state by seeing if current 
	// image name contains the string "-over". If not, set up rollover.
	if( $(id).attr("src") && $(id).attr("src").search("_over") == -1) {
		$(id).hover(
			function() {
				$(id).attr("src",rollImage.src);
			},
			function() {
				$(id).attr("src",rollImage.src.replace('_over',''));
			}
		);
	}
}

/*
    Handle Guideline Note warning dialog. This can be removed
    when this not is no longer needed.
*/
jQuery( function($){
	$('#guideline_note .toggle_warning').click( function() { 
		$('#guideline_note .body').toggle();
		$(this).text( $(this).text() == "Hide" ? "Read More" : "Hide" );
	} );
} );

