// JavaScript Document

// Define the interval variable
//var ivID;

// animation trigger on rollOver
function rollOver(id, stopfr) {
	clearInterval(id.ivID);
	// height of one frame
	var jump = id.parentNode.offsetHeight;
	// where to stop
	var limit;
	stopfr ? limit = stopfr*jump : limit = (parseInt(id.offsetHeight) - jump);
	//alert(parseInt(id.offsetHeight))
	id.ivID = setInterval(anim, 30, id, 'fw', jump, limit, stopfr);
}

// animation trigger on rollOut
function rollOut(id, stopfr) {
	// define current frame
	var curfr = (parseInt(id.offsetTop)*-1)/id.parentNode.offsetHeight;
	// check if the current frame is beyond the stop frame » no rollOut
	if((stopfr && curfr <= stopfr) || curfr > 0) {
		clearInterval(id.ivID);
		// height of one frame
		var jump = id.parentNode.offsetHeight;
		// where to stop
		var limit;
		stopfr ? limit = stopfr*jump : limit = 0;
		id.ivID = setInterval(anim, 30, id, 'bw', jump, limit, stopfr);
	}
}

// 1 frame animation
function anim(id, dir, jump, limit, stopfr) {
	// total frames
	var framecount = parseInt(id.offsetHeight) / jump - 1;
	if (dir == 'fw')  {
		//alert(parseInt(id.offsetTop)*-1+" / "+limit)
		// move one frame down
		if (parseInt(id.offsetTop)*-1 < limit) {
			id.style.top = parseInt(id.offsetTop)-jump+"px"
		} else {
			// jump to first frame when reaching last
			stopfr == (framecount) ? id.style.top = 0+"px" : null;
			clearInterval(id.ivID);
		}
	} else if (dir == 'bw') {
		// move 1 frame up
		if (parseInt(id.offsetTop)*-1 > limit) {
			id.style.top = parseInt(id.offsetTop)+jump+"px"
		} else {
			clearInterval(id.ivID);
		}
	}
}