var mouseX, mouseY, mDivX, mDivY;
var isMSIE = /*@cc_on!@*/false;

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];
}

function getWinWidth()
{
	if( typeof( window.innerWidth ) == 'number' )
	{
		return(window.innerWidth);
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		return(document.documentElement.clientWidth);
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		return(document.body.clientWidth);
	}
	return [myWidth,myHeight]
}

function getWinHeight()
{
	if( typeof( window.innerWidth ) == 'number' )
	{
		return(window.innerHeight);
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		return(document.documentElement.clientHeight);
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		return(document.body.clientHeight);
	}
}

var menuPop = false;
var menuHeight = 16;
var nCont;
var menuHeight = 0;
var growth = 0;
var menuOn = false;

function debug(str)
{
	document.getElementById("debug").value = str;
}


function menuTimer()
{
	var dif = (findPos(nCont)[1] - 16) - mouseY;
	if (mouseY)
	{
		if (dif < 0)
		{
			if (menuHeight < 128)
			{
				menuHeight += 8;
				refreshMenu();
			} else {
				if (menuHeight != 128)
				{
					menuHeight = 128;
					refreshMenu();
				}
			}
		} else {
			if (menuHeight > 0)
			{
				menuHeight -= 8;
				refreshMenu();
			} else {
				if (menuHeight != 0)
				{
					menuHeight = 0;
					refreshMenu();
				}
			}
		}
	}
}

function mousePosition(evt) 
{
	if(document.all)
	{
		mouseX = event.clientX;
		mouseY = event.clientY;
	} else {
		if(document.layers)
		{
			mouseX = evt.pageX;
			mouseY = evt.pageY;
		} else {
			if(document.getElementById)
			{
				mouseX = evt.clientX;
				mouseY = evt.clientY;
			}
		}
	}
	if (!menuOn)
	{
		setInterval ( "menuTimer()", 10);
		menuOn = true;
	}
	
	refreshMenu();
}

function refreshMenu()
{
	o = findPos(nCont);
	var tmp = -1;
	for (i = 0;e = divTab[i];i++)
	{
		var c = findPos(e[0]);
		var half = (e[0].offsetWidth / 2);
		c[0] += half;
		c[1] -= e[0].offsetHeight;
		e[1].style.left = ((c[0] - o[0]) - (e[1].offsetWidth / 2)) + "px";
		var d = Math.abs(c[0] - mouseX);
		if (d < 256)
		{
			var cs = Math.cos(d * (3.1416 / (256 * 2)));
			h = 16 + (cs * menuHeight);
		} else {
			h = 16;
			e[1].style.opacity = "0";
		}
		e[0].style.width = h + "px";
		e[0].style.height = h + "px";
		var relPos = Math.abs(mouseX - c[0]);
		if ((relPos < half) && (mouseY > o[1]))
		{
			relPos /= half;
			if (isMSIE)
			{
				e[1].style.filter = "alpha(opacity=" + ((1 - relPos) * 100) + ")";
			} else {
				e[1].style.opacity = 1 - relPos;
			}
		} else {
			if (isMSIE)
			{
				e[1].style.filter = "alpha(opacity=0)";
			} else {
				e[1].style.opacity = 0;
			}
		}
	}
	nCont.style.left = ((getWinWidth() - nCont.offsetWidth) / 2) + "px";
}

var fontSize = 13;
function setTextSize(val)
{
	if ((fontSize + val > 10) && (fontSize + val< 20))
	{
		fontSize += val;
		var body = document.getElementsByTagName("body")[0];
		body.style.fontSize = fontSize + "px";
	}
}

var divTab = new Array();
var linkTab = new Array(
	new Array("Crystal_Clear_app_home.png","./0000.php","Retour à la page d'acceuil",""),
	new Array("map.png","./carte.php","Plan du site",""),
	new Array("email.png","mailto:webmaster@brive.fr","Contact webmaster",""),
	new Array("help.png","./_legal.php","Informations Légales",""),
	new Array("cloudy4.png","#","Météo","createPopupMeteo();return false;"),
	new Array("Crystal_Clear_action_viewmag+.png","#","Augmenter la taille du texte","setTextSize(1);return false;"),
	new Array("Crystal_Clear_action_viewmag-.png","#","Diminuer la taille du texte","setTextSize(-1);return false;")
);

var currentIcon = null;
function activeIcon(obj)
{
	currentIcon = obj;
}

function initMenu()
{
	var footer = document.getElementById("notesBasPage");
	var lst = footer.getElementsByTagName("a");
	nCont = document.createElement("div");
	nCont.setAttribute("id","nCont");
	nCont.style.position = "absolute";
	nCont.style.bottom = "3px";
	nCont.style.width = (7 * 128) + "px";
	while (footer.firstChild) footer.removeChild(footer.firstChild);
	for (var i = 0;e = linkTab[i];i++)
	{
		var nDiv = document.createElement("div");
		nDiv.setAttribute("id","jMenu" + i);
		var nA = document.createElement("a");
		nA.setAttribute("href",e[1]);
		nA.jsFunction = e[3];
		if (e[3])
		{
			if (isMSIE)
			{
				if (i == 4) nA.onclick = function() { createPopupMeteo();return false; };
				if (i == 5) nA.onclick = function() { setTextSize(1);return false; };
				if (i == 6) nA.onclick = function() { setTextSize(-1);return false; };
			} else {
				nA.setAttribute("onClick",e[3]);
			}
		}
		
		var nSpan = document.createElement("span");
		nSpan.style.position = "absolute";
		nSpan.style.whiteSpace="nowrap";
		if (isMSIE)
		{
			nSpan.style.filter="alpha(opacity=0)";
		} else {
			nSpan.style.opacity = "0";
		}
		nSpan.style.bottom = "0";
		nSpan.appendChild(document.createTextNode(e[2]));
		nA.appendChild(nSpan);
		var nImg = document.createElement("img");
		nImg.setAttribute("src","./Style/Icones/128/" + e[0]);
		nImg.style.width = "16px";
		nImg.style.height = "16px";
		nImg.style.behavior = "url('./Style/iepngfix.htc')";
		nA.appendChild(nImg);
		nCont.appendChild(nA);
		divTab[i] = new Array(nImg,nSpan);
		footer.appendChild(nDiv);
	}
	footer.appendChild(nCont);
	nCont.style.left = ((getWinWidth() - nCont.offsetWidth) / 2) + "px";
}

document.onmousemove = mousePosition;
