/*
 * IMS javascript library.
 * Requires prototype.
 * @author Chris Lewis <clewis@ims-marketing.com> Fri Feb 09 11:23:41 EST 2007
 */

/* Setup the IMS namespaces. */
var ims = {};
ims.ui = {}


/**
 * ImgSetSwapper makes it easy to automatically set up image rollovers
 * based on a class name. Create an instance and tell it the class name
 * and rollover image suffix, and it will handle the rest.
 */
ims.ui.ImgSetSwapper = Class.create();
ims.ui.ImgSetSwapper.prototype = {
  
  initialize: function(iClass, iSfx) {
    this._iClass = iClass;
    this._iSfx = iSfx;
    var imgs = document.getElementsByClassName(this._iClass);
    var that = this;
    imgs.each(
      function(_img) {
        Event.observe(_img, 'mouseover', function() { that.doSwap(_img, 'mouseover'); });
        Event.observe(_img, 'mouseout', function() { that.doSwap(_img, 'mouseout'); });
      }
    );
  },
  
  doSwap: function(img, eType) {
    var base = img.src.substring(0, img.src.lastIndexOf('.'));
    var ext = img.src.substring(img.src.lastIndexOf('.'));
    img.src = (eType == 'mouseover' ? base + this._iSfx : base.gsub(this._iSfx, '')) + ext;
  }
  
}
