/*
---------------------------------------------------------
	bundle.js ver 1.0 [2008/8/20] 
	*http://higash.net/20080820/bundljs.html
---------------------------------------------------------
*/

/*
---------------------------------------------------------
	smartRollover
	*Modify smartRollover.js
	*http://css-happylife.com/log/javascript/000157.shtml
---------------------------------------------------------
*/
function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
	        var preImages = new Array();

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off.")) {
				var preImage = new Image();
				preImage.src = images[i].getAttribute("src").replace("_off.", "_on.");
				preImages.push(preImage);
				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."));
				}
			}
		}
	}
}

/*
---------------------------------------------------------
	inputColorInit
	*Modify colorful.js
	*http://espion.just-size.jp/archives/05/231211111.html
---------------------------------------------------------
*/
var colorful = new ColorfulInput;
var inputColorInit = function() {
   colorful.set();
}
function ColorfulInput() {
  this.skip  = ['button','checkbox','radio','search','submit'];
  this.skip_id = ['s'];
  this.color = { 'blur': '', 'focus': '#dcf7c1' };
  this.set = function() {
    var i;
    for (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) {
    var i;
    for(i in this.skip) {
      if(elm.type == this.skip[i]) return false;
    }
    for(i in this.skip_id) {
      if(elm.id == this.skip_id[i]) return false;
    }
    return true;
  };
  this._setColor = function(elm, type) { 
    var i;
    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;
    }
  };
}

/*
---------------------------------------------------------
	Auto-striped table
	*Modify http://www.wellstyled.com/files/css-striped-tables/example02.html
	*http://www.wellstyled.com/css-striped-tables.html
---------------------------------------------------------
*/
function init() {
	stripeAllTables();
//	stripeTableById('#');
	}
function stripeTable(t) {
	var i, odd = true;
	for (i=0; i<t.rows.length; i++) {
		t.rows[i].className += odd ? ' odd' : ' even';
		odd = !odd;
		}
	}
function stripeTableById(id) {
	var t = document.getElementById(id);
	if (t) stripeTable(t);
	}
function stripeAllTables() {
	var t = document.getElementsByTagName('TABLE');
	for (var i=0; i<t.length; i++) stripeTable(t[i])
	}



/*
---------------------------------------------------------
	addLoadEvent
---------------------------------------------------------
*/
function addOnLoadEvent(func) {
	if (window.attachEvent){
		window.attachEvent('onload', func);
	}
	else {
		window.addEventListener('load', func, false);
	}
}
addOnLoadEvent(smartRollover);
addOnLoadEvent(inputColorInit);
addOnLoadEvent(stripeAllTables);
