// *****************************************************************************

// ** ファイル名：rollover.js

// ** 製作者：多川

// ** 概　要：画像のロールオーバー処理（prototype依存）

// ** 制作日：20070220

// ** 更新日：20070422

// *****************************************************************************



var RollOverImage = Class.create();

RollOverImage.prototype = {

	initialize: function (img){

		this.image = $(img);

		// NoImage

		if (this.image != null) {

			this.originalPath = this.image.src;

			if(arguments[1]) {

				// CurrentdirImage

				if (arguments[2]) {

					var currentdirFlag = false;

					currentdirId = arguments[2].split(" ");

					for (var i = 0; i < currentdirId.length; i ++) {

						if ($(currentdirId[i])) {

							this.image.src = arguments[1];

							currentdirFlag = true;

						}

					}

					if (currentdirFlag == false) {

						this.setMouseDownImage(arguments[1]);		

					}

				} else {

					this.setMouseDownImage(arguments[1]);	

				}

			}

		}

	},

	setMouseDownImage: function (path){

		// DownImage

		this.mouseDownImage = new Image();

		this.mouseDownImage.src = path;

		this.image.onmousedown = this.mousedown.bind(this);

		this.image.onmouseup = this.reversion.bind(this);

		// OverImage

		this.mouseOverImage = new Image();

		this.mouseOverImage.src = path;

		this.image.onmouseover = this.rollover.bind(this);

		this.image.onmouseout = this.reversion.bind(this);

		// ActiveImage

		this.image.onclick = this.rollover.bind(this);

	},

	rollover: function (){

		this.image.src = this.mouseOverImage.src;

	},

	mousedown: function (){

		this.image.src = this.mouseDownImage.src;

	},

	reversion: function (){

		this.image.src = this.originalPath;

	}

};
