/*

thame.js


JS functions for thame site


*/


var thame_headers = 1;
var thame_cur = 1;
var thame_prev = 1;
var thame_stage = 100;
var thame_to = null;
var thame_toScroll = null;



function thame_do(n)
{
	thame_headers = n;

	thame_toScroll = setTimeout("thame_next();", 5000);
}

function thame_next()
{
	if(thame_cur == thame_headers)
		thame_changeImage2(1);
	else
		thame_changeImage2(thame_cur + 1);

	thame_toScroll = setTimeout("thame_next();", 5000);
}


function thame_changeImage(n)
{
	clearTimeout(thame_toScroll);
	
	thame_changeImage2(n);
}


function thame_changeImage2(n)
{
	if(n > thame_headers || n < 1)
		return;

	if(thame_stage != 100)
		thame_finish();

	thame_start(n);
}


function thame_start(n)
{
	thame_prev = thame_cur;
	thame_cur = n;

	if(thame_prev == n)
		return;

	thame_stage = 0;

	b1 = document.getElementById('thame-header-buttons' + thame_cur);
	b2 = document.getElementById('thame-header-buttons' + thame_prev);

	b1.className = "thame-header-buttons-highlight";
	b2.className = "";

	o1 = document.getElementById('thame-header' + thame_cur);
	o2 = document.getElementById('thame-header' + thame_prev);

	o1.style.opacity = 0;
	o1.style.filter = "alpha(opacity=0)";
	o1.style.MozOpacity = 0;

	o1.style.zIndex = 100;
	o2.style.zIndex = 99;

	o1.style.visibility = "visible";

	
	thame_to = setTimeout("thame_fade();", 50);
}

function thame_fade()
{
	thame_stage += 10;
	if(thame_stage > 100)
		thame_stage = 100;

	o1 = document.getElementById('thame-header' + thame_cur);
	o2 = document.getElementById('thame-header' + thame_prev);

	o1.style.opacity = thame_stage / 100;
	o1.style.filter = "alpha(opacity=" + thame_stage + ")";
	o1.style.MozOpacity = thame_stage / 100;

	if(thame_stage == 100)
		o2.style.visibility = "hidden";
	else
		thame_to = setTimeout("thame_fade();", 50);
}


function thame_finish()
{
	thame_stage = 100;
	thame_fade();
	clearTimeout(thame_to);
}



