
/*

Copyright (c) 2010 Jesse McCarthy <http://jessemccarthy.net/>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.

*/


$( document ).ready( function () {

  // Selectors for use by jQuery

  var nav_groups = [

    '#NLA_primary_nav .NLA_nav_link'

  ];
  // nav_groups


  var ng_index;


  // jQuery event : directory name

  var rollover_events = { 'mouseenter' : 'hover', 'mouseleave' : 'link' };


  var rollover_handler = function ( event ) {

    $( "img", this )[0].src = $( this ).data( 'rollover_urls' )[ event.type ];


    return;

  };
  // rollover_handler


  // Process nav groups

  for ( ng_index = 0 ; ng_index < nav_groups.length ; ++ng_index ) {

    // Process each nav link

    $( nav_groups[ ng_index ] ).each( function ( index ) {

      var image = $( this ).find( 'img' )[0];

      $( this ).data( 'rollover_urls', {

        'mouseleave' : image.src,

        // Replace the path segment for the directory that has the mouseleave images with the directory that has the mouseenter images

        'mouseenter' : image.src.replace(

          ( "/" + rollover_events[ 'mouseleave' ] + "/" ),

          ( "/" + rollover_events[ 'mouseenter' ] + "/" )

        )

      } );
      // $( this ).data


      // Preload mouseenter image

      document.createElement( 'img' ).src = $( this ).data( 'rollover_urls' )[ 'mouseenter' ];

    } );
    // $( nav_groups[ ng_index ] ).each


    // Attach event handler to each link for each rollover event

    for ( var rollover_event in rollover_events ) {

      // E.g. $( SELECTOR ).mouseenter( rollover_handler ) / $( SELECTOR ).mouseleave( rollover_handler )

      $( nav_groups[ ng_index ] )[ rollover_event ]( rollover_handler );

    }
    // for

  }
  // for nav_groups


  // Preload background images (used by CSS)

  var bg_images = [ 'first', 'default', 'last' ];

  for ( var bg_index = 0 ; bg_index < bg_images.length ; ++bg_index ) {

      document.createElement( 'img' ).src = ( "/inside/ui/standard/images/nav/primary/hover/backgrounds/" + bg_images[ bg_index ] + ".gif" );

  }
  // for


  return;

} );
// $( document ).ready(
