var MAX_TICKS = 7;  	// The max number of ticks
var MIN_TICKS = 0;  	// The min number of ticks
var TICK_TIME = 50; 	// Milliseconds between ticks (ignoring render lag)
var currentTick = 0;	// The current number of ticks
var tickTimer;			// The timer for ticking (array)
var lock = -1;			// A lock for mouse over
var element;			// The current element

// Start the timer
function start(id) {
	if(element != document.getElementById(id) || currentTick == -1) {
		if(lock != -1) return; // Test for two open images
		element = document.getElementById(id);
		currentTick = 0;
		lock = -1;
	}
	stop(); // Clear any outstanding timers
	lock = lock * -1; // Toggle the lock
	tickTimer = window.setInterval('tick()', TICK_TIME);
}

// Tick the timer
function tick() {
	currentTick = currentTick + lock;
	if(currentTick >= MAX_TICKS || currentTick < MIN_TICKS) {
		stop();
	} else {
		var opacity = (currentTick+lock)/MAX_TICKS;
		if(window.navigator.appName == "Netscape") {
			element.style.opacity = opacity;
		} else {
			element.style.filter = "alpha(opacity=" + opacity*100 + ")";
		}
	}
}

// Stop the timer
function stop() {
	window.clearInterval(tickTimer);
	if(currentTick == 0) element.style.display = 'block';
	if(currentTick == -1) element.style.display = 'none';
//	alert(currentTick);
}
