// JavaScript Document

function display(elemId) {
    if (document.getElementById) {
		for (i = 1; i <= nbElem; i++) {
			tab = "tab" + i;
			li = "li" + i;
			lib = "lib" + i;
			document.getElementById(tab).style.display = (i == elemId) ? 'block' : 'none';
			document.getElementById(li).className = (i == elemId) ? 'active' : '';
			document.getElementById(lib).className = (i == elemId) ? 'active' : '';
		}
	}
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight=window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getOffsetY(tab) {
	var hDiv = document.getElementById(tab).offsetHeight;
	var hDoc = getWindowHeight();
	var offsetY = 0;
	if (navigator.appName=="Microsoft Internet Explorer") {
		offsetY = document.documentElement.scrollTop + (hDoc - hDiv) / 2;
	} else {
		offsetY = window.pageYOffset + (hDoc - hDiv) / 2;
	}
	return offsetY;
}

function displayLayer(tab) {
	var h_global = document.getElementById('global').offsetHeight;
	var h_document = getWindowHeight();
	document.getElementById(tab).style.top = getOffsetY(tab) + "px";
	document.getElementById(tab).style.visibility = 'visible';
	document.getElementById('masque').style.height = Math.max(h_global, h_document) + "px";
	document.getElementById('masque').style.visibility = 'visible';
}

function hideLayer(tab) {
	document.getElementById(tab).style.visibility = 'hidden';
	document.getElementById('masque').style.visibility = 'hidden';
}

function video(id, path) {
	var xhr = getXMLHttpRequest();

	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			selection = xhr.responseText;
			document.getElementById('detail_video').innerHTML = selection;
			displayVideo('video');
		}
	}

	xhr.open("POST", path + "video/video.php", true);
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr.send("id=" + id + "&path=" + path);
}

function displayVideo(tab) {
	document.getElementById(tab).style.top = getOffsetY(tab) + "px";
	document.getElementById(tab).style.visibility = 'visible';
}

function hideVideo(tab) {
	document.getElementById(tab).style.visibility = 'hidden';
	document.getElementById('detail_video').innerHTML = '';
}
