
/**
 * ロールオーバ処理
 * 
 * ※"_off"がデフォルトの画像
 *   "_on"がロールオーバ時の画像
 */
function smartRollover() {
  if(document.getElementsByTagName) {
    var images = document.getElementsByTagName("img");
    for(var i=0; i < images.length; i++) {
      if(images[i].getAttribute("src").match("_off.")) {
        images[i].onmouseover = function() {
          this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
        }
        images[i].onmouseout = function() {
          this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
        }
      }
    }
  }
}
if(window.addEventListener) {
    window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
    window.attachEvent("onload", smartRollover);
}

/**
 * テキストフィールドのフォーカス時に背景色を変更する
 *
 */
var colorful = new ColorfulInput;
colorful.skip = ['submit', 'reset', 'button'];	//ボタン類には配色しない
colorful.color['focus'] = '#333333';			//背景色指定

window.onload = function() {
  colorful.set();
}

function ColorfulInput() {
  this.skip  = [];
  this.color = { 'blur': '', 'focus': '#EEEEEE' };

  this.set = function() {
    for (var i = 0; i < document.forms.length; i++) {
      for (var f = 0; f < document.forms[i].length; f++) {
        var elm = document.forms[i][f];
        if(!this._checkSkip(elm)) continue;

        this._setColor(elm, 'focus');
        this._setColor(elm, 'blur');
      }       
    }
  }

  this._checkSkip = function(elm) {
    for(var i in this.skip) {
     if(elm.type == this.skip[i]) return false;
    }
    return true;
  }

  this._setColor = function(elm, type) { 
    var color = this.color[type];
    var event = function() { elm.style.backgroundColor = color; };

    if(elm.addEventListener) {
      elm.addEventListener(type, event, false); 
    } else if(elm.attachEvent) {
      elm.attachEvent('on'+type, event); 
    } else {
      elm['on'+type] = event;
    }
  }
}

