
function show_popup(id, angle, zoom)
{
    //Minimum space between div and border
    var borderspace = 20;
    
    //Convert angle to radians
    angle = (angle / 180) * Math.PI;
   
    //Get div element and its size
    var div = document.getElementById(id);
    var divcenterx = Math.round(div.offsetWidth/2);
    var divcentery = Math.round(div.offsetHeight/2);
    
    //Get browser width
    var width = document.all ? document.body.clientWidth : window.innerWidth;
    var height = document.all ? document.body.clientHeight : window.innerHeight;
    
    //Get center of screen and translation distance
    var centerx = Math.round(width/2);
    var centery = Math.round(height/2);
    var distance = Math.round(width/2);
    if (height < width) distance = Math.round(height/2);
    
    //Get new coords using angle and zoom
    var x = Math.round(centerx + Math.cos(angle) * distance * zoom - divcenterx);
    var y = Math.round(centery + Math.sin(angle) * distance * zoom - divcentery);
    
    //Clip coords
    if (x < borderspace) x = borderspace;
    if (x > (width - (divcenterx*2) - borderspace)) x = width - (divcenterx*2) - borderspace;
    if (y < borderspace) y = borderspace;
    if (y > (height - (divcentery*2) - borderspace)) y = height - (divcentery*2) - borderspace;
    
    //Set position of popup and make it visible
    div.style.left = x + 'px';
    div.style.top = y + 'px';
    div.style.visibility = 'visible';
}

function close_popup(id)
{
    var div = document.getElementById(id);
    if (div) div.style.visibility = 'hidden';
}

function close_popups()
{
    for (var n=1; n<20; n++)
    {
        var div = document.getElementById('p' + n);
        if (div) close_popup('p' + n);
        else return;
    }
}

function close_collections()
{
    for (var n=1; n<10; n++)
    {
        var div = document.getElementById('c' + n);
        if (div) close_popup('c' + n);
        else return;
    }
}    

function close_all()
{
    close_popups();
    close_collections();
}

function cancelEvents(e)
{
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}
