document.r = setTimeout( "rotate()", 7000 );
document.done = 1;
function rotate()
{

	if( !document.id ) document.id = 1;
	switch( document.id )
	{
		case 1: document.id = 2; break;
		case 2: document.id = 3; break;
		case 3: document.id = 1; break;
	}
	
	DO("b" + document.id);
}
function mm(eid)
{
	if( document.r )
	{
		clearTimeout( document.r );
	}
	document.over = 1;
	DO(eid);
}
function mo()
{
	document.over = 0;
	if( document.done )
	{
		if( document.r ) clearTimeout( document.r );
		document.r = setTimeout( "rotate()", 7000 );
	}
}
function DO(eid)
{
	if( !document.cur )	document.cur = "b1";
	if( !document.arr )	document.arr = new Array();
	if( !document.arr2 ) document.arr2 = new Array();
	
	if( document.cur == eid ) return;
	document.arr.push( "bannerBar" );
	document.arr.push( "bannerBar" );
	document.cur = eid;
	document.id = Number(eid.replace("b",""));
	
	document.arr2.push( Op );
	document.arr2.push( Change );
	document.arr2.push( Op );
	
	if( document.done )
	{
		document.done = 0;
		Next();
	}
}

function Change()
{
	if( document.arr.length == 0 ) return;
	var id = document.arr.shift();
	document.arr.unshift(id);
	
	var o = document.getElementById( "bannerBar" );
	if( id == "bannerBar")
	{
		switch( document.id )
		{
			case 1:
				o.style.background = "url('/2010img/8bitEWeek_bg.png')";
				o.style.backgroundRepeat = "repeat-x";
				document.getElementById( "b1t" ).className = "selectedW";
				document.getElementById( "b2t" ).className = "";
				document.getElementById( "b3t" ).className = "";
				document.getElementById( "b1" ).style.display = "block";
				document.getElementById( "b2" ).style.display = "none";
				document.getElementById( "b3" ).style.display = "none";
				break;
			case 2:
				o.style.background = "url('/2010img/banner3_bg.png')";
				o.style.backgroundRepeat = "repeat-x";
				document.getElementById( "b1t" ).className = "";
				document.getElementById( "b2t" ).className = "selectedW";
				document.getElementById( "b3t" ).className = "";
				document.getElementById( "b1" ).style.display = "none";
				document.getElementById( "b2" ).style.display = "block";
				document.getElementById( "b3" ).style.display = "none";
				break;
			case 3:
				o.style.background = "url('/2010img/academicBanner_bg.png')";
				o.style.backgroundRepeat = "repeat-x";
				document.getElementById( "b1t" ).className = "";
				document.getElementById( "b2t" ).className = "";
				document.getElementById( "b3t" ).className = "selectedW";
				document.getElementById( "b1" ).style.display = "none";
				document.getElementById( "b2" ).style.display = "none";
				document.getElementById( "b3" ).style.display = "block";
				break;
		}
	}
	Next();
}
function Op()
{
	if( document.arr.length == 0 ) return;
	var id = document.arr.shift();
	fade( id, 300 );
}
function Next()
{
	if( document.arr2.length == 0 ) 
	{
		document.done = 1;
		if( !document.over ) 
		{
			if( document.r ) clearTimeout( document.r );
			document.r = setTimeout( "rotate()", 5000 );
		}
		return;
	}
	var fnc = document.arr2.shift();
	fnc();
}

function fade(eid, t)
{
	/*============================
	eid = element id
	t = time to perform fade
	o.s = fade state( 1 = go to 100, -1, go to 0 )
	===============================*/
	
	var o = document.getElementById(eid);
	if( !o ) return;
	
	o.setFade = setFade;
	o.startFade = startFade;
	o.endFade = endFade;
	
	if( o.style.display == "none" ) o.s = 1;
	else o.s = -1;

	o.t = t;
	o.startFade();
	document.t = setTimeout("animateFade('" + eid + "'," + new Date().getTime() + "," + t + ")", 33 );
}

function animateFade(eid,lt,t)
{
	/*============================
	eid = element id
	l = last tick
	t = time to perform fade
	o.s = fade state( 1 = go to 100, -1, go to 0 )
	===============================*/
	
	var o = document.getElementById(eid);
	if( !o ) return;
	
	var t1 = new Date().getTime();
	var et = t1 - lt;
	if( o.t <= et )
	{
		o.setFade( o.s == 1 ? 100 : 0 );
		o.endFade();
		Next();
		return;
	}	
	
	o.t -= et;
	var val = 100 * o.t / t;
	if( o.s == 1 )
		val = 100 - val;
		
	o.setFade( val );
	document.t = setTimeout("animateFade('" + eid + "'," + t1 + "," + t +")", 33 );
}

function startFade()
{
	if( this.style.display == "none" )
	{
		this.setFade( 0 );
		this.style.display = "block";
	}
}
function setFade(v)
{
	this.style.opacity = v/100;
	this.style.filter = "alpha(opacity="+v+")";
}
function endFade()
{
	if( this.s == -1 )
		this.style.display = "none";
}
function changeCSS(s,p,v) 
{
	if (!document.styleSheets) return;

	var id = 1;	
	var theRules = new Array();
	if (document.styleSheets[id].cssRules)
		theRules = document.styleSheets[id].cssRules
	else if (document.styleSheets[id].rules)
		theRules = document.styleSheets[id].rules
	else
		theRules = null;
	
	var changed = false;
	if( theRules )
	{
		for( var i = 0; i < theRules.length; i++ )
		{
			if( s == theRules[i].selectorText )
			{
				changed = true;
				theRules[i].style[p] = v;
				break;
			}
		}
	}
	if( !changed )
	{
		if( document.styleSheets[id].insertRule )
			document.styleSheets[id].insertRule(s+"{"+p+":"+v+"}",theRules.length);
		else if( document.styleSheets[id].addRule )
			document.styleSheets[id].addRule(s, p+":"+v);
	}
}

