
function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent){
		while(1){
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	}
	else if(obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent){
		while(1){
			curtop += obj.offsetTop;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	}
	else if(obj.y) curtop += obj.y;
	return curtop;
}

function comeIn(box, startX, startY, endX, endY, rate, timeStep){
	if (box.transitionState == 2){
		box.style.opacity = 1.0;
		box.style.display = "none";
		box.style.height = 0;
		box.style.width = 0;
	}
	x = parseInt(box.style.width.substring(0, box.style.width.length-2));
	y = parseInt(box.style.height.substring(0, box.style.height.length-2));
	if (startX < endX) x += rate;
	else x += rate, box.style.left = (parseInt(box.style.left.substring(0, box.style.left.length-2)) - rate) + "px";
	if (startY < endY) y += rate;
	else y += rate, box.style.top = (parseInt(box.style.top.substring(0, box.style.top.length-2)) - rate) + "px";
	box.style.width = x + "px";
	box.style.height = y + "px";
	width = Math.abs(startX - endX);
	height = Math.abs(startY - endY);
	if (x >= width){
		box.style.width = width + "px";
		box.style.left = Math.min(startX, endX) + "px";
	}
	if (y >= height){
		box.style.height = height + "px";
		box.style.top = Math.min(startY, endY) + "px";
	}
	if ((x >= width) && (y >= height)){
		box.children[0].style.display = "block";
		box.transitionState = 0;
	}
	else setTimeout(function(){comeIn(box, startX, startY, endX, endY, rate, timeStep)},timeStep);
}

function divIn(obj, start_id, end_id){
	textDiv = obj.children[0];
	textDiv.transitionState = 1;
	startObj = document.getElementById(start_id);
	endObj = document.getElementById(end_id);
	startX = findPosX(startObj);
	startY = findPosY(startObj);
	endX = findPosX(endObj);
	endY = findPosY(endObj);
	if (startX > endX) startX += 130;
	else endX += 130;
	if (startY > endY) startY += 130;
	else endY += 130;
	textDiv.style.left = startX + "px";
	textDiv.style.top =  startY + "px";
	textDiv.style.display = "block";
	textDiv.style.height = "0px";
	textDiv.style.width = "0px";
	comeIn(textDiv, startX, startY, endX, endY, 8, 10);
}

function goOut(box, rate, timeStep){
	if (box.transitionState == 1){
		box.style.opacity = 1.0;
		return;
	}
	box.style.opacity -= rate;				
	if (box.style.opacity <= 0){
		box.style.opacity = 1.0;
		box.style.display = "none";
		box.style.height = "0px";
		box.style.width = "0px";
		box.transitionState = 0;
	}
	else setTimeout(function(){goOut(box, rate, timeStep);}, timeStep);
}

function hideText(obj){
	box = obj.children[0];
	box.transitionState = 2;
	box.children[0].style.display = "none";
	box.style.opacity = 1.0;
	goOut(box, 0.05, 15);
}

