function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function showHide(div) {
	el = document.getElementById(div);
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	document.getElementById("overlay").style.visibility = el.style.visibility;
	
	if (div == "search" && el.style.visibility == "visible") document.getElementById("q").focus();
}

function getTop(MyObject)
//Fonction permettant de conna?tre la position d'un objet
//par rapport au bord haut de la page.
//Cet objet peut ?tre ? l'int?rieur d'un autre objet.
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
    }
	
var qfocus=false;
document.getElementById('q').onfocus = function() {qfocus = true;}
document.getElementById('q').onblur = function() {qfocus = false;}

document.onkeypress=function(e) 
{
	if (!e) e = window.event;
	var k=(e.keyCode)?e.keyCode: ((e.charCode)?e.charCode:((e.which)?e.which:0));
	//alert(k);

if (!qfocus) {
	if (k == 117) document.location='./?'
	if (k == 104) showHide("ghelp");
	if (k == 47) showHide("search");
	if (k == 106) {
		links[current_link].className = "links";
		current_link = (current_link - 1 + links.length) % links.length;
		links[current_link].className = "links selected";
		if (getTop(links[current_link])+150 - window.pageYOffset > window.innerHeight) window.scrollTo(0, getTop(links[current_link])-window.innerHeight+150);
		if (getTop(links[current_link])-150 < window.pageYOffset) window.scrollTo(0, getTop(links[current_link])-150);}
	if (k == 107) {
		links[current_link].className = "links";
		current_link = (current_link + 1) % links.length;
		links[current_link].className = "links selected";
		if (getTop(links[current_link])+150 - window.pageYOffset > window.innerHeight) window.scrollTo(0, getTop(links[current_link])-window.innerHeight+150);
		if (getTop(links[current_link])-150 < window.pageYOffset) window.scrollTo(0, getTop(links[current_link])-150);}
	if (k == 111) document.location=links[current_link].href;
	if (k == 100) document.location='./?diaporama'
	if (k == 69) document.location='./?edit'
} else if (k == 27) {showHide("search");document.getElementById("q").blur();}
}

var links = getElementsByClass('links');
var current_link = 0
links[current_link].className = "links selected";
