/**
 * Dateiname       : javascript/Rollover.js
 * Erzeugungsdatum : 27.08.2008
 * Autor           : CK
 * Version         : 1.0
 * Letzte Akt.     : 27.08.2008 (CK)
 * 
 * (c) Copyright SECRA GmbH
 */

/*global secra, Image, document */

var secra;
if(!secra){secra = {};}
else if(typeof secra!=="object"){throw new Error("secra ist kein Objekt!");}
if(secra.Rollover){throw new Error("secra.Rollover existiert bereits!");}

secra.Rollover = function(id) {
  this.id             = id;
  this.baseimagepath  = secra.Rollover.baseimagepath;
  this.postfix        = secra.Rollover.postfix;
  this.fileext        = secra.Rollover.fileext;
  if( (this.img = document.getElementById(this.id)) ) {
    this.image          = [];
    this.image[0]       = new Image();
    this.image[0].src   = this.img.src;
    this.image[1]       = new Image();
    this.image[1].src   = this.baseimagepath + this.id + this.postfix + this.fileext;

    if(this.image[1].complete) {
      this.addHandler();
    } else {
      this.image[1].onload = secra.assign(secra.Rollover.prototype.addHandler, this);
    }
  }
};
secra.Rollover.baseimagepath  = "/bitmaps/";
secra.Rollover.postfix        = "_hover";
secra.Rollover.fileext        = ".jpg";

secra.Rollover.prototype.addHandler = function() {
  this.img.onmouseover  = secra.assign(secra.Rollover.prototype.over, this);
  this.img.onmouseout   = secra.assign(secra.Rollover.prototype.out, this);
};

secra.Rollover.prototype.over = function() {
  this.img.src = this.image[1].src;
};

secra.Rollover.prototype.out = function() {
  this.img.src = this.image[0].src;
};

secra.assign = function(method, obj, args) {
  return function() {
    method.apply(obj, args = args || []);
  }
};

