﻿//
// WEB SMALL POPUP

var IdentityPopTimer = "";

function showIdentityPopup(e) {
	var popIdentity = document.getElementById('identitypop');
	var btnIdentity = document.getElementById('identity');


	if (moveanim.timer != null) {
		clearInterval(moveanim.timer);
		moveanim.timer = null;
	}

	// Determine where we should pop up in relation to the dynamic button
 
	position = findElementPos(btnIdentity);
	popIdentity.style.top = (position[1] - (popIdentity.offsetHeight - 40)) +"px";
	popIdentity.style.left = "360" + "px";

	// If already trigger a rollover, cancel it because we're back in

	if (IdentityPopTimer != "")
	{
		clearTimeout(IdentityPopTimer);
		IdentityPopTimer = "";
	} else {
		setOpacity(0, 'identitypop');
		popIdentity.style.visibility = 'visible';
		moveStart(popIdentity, parseInt(popIdentity.style.left), parseInt(popIdentity.style.left), parseInt(popIdentity.style.top) + 10, parseInt(popIdentity.style.top), 15);
		fadeElementSetup('identitypop', 0, 100, 13);
	}
}

function hideIdentityPopup() {
	// Start timer to hide the pop-up and the overlay
	IdentityPopTimer = setTimeout("IdentityPopupActuallyHide()", 500);
}

function IdentityPopupActuallyHide() {
	var popIdentity = document.getElementById('identitypop');
	if (IdentityPopTimer != "")
	{
		IdentityPopTimer = "";
		moveStart(popIdentity, parseInt(popIdentity.style.left), parseInt(popIdentity.style.left), parseInt(popIdentity.style.top), parseInt(popIdentity.style.top) - 10, 15);		
		fadeElementSetup('identitypop', 100, 0, 13, 1);
	}
}

//
// MOVE: Animate the move of an element.
//
// Move is also synchronous. One at a time, please.
//

var moveanim = {time:0, beginX:0, changeX:0.0, beginY:0, changeY:0, duration:0.0, element:null, timer:null};

function moveStart(elem, startX, endX, startY, endY, duration)
{
	if (moveanim.timer != null) {
		clearInterval(moveanim.timer);
		moveanim.timer = null;
	}
	moveanim.time = 0;
	moveanim.beginX = startX;
	moveanim.changeX = endX - startX;
	moveanim.beginY = startY;
	moveanim.changeY = endY - startY;
	moveanim.duration = duration;
	moveanim.element = elem;

	moveanim.timer = setInterval("moveAnimDo();", 15);
}

function moveAnimDo()
{
	if (moveanim.time > moveanim.duration) {
		clearInterval(moveanim.timer);
		moveanim.timer = null;
	}
	else {
		moveX = cubicOut(moveanim.time, moveanim.beginX, moveanim.changeX, moveanim.duration);
		moveY = cubicOut(moveanim.time, moveanim.beginY, moveanim.changeY, moveanim.duration);
		moveanim.element.style.left = moveX + "px";
		moveanim.element.style.top = moveY + "px";
		moveanim.time++;
	}
}



//console.log("Initialized");