// JavaScript Document
// ---	run/assign jquery events after document is loaded
var domain 	= 'http://www.jofa.org';

$( document ).ready ( function () {
	// ---	hide the nav cover-up
	$( "#hide-lnav" ).css ( "display", "none" );
	// ---	if left nav exists, assign rollovers
	if ( $( "#left-nav" ).length ) {
		// ---	find the color way from <meta>
		var img_section 	= $( "meta[name='color-way']" ).attr ( "content" );
		if ( !img_section ) 	img_section = "index";
		var lnav_imgdir 	= domain +"/img/" +img_section +"/nav/";
		// ---	rollovers for left nav, about section
		$( ".lnav-about" ).mouseover (
			function () {
				var id 	= $( this ).attr ( "id" ).substr ( 5 );
				$( this ).attr ( "src", lnav_imgdir +"v2." +id +"_over.jpg" );
				$( "#about_" +id ).css ( "display", "block" );
			}
		);
		// ---	rollovers for left nav, social section (online library)
		$( ".lnav-social" ).mouseover (
			function () {
				var id 	= $( this ).attr ( "id" ).substr ( 5 );
				$( this ).attr ( "src", lnav_imgdir +"v2." +id +"_over.jpg" );
				$( "#social_" +id ).css ( "display", "block" );
			}
		);
		// ---	rollouts for flyout menus, tier 2
		$( ".menu_rout" ).mouseover (
			function () {
				// ---	get the parent div and turn it off
				var menu_id 	= $( this ).closest ( "div" ).attr ( "id" );
				$( "#" +menu_id ).css ( "display", "none" );
				// ---	reset the left nav button
				var lnav_id 	= menu_id.substr ( menu_id.indexOf ( "_" ) +1 );
				$( "#lnav-" +lnav_id ).attr ( "src", lnav_imgdir +"v2." +lnav_id +"_off.jpg" );
				// ---	hide third tier
				$( ".menu_layer3" ).css ( "display", "none" );
			}
		);
		// ---	rollouts for flyout menus, tier 3
		$( ".menu_rout3" ).mouseover (
			function () {
				// ---	get the parent div and turn it off
				var menu_id 	= $( this ).closest ( "div" ).attr ( "id" );
				$( "#" +menu_id ).css ( "display", "none" );
			}
		);
		// ---	rollovers for flyout menus, about section
		$( ".menu_td-about" ).hover (
			function () {
				$( this ).removeClass ( "menu_td-about" );
				$( this ).addClass ( "menu_td-about_on" );
				// ---	show the third tier child
				if ( $( this ).attr ( "id" ).substring ( 0, 3 ) == "t2-" ) {
					// ---	hide all third tier before showing 
					$( ".menu_layer3" ).css ( "display", "none" );
					var id 	= $( this ).attr ( "id" ).substr ( 3 );
					$( "#" +id ).css ( "display", "block" );
				}
			}, 
			function () {
				$( this ).removeClass ( "menu_td-about_on" );
				$( this ).addClass ( "menu_td-about" );
			}
		);
		// ---	rollovers for flyout menus, social section
		$( ".menu_td-social" ).hover (
			function () {
				$( this ).removeClass ( "menu_td-social" );
				$( this ).addClass ( "menu_td-social_on" );
				// ---	show the third tier child
				if ( $( this ).attr ( "id" ).substring ( 0, 3 ) == "t2-" ) {
					// ---	hide all third tier before showing 
					$( ".menu_layer3" ).css ( "display", "none" );
					var id 	= $( this ).attr ( "id" ).substr ( 3 );
					$( "#" +id ).css ( "display", "block" );
				}
			}, 
			function () {
				$( this ).removeClass ( "menu_td-social_on" );
				$( this ).addClass ( "menu_td-social" );
			}
		);
	} //endif
	
	// ---	if back to home link exists, assign rollovers
	if ( $( "#backhome_msg" ).length ) {
		$( "#area-backhome" ).hover (
			function () {
				$( "#backhome_msg" ).css ( "display", "block" );
			}, 
			function () {
				$( "#backhome_msg" ).css ( "display", "none" );
			}
		);
	} //endif
} );

