/*
**Description: Implements the auto fade of the index.jsp
**Author: Huangzhenzhong
**Date :2008-11-10
*/

function AutoFade(args)
{
	this.instance = args.instance;
	this.smallIcon = args.smallIcon;
	this.activeIconClass = args.activeIconClass;
	this.inactiveIconClass = args.inactiveIconClass;
	this.bigImage = args.bigImage;
	this.icons = document.getElementsByName(this.smallIcon);
	this.images = document.getElementsByName(this.bigImage);
	this.showedOne = 0;

	this.size = this.icons.length;
	for(var i=0;i<this.icons.length;i++)
	{
		this.icons[i].onmouseover = new Function(this.instance+".show("+i+",1)");
		this.icons[i].onmouseout = new Function(this.instance+".resume()");
		this.images[i].onmouseover = new Function(this.instance+".show("+this.instance+".showedOne)");
		this.images[i].onmouseout = new Function(this.instance+".resume()");
		if(this.showedOne!=i)
			this.images[i].display="none";
		else
			this.images[i].style.zIndex = parseInt(this.images[i].style.zIndex)+this.size; 
	}
	this.isPaused = false;
	this.start();
}

AutoFade.prototype.show=function(i)
{
	this.pause();
	this.icons[i].className = this.activeIconClass;
	for(var j=0;j<this.icons.length;j++) if(i!=j){ this.icons[j].className = this.inactiveIconClass;}
	if(this.showedOne == i)
	{
		if(parseInt(this.images[(this.showedOne+1)%this.size].style.zIndex)>parseInt(this.images[this.showedOne].style.zIndex))
		{
			this.images[this.showedOne].style.zIndex = parseInt(this.images[this.showedOne].style.zIndex)+this.size; 
			this.images[(this.showedOne+1)%this.size].style.zIndex = parseInt(this.images[i].style.zIndex)-this.size;
			this.images[(this.showedOne+1)%this.size].style.display="none"; 
			this.images[this.showedOne].style.display="block";
		}
	}
	else
	{
		this.images[this.showedOne].style.zIndex = parseInt(this.images[this.showedOne].style.zIndex)-this.size; 
		this.images[i].style.zIndex = parseInt(this.images[i].style.zIndex)+this.size; 
		this.images[this.showedOne].style.display="none"; 
		this.images[i].style.display="block";
		this.showedOne = i;
	}
	this.setOpacity(this.images[this.showedOne],1);
};
AutoFade.prototype.pause=function()
{
	this.isPaused = true;
};
AutoFade.prototype.resume=function()
{
	this.isPaused =false;
};

AutoFade.prototype.magicShow=function(i,opacity)
{
	if(this.isPaused) {window.setTimeout(this.instance+".magicShow(("+this.instance+".showedOne+1)%"+this.instance+".size"+","+1+")",3000);return;};
	this.setOpacity(this.images[this.showedOne],opacity);
	if(opacity==0)
		this.images[this.showedOne].style.display="none";
	this.setOpacity(this.images[i],1- opacity);
	if(this.images[i].style.display=="none")
		this.images[i].style.display = "block";
	if(Math.abs(opacity-0.5)<0.01)
	{
		this.images[this.showedOne].style.zIndex = parseInt(this.images[this.showedOne].style.zIndex)-this.size; 
		this.images[i].style.zIndex = parseInt(this.images[i].style.zIndex)+this.size; 
	}
	opacity=opacity-0.02;
	if(opacity>0)
		window.setTimeout(this.instance+".magicShow("+i+","+opacity+")",10);
	else
	{
		this.showedOne = i;
		for(var j=0;j<this.icons.length;j++) if(i!=j){ this.icons[j].className = this.inactiveIconClass;}
		this.icons[i].className = this.activeIconClass;
		window.setTimeout(this.instance+".magicShow(("+this.instance+".showedOne+1)%"+this.instance+".size"+","+1+")",3000);
	}
};
AutoFade.prototype.start=function()
{
	window.setTimeout(this.instance+".magicShow("+(this.showedOne+1)%this.size+","+1+")",3000);
};
AutoFade.prototype.setOpacity=function(element,opacity)
{
	try
	{
	element.style.opacity=opacity;
	element.style.filter = "alpha(opacity="+opacity*100+")";
	}catch(e){};
};
var last = 1;
function selectProductTab(which)
{
	var lastTab = $_("productTab_"+last);
	var lastBox = $_("productBox_"+last);
	
	var tab = $_("productTab_"+which);
	var box = $_("productBox_"+which);
	
	lastTab.className="";
	lastBox.style.display="none";
	
	if(which==2||which==4)
		tab.className="back02_af";
	else if(which==3)
		tab.className="back03_af";
	else
		tab.className="back01_af";
	
	box.style.display="block";
	last = which;
}

function switchCategory(which)
{
	if(which==1)
	{
		$_("ChinaStampCategoryTop").className="twotitle_open";
		$_("ChinaStampCategory").style.display="block";
		$_("ForeignStampCategoryTop").className="twotitle_off";
		$_("ForeignStampCategory").style.display="none";
	}
	else if(which==2)
	{
		$_("ChinaStampCategoryTop").className="twotitle_off";
		$_("ChinaStampCategory").style.display="none";
		$_("ForeignStampCategoryTop").className="twotitle_open";
		$_("ForeignStampCategory").style.display="block";
	}
	
}


