var ixfCache = new Array();

function fadeForward(imgName, fadeInt)
{
	if (!ixfCache[imgName])
	{
		ixfCache[imgName] = new ixfClass(imgName, fadeInt);
	} else {
		ixfCache[imgName].stopFade();
	}
	ixfCache[imgName].startFade(1);
}

function fadeBack(imgName)
{
	if (ixfCache[imgName])
	{
		ixfCache[imgName].stopFade();
		ixfCache[imgName].startFade(-1);
	}
}
function ixfStopFade()
{
	if (this.clock!=null)
	{
		clearInterval(this.clock);
		this.clock = null;
	}
}

function ixfStartFade(dir)
{
	this.dirStep = dir;
	this.clock = setInterval("ixfCache['"+this.imgName+"'].crossFade()", 13);
}

function ixfCrossFade() {
	var curOpacity = 0;
	switch(this.type)
	{
		case 'ie' :
			curOpacity = this.sImg.filters.alpha.opacity / 100;
			break;
			
		case 'khtml' :
			curOpacity = this.sImg.style.KhtmlOpacity;
			break;
			
		case 'moz' : 
			curOpacity = this.sImg.style.MozOpacity;
			break;
			
		default : 
			curOpacity = this.sImg.style.opacity;
	}

	if (typeof curOpacity == 'undefined')
	{
		curOpacity = 0;
	}
	curOpacity = curOpacity*1 + this.dirStep * this.dStep;
	if (curOpacity >= 1)
	{
		curOpacity = 1;
	} else if (curOpacity <= 0) {
		curOpacity =0
	}
	if(curOpacity==0 || curOpacity==1)
	{
		this.stopFade();		
	}
	switch(this.type)
	{
		case 'ie' :
			
			this.sImg.filters.alpha.opacity = curOpacity * 100;
			break;
			
		case 'khtml' :
			this.sImg.style.KhtmlOpacity = curOpacity;
			break;
			
		case 'moz' : 
			this.sImg.style.MozOpacity = curOpacity;
			break;
			
		default : 
			this.sImg.style.opacity = curOpacity;
	}
}

function ixfClass(imgName, fadeInt)
{
	this.imgName = imgName;
	this.fImg = document.getElementsByName(imgName)[0];
	this.sImg = document.getElementsByName(imgName+"_sec")[0];
	if(typeof this.fImg.style.opacity != 'undefined')
	{
		this.type = 'w3c';
	}
	else if(typeof this.fImg.style.MozOpacity != 'undefined')
	{
		this.type = 'moz';
	}
	else if(typeof this.fImg.style.KhtmlOpacity != 'undefined')
	{
		this.type = 'khtml';
	}
	else if(typeof this.fImg.filters == 'object')
	{
		this.type = (this.fImg.filters.length > 0 && typeof this.fImg.filters.alpha == 'object' && typeof this.fImg.filters.alpha.opacity == 'number') ? 'ie' : 'none';
	}
	else
	{
		this.type = 'none';
	}
	switch(this.type)
	{
		case 'ie' :
			this.sImg.filters.alpha.opacity = 0;
			break;
			
		case 'khtml' :
			this.sImg.style.KhtmlOpacity = 0;
			break;
			
		case 'moz' : 
			this.sImg.style.MozOpacity = 0;
			break;
			
		default : 
			this.sImg.style.opacity = 0;
	}

	this.sImg.style.left = getRealPosition(this.fImg, 'x') + 'px';
	this.sImg.style.top = getRealPosition(this.fImg, 'y') + 'px';
	this.sImg.style.display = 'block';


	this.stopFade = ixfStopFade;
	this.startFade = ixfStartFade;
	this.crossFade = ixfCrossFade;

	this.dStep = 1/(20*fadeInt);
	this.dirStep = 1;
	this.fadeInt = fadeInt;

}
function getRealPosition(oImg, xType)
{
	var pos = (xType == 'x') ? oImg.offsetLeft : oImg.offsetTop;
	var tmp = oImg.offsetParent;
	while(tmp != null)
	{
		pos += (xType == 'x') ? tmp.offsetLeft : tmp.offsetTop;
		tmp = tmp.offsetParent;
	}
	
	return pos;
};

