//  Author: Christopher W. Baran
//
//  Written: December 10, 2008
//
//  Global Mouse Over Script
//  Based on jQuery


$(document).ready(function() {

  // *************** Button Mouse Over Swapping *******************
  // Any img tags on the page with src names that contain _off.
  //  will mouse over to the same base name _ovr.
  $('[src*="_off."]').not('[src*="_shared"]').each(function() {
    // Preload Images
    jQuery("<img>").attr("src", $(this).attr('src').replace( /(.*?)_off(\..*)/, '$1_ovr$2' ) );

    $(this).hover(function () {
			adjacent_left_image = $(this).parent().prev("img").filter('[src*="_shared"]');
      adjacent_right_image = $(this).parent().next("img").filter('[src*="_shared"]');
			
      if (adjacent_left_image.length == 1) {
				jQuery("<img>").attr('src', adjacent_left_image.attr('src').replace(/(.*?)_off(\..*)/, '$1_ovr$2'));
	  	  adjacent_left_image.attr('src', adjacent_left_image.attr('src').replace(/(.*?)_off(\..*)/, '$1_ovr$2'));
	    }
				
      $(this).attr('src', $(this).attr('src').replace(/(.*?)_off(\..*)/, '$1_ovr$2'));
			
      if (adjacent_right_image.length == 1) {
				jQuery("<img>").attr('src', adjacent_right_image.attr('src').replace(/(.*?)_off(\..*)/, '$1_ovr$2'));
	  	  adjacent_right_image.attr('src', adjacent_right_image.attr('src').replace(/(.*?)_off(\..*)/, '$1_ovr$2'));
	    }
    },
    function () {
      if (adjacent_left_image.length == 1) 
        adjacent_left_image.attr('src', adjacent_left_image.attr('src').replace(/(.*?)_ovr(\..*)/, '$1_off$2'));
				
      $(this).attr('src', $(this).attr('src').replace(/(.*?)_ovr(\..*)/, '$1_off$2'));
			
      if (adjacent_right_image.length == 1) 
        adjacent_right_image.attr('src', adjacent_right_image.attr('src').replace(/(.*?)_ovr(\..*)/, '$1_off$2'));
    });
  });

});

