/* bool JPRK_add_event_listener() -- Attach an event listener to an object object element -- The object to attach the listener to string event_type -- The name of the event type (e.g. click, mouseover) string listener -- Name of the listener function bool useCapture -- useCapture parameter to addEventListener */ function JPRK_add_event_listener( element, event_type, listener, useCapture ) { var return_value = false; // The UA supports it, so use the DOM method if ( element.addEventListener ) { element.addEventListener( event_type, window[ listener ], useCapture ); return_value = true; } // end if // Use the traditional method else { element[ "on" + event_type.toLowerCase() ] = window[ listener ]; return_value = true; } // end else return return_value; } // end JPRK_add_event_listener /* void JPRK_preload_rollovers() -- Preload images for navigation elements that have a rollover effect */ function JPRK_preload_rollovers() { var rollover_states = new Array( 'hover', 'link' ); var image_file_basename; var matches; var current_nav_link; var navbar_images_URL = window.navbar_images_URL; var nav_link_sets = new Array( "JPRK_primary_nav", "JPRK_language_links" ); // Array of all navigation elements that need preloading for a rollover effect var all_nav_links = new Array(); var nav_links; // Loop through each set of navigation elements for ( nls_index = 0 ; nls_index < nav_link_sets.length ; ++nls_index ) { nav_links = document.getElementById( nav_link_sets[ nls_index ] ).getElementsByTagName( 'a' ); // Loop through each 'a' element in the current set of navigation elements for ( nl_index = 0 ; nl_index < nav_links.length ; ++nl_index ) { current_nav_link = nav_links[ nl_index ]; // Add the current nav link to the array of elements requiring image preloading, if appropriate if ( current_nav_link.getAttribute( 'id' ).match( /JPRK_nav_link_(.+)/ ) ) { all_nav_links.push( current_nav_link ); } // end if } // end for } // end for if ( ! all_nav_links.length ) { return; } // end if // Loop through elements requiring image preloading for ( anl_index = 0 ; anl_index < all_nav_links.length ; ++anl_index ) { current_nav_link = all_nav_links[ anl_index ]; // Extract the unique identifier for the navigation element from the HTML ID matches = current_nav_link.getAttribute( 'id' ).match( /JPRK_nav_link_(.+)/ ); nav_link_ID = matches[1]; JPRK_add_event_listener( current_nav_link, 'mouseover', "JPRK_nav_roll", false ); JPRK_add_event_listener( current_nav_link, 'mouseout', "JPRK_nav_roll", false ); if ( nav_link_ID.indexOf( ':' ) ) { image_file_basename = nav_link_ID.substr( nav_link_ID.lastIndexOf( ':' ) + 1 ); } // end if else { image_file_basename = nav_link_ID; } // end else // Preload the image associated with each state a navigation element can take for ( rs_index = 0 ; rs_index < rollover_states.length ; ++rs_index ) { window[ ( "JPRK_nav_link_" + nav_link_ID + "_" + rollover_states[ rs_index ] ) ] = new Image(); window[ ( "JPRK_nav_link_" + nav_link_ID + "_" + rollover_states[ rs_index ] ) ].src = navbar_images_URL + rollover_states[ rs_index ] + "/" + image_file_basename + ".gif"; } // end for } // end for return; } // end JPRK_preload_rollovers /* void JPRK_nav_roll() -- Implement a rollover effect on a navigation element object event -- The event object generated by the UA in response to user action */ function JPRK_nav_roll( event ) { // Normalize the event object for cross-browser purposes event = ( event ? event : window.event ); var new_state; var matches = event.type.match( /mouse(.+)/ ); // Map DOM event type names (mouseover, mouseout) to CSS style names (hover, link) if ( matches[1] == 'over' ) { new_state = 'hover'; } // end if else if ( matches[1] == 'out' ) { new_state = 'link'; } // end else if // Extract the unique identifier of the element from the HTML ID matches = this.getAttribute( 'id' ).match( /JPRK_nav_link_(.+)/ ); nav_link_ID = matches[1]; nav_link_ID = nav_link_ID.toLowerCase(); var class_names = ( this.getAttribute( 'class' ) ? this.getAttribute( 'class' ) : this.getAttribute( 'className' ) ); // If the navigation element the user is acting upon corresponds to the section that the current page belongs to, stop processing if ( class_names.match( /(^| )(JPRK_current_site_section|JPRK_current_language)( |$)/ ) ) { return; } // end if if ( document.getElementById( 'JPRK_nav_link_' + nav_link_ID ) ) { // Change the source of the image that is the content of the navigation element the user is acting upon to the source of the image corresponding to the new state of the element document.getElementById( 'JPRK_nav_link_' + nav_link_ID ).firstChild.src = window[ 'JPRK_nav_link_' + nav_link_ID + "_" + new_state ].src; } // end if return; } // end JPRK_nav_roll /* void JPRK_loading_complete() -- Onload handler */ function JPRK_loading_complete() { // Execute specific onload logic for the current page if defined if ( window.loading_complete ) { window.loading_complete(); } // end if if ( ! window.navbar_images_URL ) { window.navbar_images_URL = "/images/english/ui/navigation/"; } // end if window.JPRK_preload_rollovers(); return; } // end JPRK_loading_complete JPRK_add_event_listener( window, "load", "JPRK_loading_complete", false );