/**
 * Javascript Class
 * 
 * @package    bkc.vn
 * @author     banhthidiem <banhthidiem@gmail.com>
 * @copyright  2007 Bach Khoa Computer Inc.
 * @version    $Id: ChangeImages.js, v1.0 2007/04/05
 */

function ChangeImages(newList, w, h, name, transitionList, util)
{
	this.imgList = newList;
	this.oImg = null;
	this.w = w;
	this.h = h;
	this.curNum = 0;
	this.myName = name;
	this.oTimeOut = null;
	this.TOSecond = 5000;
	this.transitionNum = 0;
	this.transitionList = transitionList;
	this.util = util;
};

ChangeImages.prototype.createMain = function ()
{
	this.createImgList();
	this.oImg = this.createObjectImg();
	this.oHeader = this.oImg;
	this.oOut = this.oImg;
	this.oImg.url = this.imgList[0][2];
	if (this.util.isIE )
	{
		this.oImg.style.filter = "revealTrans(duration=1.5, transition=" + this.autoChangeTransition() + ")";
	}
	var self = this;
	this.util.addEvent(self.oImg, "click", function ()
	{
		if (self.oImg.url)
		{
			if (self.oImg.url != "")
				self.util.wd.open(self.oImg.url);
		}
		else
			return;	
	});
	return this.oImg;
};

ChangeImages.prototype.autoChangeTransition = function ()
{
	if (this.transitionList.length - 1 > this.transitionNum)
	{
		this.transitionNum += 1;
	}
	else
	{
		this.transitionNum = 0;
	}
	return this.transitionList[this.transitionNum];
};

ChangeImages.prototype.changeAffect = function (newImg)
{
	try
	{
		if (this.util.isIE && this.util.appVersion >= 6) 
		{
			this.oImg.filters.revealTrans.Stop();
			this.oImg.filters.revealTrans.transition = this.autoChangeTransition();
			this.oImg.filters.revealTrans.Apply();
			this.oImg.src = newImg.src;
			this.oImg.filters.revealTrans.Play();
		}
		else
			this.oImg.src = newImg.src;
		
	}
	catch (e)
	{ }
};

ChangeImages.prototype.changeImg = function ()
{
	var newImg = this.imgList[this.curNum][0];	
	this.changeAffect(newImg);
	if (this.oImg)
	{
		this.oImg.title = this.imgList[this.curNum][1];
		if (this.imgList[this.curNum][2] != "")
		{
			this.oImg.url = this.imgList[this.curNum][2];
			if (this.util.isIE)
			{
				if (this.util.appVersion >= 6) this.oImg.style.cursor = "pointer";
			}
			else this.oImg.style.cursor = "pointer";
		}
		else
		{
			this.oImg.url = "";
			if (this.util.isIE)
			{
				if (this.util.appVersion >= 6) this.oImg.style.cursor = "default";
			}
			else this.oImg.style.cursor = "default";
		}
	}
	if ((this.imgList.length - 1) > this.curNum)
		this.curNum += 1;
	else
		this.curNum = 0;
};

ChangeImages.prototype.createImgList = function ()
{
	var newList = this.imgList;
	for (var i = 0, x; i < newList.length; i++) 
	{
		x = newList[i][0];
		newList[i][0] = new Image(this.w, this.h);
		newList[i][0].src = x;
	}
	this.imgList = newList;
};

ChangeImages.prototype.createObjectImg = function ()
{
	var oImg = new Image(this.w, this.h);
	oImg.name = this.myName;
	oImg.id = this.myName;
	oImg.className = "box_content_0";
	oImg.border = 0;
	return oImg;
};

ChangeImages.prototype.autoChangeImg = function ()
{
	this.changeImg();
	this.oTimeOut = setTimeout(this.myName + ".autoChangeImg()", this.TOSecond);
};

function CreateFlashAdvert(myName, w, h, src)
{
	this.myName = myName;
	this.w = w;
	this.h = h;
	this.src = src;
	this.u = utilObj;
};

CreateFlashAdvert.prototype.createMain = function()
{
	var o = this.u.createEl("DIV");
	
	o.id = this.myName;
	var swfNode = '<object id="' + this.myName + 'FlashContainer" style="margin: 0px; padding: 0px;" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.w + '" height="' + this.h + '">';
	swfNode += '<param name="movie" value="'+ this.src +'" />';
	swfNode += '<param name="wmode" value="transparent" />';
	swfNode += '<embed width="' + this.w + '" height="' + this.h + '" id="' + this.myName + 'Flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" wmode="transparent" type="application/x-shockwave-flash" style="margin: 0px; padding: 0px;" scale="noscale" wmode="opaque" quality="high" menu="false" src="'+ this.src +'"/>';
	swfNode += "</object>";
	o.style.width = this.w + "px";
	o.style.height = this.h + "px";
	o.className = "box_content_0";
	o.innerHTML = swfNode;
	this.oHeader = o;
	return o;
};

CreateFlashAdvert.prototype.createEMBED = function()
{
	var o = this.u.createEl("EMBED");
	o.id = this.myName;
	o.width = this.w;
	o.height = this.h;
	o.className = "box_content_0";
	o.type = "application/x-shockwave-flash";
	o.quality = "high";
	o.scale = "noscale";
	o.wMode = "opaque";
	o.menu = "false";
	o.wmode = "transparent";
	o.pluginSpage = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
	o.src = this.src;
	this.oHeader = o;
	return o;
};