/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*	Pops Media
*	Author: Linh.Tran
*	Description: Auto slide
*	Module: Tinipet game
*	Date started: 09/04/2010
*	Date updated: 
*	Module Version Number: 1.0.0
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
var wt_AutoSlide = Class.create();
wt_AutoSlide.prototype = {
gStart:0,
gTotalImg:0,
gHide:1,
gAutoPaging:1,
gPage:2,
gClick:0,
	initialize: function() 
	{
	},

	/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	* Author: Linh.Tran
	* Function Name: wt_AutoImage
	* Description: Thay doi hinh tu dong
	* Input: N/A
	* Output: N/A
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	wt_AutoImage: function()
	{
		if(this.gStart == 0) //Khoi tao ban dau
		{
			var eImage     = document.getElementById('imgList').getElementsByTagName('img');
			this.gTotalImg = eImage.length;
			this.gStart    = 1;
			
			t = setTimeout("wt_AutoSlide.prototype.wt_AutoImage()", 5000);
		}
		else
		{
			//Chan su kien click phan trang khi dang thay doi hinh
			this.gClick = 1;
			clearTimeout(t);
		
			if(this.gHide < this.gTotalImg) //Next image
			{
				var imgID = 'img_'+this.gHide;
				new Effect.Fade(imgID, { duration:1, afterFinish:this.wt_IsAction });
				
				this.wt_CircleSlide(this.gPage);
				
				this.gPage++;
				this.gHide++;
			}
			else //Back to first image
			{
				for(var i=1; i<this.gTotalImg; i++)
				{
					var id    = this.gTotalImg-i
					var imgID = 'img_'+id;
					
					if(i < this.gTotalImg-1)
					{
						new Effect.toggle(imgID, 'Appear', {duration:1});
					}
					else
					{
						new Effect.toggle(imgID, 'Appear', { duration:1, afterFinish:this.wt_IsAction });
					}
				}
				
				this.wt_CircleSlide(1);
				
				this.gPage = 2;
				this.gHide = 1;
			}
		}
	},
	
	/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	* Author: Linh.Tran
	* Function Name: wt_SlidePaging
	* Description: phan trang cua auto image
	* Input: @page
	* Output: N/A
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	wt_SlidePaging :function(page)
	{
		if(this.gClick == 1)
		{
			return;
		}
		
		this.gClick = 1;
		clearTimeout(t);
		
		this.wt_CircleSlide(page);
		
		if(page >= this.gPage) //Paging next
		{
			for(var i=1; i<page; i++)
			{
				var imgID = 'img_'+i;
				
				if(i < page-1)
				{
					new Effect.Fade(imgID, {duration:1});
				}
				else //Khi image thu (page-1) an di thi khoi tao chuc nang click chuot
				{
					new Effect.Fade(imgID, { duration:1, afterFinish:this.wt_IsAction });
				}
			}
			
			this.gPage = page;
			this.gHide = page-1;
			this.gPage = page;
		}
		else //paging prev
		{
			for(var i=1; i<=this.gPage-page; i++)
			{
				var id    = this.gPage-i;
				var imgID = 'img_'+id;
				
				if(i < this.gPage-page)
				{
					new Effect.toggle(imgID, 'Appear', {duration:1});
				}
				else //Khi image thu (this.gPage-page) an di thi khoi tao chuc nang click chuot
				{
					new Effect.toggle(imgID, 'Appear', { duration:1, afterFinish:this.wt_IsAction });
				}
			}
			
			this.gPage = page;
			this.gHide = page;
			this.gPage = page+1;
		}
	},
	
	/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	* Author: Linh.Tran
	* Function Name: wt_CircleSlide
	* Description: Hieu ung truot hinh tron
	* Input: @page
	* Output: N/A
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	wt_CircleSlide: function(page)
	{
		var total = (page - this.gAutoPaging)*20;
		
		new Effect.Move('circleImg',
		{
			x: total,
			duration:0.3
		})
	
		this.gAutoPaging = page;
	},
	
	/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	* Author: Linh.Tran
	* Function Name: wt_IsAction
	* Description: Khoi tao lai chuc nang click chuot
	* Input: N/A
	* Output: N/A
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	wt_IsAction:function()
	{
		wt_AutoSlide.prototype.gClick = 0;
		t = setTimeout("wt_AutoSlide.prototype.wt_AutoImage()", 5000);
	}
};
