/**
 * Thienminh.com :: The Show network pro
 * Javascript Class
 * 
 * @package    Thienminh.com
 * @author     banhthidiem <banhthidiem@gmail.com>
 * @copyright  2007 Bach Khoa Computer Inc.
 * @version    $Id: ChangeImages.js, v1.0 2007/04/05
 */

function ChangeImages()
{
	this.imgList = null;
	this.imgObj = null;
	this.curNum = 0;
	this.name = "";
	this.oTimeOut = null;
	this.TOSecond = 5000;
	this.transitionNum = 0;
}

ChangeImages.prototype.Init = function (displayName, imgSrc, newList, w, h, autoRun, name)
{
	DetectEnvironment.detect();
	this.imgObj = document.createElement("IMG");
	this.imgObj.name = "imgAdvert";
	this.imgObj.src = imgSrc;
	this.imgObj.width = w;
	this.imgObj.height = h;
	this.imgObj.border = 0;
	if (DetectEnvironment.isIE())
	{
		this.imgObj.style.filter = "blendTrans(duration=0.9)";
	}
	document.getElementById(displayName).appendChild(this.imgObj);
	this.CreateImgList(newList, w, h);
	this.imgObj.url = this.imgList[0][2];
	this.name = name;
	addEvent(this.imgObj, "click", function (evt)
	{
		var el = getTargetElement(evt);
		if (el.url)
		{
			if (el.url != "")
				window.open(el.url);
		}
		else
			return;	
	});
	if (autoRun)
		this.AutoChangeImg();
}

ChangeImages.prototype.ChangeAffect = function (newImg)
{
	if (this.imgObj) 
	{
		if (DetectEnvironment.isIE()) 
		{
			this.imgObj.filters.blendTrans.Stop();
			this.imgObj.filters.blendTrans.Apply();
			this.imgObj.src = newImg.src;
			this.imgObj.filters.blendTrans.Play();
		}
		else
			this.imgObj.src = newImg.src;
	}
}

ChangeImages.prototype.ChangeImg = function ()
{
	var newImg = this.imgList[this.curNum][0];	
	this.ChangeAffect(newImg);
	if (this.imgObj)
	{
		this.imgObj.title = this.imgList[this.curNum][1];
		if (this.imgList[this.curNum][2] != "")
		{
			this.imgObj.url = this.imgList[this.curNum][2];
			this.imgObj.style.cursor = "pointer";
		}
		else
		{
			this.imgObj.url = "";
			this.imgObj.style.cursor = "default";
		}
	}
	if ((this.imgList.length - 1) > this.curNum)
		this.curNum += 1;
	else
		this.curNum = 0;
}

ChangeImages.prototype.CreateImgList = function (newList, w, h)
{
	for (var i = 0, x; i < newList.length; i++) 
	{
		x = newList[i][0];
		newList[i][0] = new Image(w, h);
		newList[i][0].src = x;
	}
	this.imgList = newList;
}

ChangeImages.prototype.AutoChangeImg = function ()
{
	this.ChangeImg();
	this.oTimeOut = setTimeout(this.name + ".AutoChangeImg()", this.TOSecond);
}