/****************************************************/
/*				CUSTOM OVER CALENDAR				*/
/****************************************************/
var showObject;
var offsetfrommouse=[10,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var hScreenSecurity = 212;
var vScreenSecurity = 200;

function overCalendar() {
	if($('calendar')) {
		// création du conteneur de zoom
		var conteneurZoom = document.createElement('div');
		conteneurZoom.id = 'overCalendar';
		document.body.appendChild(conteneurZoom);
		showObject = $('overCalendar');
		
		$$('#calendar a').each(function(n) {
			n.contentTitle = n.title;
			n.onmouseover = function() {
				putContent(this.contentTitle);
				this.title = "";
				document.onmousemove=followmouse;
			}
			n.onmouseout = function() {
				document.onmousemove=killfollowmouse;
			}
		});
	}
}

function putContent(contenu) {
	contenu = contenu.split("\n");
	if(contenu.length > 0) {
		contenuHTML = "<ul>";
		for(ic=0; ic<contenu.length; ic++) {
			contenuHTML += "<li>"+contenu[ic]+"</li>";
		}
		contenuHTML += "</ul>";
	}
	showObject.innerHTML = contenuHTML;
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function killfollowmouse(e) {
	showObject.style.left = "-999em";
}

function followmouse(e){
	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){	// MOZILLA
		if (docwidth - e.pageX < hScreenSecurity){
			xcoord = e.pageX - (xcoord + hScreenSecurity ); // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (10 + vScreenSecurity)){
			ycoord += e.pageY - Math.max(0,(vScreenSecurity + 10 + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){		// IE
		if (docwidth - event.clientX < hScreenSecurity){
			xcoord = event.clientX + truebody().scrollLeft - (xcoord + hScreenSecurity); // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (10 + vScreenSecurity)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(vScreenSecurity + 10 + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	
	showObject.style.left = xcoord+"px";
	showObject.style.top = ycoord+"px";
}

/****************************************************/
/*				INITIALISATION DE LA PAGE			*/
/****************************************************/
function addLoadListenerCalendrier(func) {
	if (window.addEventListener) {
		window.addEventListener("load", func, false);
	} else if (document.addEventListener) {
		document.addEventListener("load", func, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", func);
	}
}

if (document.getElementById && document.createTextNode) {
	addLoadListenerCalendrier(function() {
		overCalendar();
	});
}
