////// ARROW KEYS /////////////////////////////////////

function next()
{
	var link = document.getElementById ("nextPic");
	if (link)
	{
		window.location.href = link.href
	}
}

function prev()
{
	var link = document.getElementById ("prevPic");
	if (link)
	{
		window.location.href = link.href
	}
}

function getkey(e)
{
	// Internet Explorer
	if (e == null)
	{
		kcode = event.keyCode;
	}
	// Mozilla
	else
	{
		// moz doesn't override ctrl keys,
		// eg, Ctrl-N won't bypass this function to open new window
		if (e.altKey || e.ctrlKey) {
			return true;
		}
		kcode = e.which;
	}

	switch(kcode) { 
	case 39 : next(); return false; //right arrow
	case 37 : prev(); return false; //left arrow
	}
}

document.onkeydown = getkey;

////// HOVER /////////////////////////////////////

function showHover()
{
	var toppadding = 20;

	var mainphoto = document.getElementById ("mainphoto");
	var hoverdiv = document.getElementById ("hoverdiv");
	var hoverdiv = document.getElementById ("hoverdiv");
	var pos = findPos (mainphoto);

	var x = pos[0] + mainphoto.width/2 - 198; // - hoverdiv.style.width;
	var y = pos[1] + toppadding;

	hoverdiv.style.left = x;
	hoverdiv.style.top  = y;
	hoverdiv.style.display = "block";

}


function hideHover()
{
	var hoverdiv = document.getElementById ("hoverdiv");
	hoverdiv.style.display = "none";
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

