/**
 *  author:		Timothy Groves - http://www.brandspankingnew.net
 *	version:	1.3 - 2006-11-02
 *				1.2 - 2006-11-01
 *				1.1 - 2006-09-29
 *				1.0 - 2006-09-25
 *
 *	requires:	nothing
 *
 *				DH 4-12-06
 *				change to smoothTransition (between two divs)
 */

var useBSNns;

if (useBSNns)
{
	if (typeof(bsn) == "undefined")
		bsn = {}
	var _bsn = bsn;
}
else
{
	var _bsn = this;
}

_bsn.SmoothTransition = function (div1, div2, fadetime) {	
	// fade from div1 to div2
	// this.nAct = -1;
	// this.aDivs = divs;
	if (div1==div2)
		return;
	debug ("smooth transition", 1);
	this.div1 = document.getElementById(div1);
	this.div2 = document.getElementById(div2);
	this.div2.style.opacity = 0;		// make new element transparent
	this.div2.style.filter = "alpha(opacity=0)";
	this.div2.style.visibility = "visible";
	this.nDur = fadetime;
		
	this.nInt = 50;
	this.nTime = 0;
	var p=this;
	this.nID2 = setInterval(function() { p._fade() }, this.nInt);
}

_bsn.SmoothTransition.prototype._fade = function() {
	this.nTime += this.nInt;
	
	var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
	var op = ieop / 100;
	debug (ieop + " ");
	
	this.div2.style.opacity = op;
	this.div2.style.filter = "alpha(opacity="+ieop+")";

	this.div1.style.opacity = 1 - op;
	this.div1.style.filter = "alpha(opacity="+(100 - ieop)+")";
	
	if (this.nTime == this.nDur) {	// reached the end, so stop
		this.div2.style.filter = "";
		clearInterval( this.nID2 );
		debug ("", 1);
		// this.div1.style.visibility = "hidden";
	}
}

_bsn.SmoothTransition.prototype._easeInOut = function(t,b,c,d) {
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}

