// thezonie.js

function PreLoadImages()
{
	img=new Image();
	img.src='mail_focus.gif';
}

// Blur and Focus opacity constants (0-100)
var blur_opacity=10;
var focus_opacity=50;
var opacity_step=5;	// all opacity goals must be a multiple of the step
var opacity_timer=35;	// ms

// The id class
function cid(id,opacity/*,timer*/)
{
	this.id=id;
	this.opacity=opacity;
//	this.timer=timer;
}

var ids=new Array();
var timer=null;

//
// The id is the object, and the op is the opacity that we want that object to get to
//
function Animate(id,op)
{
	// First reset the op
	if(op == 'blur')
	{
		op=blur_opacity;
	}
	else if(op == 'focus')
	{
		op=focus_opacity;
	}
	else if(op == 'super_focus')
	{
		op=100;
	}

	// First, try and find this object in the array and set the goal opacity
	var i=0;
	var found=false;
	for(i=0;i<ids.length;i++)
	{
		if(ids[i].id == id)
		{
			found=true;
			ids[i].opacity=op;
			break;
		}
	}

	// If we didn't find it, then add it
	if(found == false)
	{
		nid=new cid(id,op/*,null*/);
		ids[i]=nid;
		document.getElementById(id).style.opacity=blur_opacity/100;	// KLUDGE
	}

	// Call the timer function which actually does the animation
//	OnTimer();
	if(timer == null)
	{
		timer=setTimeout('OnTimer();',opacity_timer);
	}
}

//
//
//
function OnTimer()
{
	// If the timer is set, clear it
	if(timer != null)
	{
		clearTimeout(timer);
		timer=null;
	}

	// See if we need to change the opacity and restart the timer by checking all the current and goal opacities of all the objects in the array.
	var at_goal=true;
	for(i=0;i<ids.length;i++)
	{
		// Get the object's current opacity
		var id=ids[i].id;
		op=document.getElementById(id).style.opacity * 100;
		
		if(op > ids[i].opacity)
		{
			at_goal=false;
			op -= opacity_step;
			op=Math.floor(op);
			document.getElementById(id).style.opacity=op/100;
			document.getElementById(id).style.filter='alpha(opacity='+op+')';
		}
		else if(op < ids[i].opacity)
		{
			at_goal=false;
			op += opacity_step;
			op=Math.floor(op);
			document.getElementById(id).style.opacity=op/100;
			document.getElementById(id).style.filter='alpha(opacity='+op+')';
		}
	}

	// If we are not at goal, restart the timer
	if(at_goal == false)
	{
		timer=setTimeout('OnTimer();',opacity_timer);
	}
}