/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
document.onclick = onClickListener;
var x;
var y;
function onClickListener(e)
{
    if (window.event) e=window.event;
    x = mouseX(e);
    y = mouseY(e);

}
*/

var popupWidth = 400;
var popupHeight = 200;
var animationInTime = 0.5;
function showPopup(x, y, popupId)
{
    var popup = document.getElementById(popupId);
    var popups = getElementsByPrefix('popup', document.getElementById('articlesList'));

    if(popups.length > 0)
	{
		for(var i=0; i<popups.length; i++)
		{
            popups[i].style.display='none';
		}
	}

    popup.style.width = 0;
    popup.style.height = 0;
    popup.style.display = 'block';
    //popup.onmouseout = popupOnMouseOutListener;
    
    //alert(x+' '+y);
    popup.style.left = x+'px';
    popup.style.top = y+'px';
    var t1 = new Tween(popup.style,'width',Tween.regularEaseOut,0,popupWidth,animationInTime,'px');
    t1.start();
    var t2 = new Tween(popup.style,'height',Tween.regularEaseOut,0,popupHeight,animationInTime,'px');
    t2.start();
    var t3 = new Tween(popup.style,'left',Tween.regularEaseOut,x,x-popupWidth,animationInTime,'px');
    t3.start();
    var tween  = new OpacityTween(popup,Tween.regularEaseIn, 0, 100, animationInTime);
	tween.start();
}

function onMouseOutListener(e)
{
    var dest = targetTo(e);
    if (dest.id.match('popup') == null)
    {
        var popups = getElementsByPrefix('popup', document.getElementById('articlesList'));

        if(popups.length > 0)
        {
            for(var i=0; i<popups.length; i++)
            {
                popups[i].style.display='none';
            }
        }
    }
}

function targetTo(e) {
  if (!e) var e = window.event;
  if (e.relatedTarget) return e.relatedTarget;
  else if (e.toElement) return e.toElement;
}

function popupOnMouseOutListener(e)
{
    var dest = targetTo(e);
    var element = (e.target) ? e.target : e.srcElement;
    if (dest.parentNode != element)
        {
            hidePopup(element);
        }
}

function hidePopup(element)
{
    element.style.display='none';
    element.style.width=0+'px';
    element.style.height=0+'px';
}


/*
function mouseX(evt)
{
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX) return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    else return null;
}

function mouseY(evt)
{
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY) return evt.clientY + (document.documentElement.scrollTop ?	document.documentElement.scrollTop : document.body.scrollTop);
    else return null;
}*/
