/* JS Document */

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function setFocus( id ){
	var obj = document.getElementById(id);	
	return (obj) ? obj.focus()  : false;	
}
function setValue( id , value){
	var obj = document.getElementById(id); 
	if (obj)
		obj.value = value;		
}
function conf(){
	return confirm ('Etes vous sur ?')	;
}
function goTo(url) {
	document.location.href=url;
}
function showInput(id, value) {
	obj = document.getElementById(id); 
	alert(obj.parentNode);
}

function setOutil( container ){
	
	$(	'a' , container ).hover(
		function(){	$("#outil").prepend( '<li class="bulle">'+  $(this).attr('title') + '</li>'); },
		function(){	$('li.bulle', container ).remove(); }
	);
}


function setMenu(element){
	
	element.hover(
	function(){ 		
		$(this).addClass('hover');
		$('> ul', this).show();
	}, 
	function(){ 
		$(this).removeClass('hover');
		$('> ul', this).hide();		
	});
}

function showAgenda( bloc , element ){
	
	$("#calendrier", bloc).hide();
	$("#chargement", bloc ).show();	
	
	
	var ajaxUrl = "/index.html?ajax=agenda";

	if ($(element).attr('rel'))
		ajaxUrl	+= '&'+$(element).attr('rel');
	

	$.ajax({
		url: ajaxUrl,
		async: true,
		success:function(data){	
		
			$("#chargement", bloc ).hide();
			bloc.html(data);
			$("#calendrier", bloc).fadeIn('slow');			
		}
	});		
	
	return false;
}

function setCalendrier( bloc ){		
	//showAgenda( bloc );		
	
	bloc.each(function(){
	
		$('a.nav' , bloc).livequery ('click', 
		  	function(){ return showAgenda( bloc , this ); 
		});
		
	});
	
	return false; 
}


function showMenu( container ) {
	
	if (container)	{	
		
		$.ajax({
			url: "/index.php?ajax=menu",
			async: true,
			success:function(data){			
				container.html( data );					
			}
		});		
	}
	
	return false;
}

function ready(){
	
	setMenu($('#menu li'));
	
	// Calendrier
	setCalendrier( $('#bloc_calendrier') );
	
//	setOutil( $("ul#outil") );
	
	// Menu déroulant
	$('> ul', '#menu li').hide();	
	$("#focus").focus();
	
	// Menu page d'accueil
	showMenu( $("#menu-container") );
}

$(document).ready(function(){ready();});
