﻿/*
Hover buttons plugin
v1.0 (27/11/2008)

Any image buttons with a class of "btnHover" will have hover button functionality assigned to them.
onmouseover, the image src will be appended with the "suffix" setting (default: "-hover");
onmouseout, the image src will be restored.

USAGE
-----
$("selector").hoverButtons();

SETTINGS
--------
suffix:    string (the suffix to attach to the filename, before the extension; defaults to "-hover")
extension: string (the file extension to use; defaults to "gif")
*/

jQuery.fn.hoverButtons = function(settings)
{
  // if the selector does not contain any elements, return the jQuery object
  if (this.length == 0) return this;
  
  // default settings
  var hb = new Object();
  hb.suffix = "-hover";
  hb.extension = "gif";
  
  // overwrite settings if supplied
  if (settings != undefined)
  {
    if (settings.suffix != undefined) hb.suffix = settings.suffix;
    if (settings.extension != undefined) hb.extension = settings.extension;
  } // if
  
  this.hover(
    function(){
      var hoverSource = $(this).attr("src").replace("." + hb.extension, hb.suffix + "." + hb.extension);
      if (!hoverSource.match(hb.suffix + hb.suffix)) $(this).attr("src", hoverSource);
    }, 
    function(){
      var hoverSource = $(this).attr("src").replace(hb.suffix + "." + hb.extension, "." + hb.extension);
      $(this).attr("src", hoverSource);
    }
  );
  
  // return the jQuery object
  return this;
} // $.hoverButtons()