var ImageChanger = function(p_objParent, p_nWidth, p_nHeight, p_nSecond) {
	this.m_objParent = p_objParent;
	this.m_nWidth = p_nWidth;
	this.m_nHeight = p_nHeight;
	this.m_nSecond = p_nSecond * 1000;
	this.m_nTop = 0;
	this.m_nLeft = 0;
	this.m_nCurrent = 0;
	this.m_objCurrent = null;
	this.m_objNext = null;
	this.m_arrImage = new Array();
};

ImageChanger.prototype.loadImage = function(p_strPath) {
	this.m_arrImage[this.m_arrImage.length] = new Object();

	this.m_arrImage[this.m_arrImage.length - 1].strPath = p_strPath;
	this.m_arrImage[this.m_arrImage.length - 1].nTop = 0 - ((this.m_arrImage.length - 1) * this.m_nHeight);
	this.m_arrImage[this.m_arrImage.length - 1].nLeft = 0;
	this.m_arrImage[this.m_arrImage.length - 1].nCount = 0;
	this.m_arrImage[this.m_arrImage.length - 1].nIndex = this.m_arrImage.length - 1;
	this.m_arrImage[this.m_arrImage.length - 1].objTimer = null;

	this.m_arrImage[this.m_arrImage.length - 1].objPanel = document.createElement("DIV");
	this.m_objParent.appendChild(this.m_arrImage[this.m_arrImage.length - 1].objPanel);

//	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.position = "relative";
	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.position = "absolute";

	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.visibility = "visible";
//	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.top = this.m_arrImage[this.m_arrImage.length - 1].nTop.toString() + "px";
	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.top = "0px";


	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.left = this.m_arrImage[this.m_arrImage.length - 1].nLeft.toString() + "px";
	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.width = this.m_nWidth.toString() + "px";
	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.height = this.m_nHeight.toString() + "px";
//	this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.border = "green 1px solid";

	var f_nFilter = (this.m_arrImage.length == 1) ? 100 : 0;

	try {
		this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.filter = "Alpha(Opacity=" + f_nFilter.toString() + ")";
	} catch(E) {
	}

	try {
		this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.opacity = (0.01 * f_nFilter).toString();
	} catch(E) {
	}

	try {
		this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.mozOpacity = (0.01 * f_nFilter).toString();
	} catch(E) {
	}

	try {
		this.m_arrImage[this.m_arrImage.length - 1].objPanel.style.khtmlOpacity = (0.01 * f_nFilter).toString();
	} catch(E) {
	}


	this.m_arrImage[this.m_arrImage.length - 1].objImage = document.createElement("IMG");

	this.m_arrImage[this.m_arrImage.length - 1].objPanel.appendChild(this.m_arrImage[this.m_arrImage.length - 1].objImage);

	this.m_arrImage[this.m_arrImage.length - 1].objImage.src = this.m_arrImage[this.m_arrImage.length - 1].strPath;
	this.m_arrImage[this.m_arrImage.length - 1].objImage.style.width = this.m_nWidth.toString() + "px";
	this.m_arrImage[this.m_arrImage.length - 1].objImage.style.height = this.m_nHeight.toString() + "px";
};

ImageChanger.prototype.startRolling = function() {
	var _this = this;

	if(this.m_nCurrent > this.m_arrImage.length) {
		this.m_objCurrent = this.m_arrImage[this.m_nCurrent];
		this.m_objNext = this.m_arrImage[0];
	} else {
		this.m_objCurrent = this.m_arrImage[this.m_nCurrent];
		this.m_objNext = this.m_arrImage[this.m_nCurrent + 1];
	}

	window.setTimeout(function() {_this.timeoutRolling()}, this.m_nSecond);
};


ImageChanger.prototype.timeoutRolling = function() {
	var _this = this;
	this.m_objCurrent.objTimer = window.setInterval(function() {_this.intervalRolling()}, 60);
};


ImageChanger.prototype.intervalRolling = function() {
	var _this = this;

	// CURRENT
	try {
		this.m_objCurrent.objPanel.style.filter = "Alpha(Opacity=" + (100 - this.m_objCurrent.nCount * 4).toString() + ")";
	} catch(E) {
	}

	try {
		this.m_objCurrent.objPanel.style.opacity = (1.0 - this.m_objCurrent.nCount * 0.04).toString();
	} catch(E) {
	}

	try {
		this.m_objCurrent.objPanel.style.mozOpacity = (1.0 - this.m_objCurrent.nCount * 0.04).toString();
	} catch(E) {
	}

	try {
		this.m_objCurrent.objPanel.style.khtmlOpacity = (1.0 - this.m_objCurrent.nCount * 0.04).toString();
	} catch(E) {
	}

	// NEXT
	try {
		this.m_objNext.objPanel.style.filter = "Alpha(Opacity=" + (this.m_objCurrent.nCount * 4).toString() + ")";
	} catch(E) {
	}

	try {
		this.m_objNext.objPanel.style.opacity = (this.m_objCurrent.nCount * 0.04).toString();
	} catch(E) {
	}

	try {
		this.m_objNext.objPanel.style.mozOpacity = (this.m_objCurrent.nCount * 0.04).toString();
	} catch(E) {
	}

	try {
		this.m_objNext.objPanel.style.khtmlOpacity = (this.m_objCurrent.nCount * 0.04).toString();
	} catch(E) {
	}

	if(this.m_objCurrent.nCount >= 25) {
		window.clearInterval(this.m_objCurrent.objTimer);
		this.m_objCurrent.nCount = 0;

		this.m_objCurrent = this.m_objNext;
		this.m_nCurrent = this.m_objCurrent.nIndex;

		if(this.m_nCurrent >= (this.m_arrImage.length - 1)) {
			this.m_objNext = this.m_arrImage[0];
		} else {
			this.m_objNext = this.m_arrImage[this.m_objCurrent.nIndex + 1];
		}

		window.setTimeout(function() {_this.timeoutRolling()}, this.m_nSecond);
	} else {
		this.m_objCurrent.nCount ++;
	}
};