// Dropdown menu ...
var currMenu = null;
function mainmenu(sender,classe){
	sender = document.getElementById(sender);
	if(sender){
		sender = (sender.tagName=="UL") ? sender : sender.childNodes[0];
		sender = (sender && sender.tagName=="UL") ? sender : sender.nextSibling;
		if(sender){
			if(sender.tagName=="UL"){
				if(classe!=""){
					var uls = sender.getElementsByTagName("UL");
					for(i=0;i<uls.length;i++){
						if(uls[i].className==classe) currMenu = uls[i].parentNode;
					}
					if(currMenu) currMenu.className+=" shover";
				}
				var lis = sender.getElementsByTagName("LI");
				for(i=0;i<lis.length;i++){
					if(lis[i].className!="vide"){
						lis[i].onmouseover=function() {
							if(currMenu) currMenu.className=currMenu.className.replace("shover", "");
							this.className+=" shover";
							//if(document.all) this.style.zIndex=100;
						}
						lis[i].onmouseout=function() {
							this.className=this.className.replace("shover", "");
							if(currMenu) if(currMenu.className.indexOf("shover")==-1) currMenu.className+=" shover";
							//if(document.all) this.style.zIndex=1;
						}
					}
				}
			}else{
				alert("Le sender n\'est pas un UL");
			}
		}
	}
}

function changeSizeTxt(plus){
	if(document.getElementById("contenu") && document.getElementById("msize") && document.getElementById("psize")){
		var cH = (document.getElementById("contenu"));
		var mA = document.getElementById("msize");
		var pA = document.getElementById("psize");
		
		if(!cH.style.fontSize) cH.style.fontSize = "12px";
		var fSize = parseInt(cH.style.fontSize.replace("px",""));
		
		mA.className = "";
		pA.className = "";
		
		if(plus){
			if(fSize<17){
				fSize++;
				cH.style.fontSize = fSize+"px";
			}
		}else{
			if(fSize>10){
				fSize--;
				cH.style.fontSize = fSize+"px";
			}
		}
		
		if(fSize>=17) pA.className = "hidden";
		if(fSize<=10) mA.className = "hidden";
	}
	return false;
}

function printPage(){
	window.print();
	return false;
}

function addBenevole(hndl){

	bRetour = validForm(hndl);

	if(bRetour){		
		jQuery.post("/script/addBenevole.php",jQuery("#formbenevole").serialize(),function(data){jQuery("#formulaire").html(data);});

	}
	return false;
}
 

function changemois(direction,mois,annee){
	killAjax();
	ret = function() {
		if(ajaxOk()){
			document.getElementById('calendrier').innerHTML=objAjax.responseText;
			cleanCal();
		}
	}
	callAjax('/script/ajax.php?what=calendrier&dir='+direction+'&mois='+mois+'&annee='+annee,ret,null);
}

function cleanCal(){
	var a = document.getElementById('calendrier').getElementsByTagName('td');
	for(i=0;i<a.length;i++){
		if(a[i].innerHTML=='' || a[i].innerHTML=='&nbsp;'){a[i].className='vide';}
	}
}


function isNumber(x) 
{ 
  return ( (typeof x === typeof 1) && (null !== x) );
}




function slideSwitch() {
	var $active = $('#slideshow IMG.active');
	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
	var $next =  $active.next().length ? $active.next()
		: $('#slideshow IMG:first');
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

var curnews = 0;
var nbnews;
slideshownews = function(){
	a = $("#module-news ul li a");
	nbnews = a.length;
	a.each(function(){
		$(this).click(function(e){e.preventDefault();loadNews($(this));});
	});
	setInterval("nextNews()",7000);
};

loadNews = function(ahndl){
	$("#module-news ul li a").each(function(){$(this).removeClass("selected");});
	ahndl.addClass("selected");
	idnews = parseInt(ahndl.attr("rel").replace("news",""))-1;
	curnews = idnews;
	
	$("#showing .img a").attr("href",ahndl.attr("href"));
	$("#showing .more a.areadmore").attr("href",ahndl.attr("href"));
	$("#showing img").css("backgroundImage","url('"+lstnews[idnews].bgimg+"')");
	$("#module-news .text h3").html(lstnews[idnews].titre);
	$("#module-news .text h4").html(lstnews[idnews].displaydate);
	$("#module-news .text p").html(lstnews[idnews].texte);
};

nextNews = function(){
	maxnews = nbnews-1;
	curnews++;
	if(curnews>maxnews){
		curnews = 0;
	}
	$("#module-news ul li a").eq(curnews).click();
};

$(function() {
	setInterval( "slideSwitch()", 5000 );
	$("#module-news ul li a").eq(0).addClass("selected");
	slideshownews();
});

