/***** Fonctions générales *****/
function preChargement() {
	imgRechercherOver = new Image(100, 26);	
	imgRechercherOver.src = "images/site/btn_recherche_bg_o.jpg";
	
	imgRechercherDown = new Image(100, 26);	
	imgRechercherDown.src = "images/site/btn_recherche_bg_d.jpg";
	
	imgMenuPlus = new Image(11, 6);	
	imgMenuPlus.src = "images/site/menu_plus.gif";
}

function listeSelection(pElement) {
	window.location = pElement.options[pElement.selectedIndex].value;
}

function allerUrl(pUrl) {
	this.location.href = pUrl;	
}

window.onload = function() {
	preChargement();	
}

/***** Fonctions AJAX *****/
function obtenir_Xhr() {
	if (window.XMLHttpRequest)
		xhr = new XMLHttpRequest();
	else if(window.ActiveXOject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(el) {
				xhr = null;
			}
		}
	}
	return xhr;
}

function afficherCalendrier(pLien, pAnnee, pMois, pJour) {
	obtenir_Xhr();
	
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById('calendrierHorizontal').innerHTML = xhr.responseText;
			
			$(function() {	
				$('#calendrierHorizontal a').tooltip
				({
					track: true,
					delay: 0,
					showURL: false,
					showBody: " - ",
					fade: 400
				});
			});
		}
	}
	
	xhr.open("POST", pLien, true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("action=calendrier&calannee=" + pAnnee + "&calmois=" + pMois + "&caljour=" + pJour);
}

/***** Fonctions menu JQuery *****/
$(document).ready(
	function() {
		cacherSousMenus();
	}
)

function deroulerSousMenu(pSection) {
	var menus = document.getElementsByTagName('h3');
	
	if (document.getElementById(pSection + "-sm")) {
		$('#' + pSection + "-sm").slideToggle('fast');
		if (document.getElementById(pSection).className == "bgNormal")
			document.getElementById(pSection).className = "bgSurvol";
		else if (document.getElementById(pSection).className == "bgNormalSm")
			document.getElementById(pSection).className = "bgSurvolSm";
		else if (document.getElementById(pSection).className == "bgSurvol")
			document.getElementById(pSection).className = "bgNormal";
		else if (document.getElementById(pSection).className == "bgSurvolSm")
			document.getElementById(pSection).className = "bgNormalSm";
		
		for (var i = 0; i < menus.length; i++) {
			if (menus[i].id.substring(0,7) == 'section') {
				if (menus[i].id != pSection) {
					$('#' + menus[i].id + "-sm").slideUp('fast');
					
					if (document.getElementById(menus[i].id).className == "bgSurvol")
						document.getElementById(menus[i].id).className = "bgNormal";
					else if (document.getElementById(menus[i].id).className == "bgSurvolSm")
						document.getElementById(menus[i].id).className = "bgNormalSm";
				}
			}
		}
	}
}

function cacherSousMenus() {
	var menus = document.getElementsByTagName('h3');
	
	for (var i = 0; i < menus.length; i++) {
		if (menus[i].id.substring(0,7) == 'section') {
			if (!document.getElementById(menus[i].id).className.match("bgActuel") && !document.getElementById(menus[i].id).className.match("bgActuelSm")) {
				$('#' + menus[i].id + "-sm").hide();
			}
		}
	}
}

/***** Fonctions tooltip JQuery *****/
$(function() {	
	$('#calendrierHorizontal a').tooltip
	({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 400
	});
});

/***** Fonctions JScrollPane *****/
$(function() {
	$('#zoneNouvellesContenu').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
});
