

function img(id) { popup('image',id); }
function com(id) { popup('commentary',id); }
function vid(id) { popup('video',id); }
function aud(id) { popup('music',id); }

function supplink(string)
{
	var split = string.split("/");
	popup(split[0],split[1]);
}
	


function popup(type,id)
{
	supplement = '';
	var ajax = get_ajax("/"+type+"/" + id);
	
	window.location.hash = "/"+type+"/" + id;
	
	var f = document.getElementById('supplement');
	
	var coords = getPageRect()
	var x = windowWidth();
	var y = windowHeight();
    f.innerHTML = '<div id="loading"></div>';
	f.style.display = "block";
	
	
	f.style.left =(x/2)-(f.offsetWidth/2)+"px";
	f.style.top = coords[1]+(y/2)-50-(f.offsetHeight/2)+"px";

   	ajax.onreadystatechange = function () {
	       if (ajax.readyState == 4) {
	           f.innerHTML = ajax.responseText;
				f.style.left = (75)+((x/2)-(f.offsetWidth/2))+"px";
				var top = (coords[1]+(y/2)-(f.offsetHeight/2))-100;
				if(top < coords[1]) top = coords[1];
				f.style.top = top+"px";
				if(type == "video" || type == "music")
				{
					silence();
				}
	       }
	   }
	ajax.send();
}




function dragstart()
{
	dragging = true;
	box = document.getElementById('supplement');
	coords = getElementRect(box);
	popOffsetX = mouseX-coords[0];
	popOffsetY = mouseY-coords[1];
}

function dragstop()
{
	dragging = false;
	document.getElementById('supplement').style.display = 'none';
}

