function MM_showHideLayers(){ //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  if(selObj.options[selObj.selectedIndex].value=='maison_picarde.php'){
  	  popupSansScroll('maison_picarde.php',745,500);	
  }
  else{
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  }
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenuDirect(targ,selObj,restore){ //v3.0
  if(selObj.options[selObj.selectedIndex].value!="")eval(targ+".location='sous_menu_"+selObj.options[selObj.selectedIndex].value+".php'");
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
function popupSansScroll(page,largeur,hauteur) {
	if (typeof(fenetre)!='undefined'){fenetre.close()}
	var origineX;var origineY;var Lecran;var Hecran;var CalageH=0;var CalageV =-100;
	if (navigator.appVersion.substring(0,1) >= 4){
		if (screen.height <= 768){Lecran = largeur;Hecran = hauteur;}
		else{Lecran = screen.width;Hecran = screen.height;}
	}
	else{Lecran = largeur;	Hecran = hauteur;}
	origineX = Math.round((Lecran-largeur)/2)+ CalageH;origineY = Math.round((Hecran-hauteur)/2)+ CalageV; 
	var fenetre2 = window.open(page,'fenetre2',"status,height=" + hauteur + ",width=" + largeur + ",resizable=yes,left=" + origineX + ",top=" + origineY + ",screenX=" + origineX + ",screenY=" + origineY + ",scrollbars=no,status=no");
	fenetre2.focus();
}
function popup(page,largeur,hauteur) {
	if (typeof(fenetre)!='undefined'){fenetre.close()}
	var origineX;var origineY;var Lecran;var Hecran;var CalageH=0;var CalageV =-100;
	if (navigator.appVersion.substring(0,1) >= 4){
		if (screen.height <= 768){Lecran = largeur;Hecran = hauteur;}
		else{Lecran = screen.width;Hecran = screen.height;}
	}
	else{Lecran = largeur;	Hecran = hauteur;}
	origineX = Math.round((Lecran-largeur)/2)+ CalageH;origineY = Math.round((Hecran-hauteur)/2)+ CalageV; 
	var fenetre = window.open(page,'fenetre',"status,height=" + hauteur + ",width=" + largeur + ",resizable=yes,left=" + origineX + ",top=" + origineY + ",screenX=" + origineX + ",screenY=" + origineY + ",scrollbars=yes,status=no");
	fenetre.focus();
}
var ongletCourant = '';

function MM_showHideLayers(){ //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v; }
}

// affiche les differentes photos
function afficherphoto(photo){
MM_showHideLayers(photo,'','show');
}
function fermerphoto(){
MM_showHideLayers('photo1','','hide',  'photo2','','hide',  'photo3','','hide',  'photo4','','hide',  'photo5','','hide',  'photo6','','hide',  'photo7','','hide',  'photo8','','hide',  'photo9','','hide',  'photo10','','hide',  'photo11','','hide',  'photo12','','hide',  'photo13','','hide',  'photo14','','hide',  'photo15','','hide',  'photo16','','hide',  'photo17','','hide', 'photo18','','hide',  'photo19','','hide',  'photo20','','hide',  'photo21','','hide',  'photo22','','hide',  'photo23','','hide', 'photo24','','hide',  'photo25','','hide',  'photo26','','hide',  'photo27','','hide',  'photo28','','hide',  'photo29','','hide', 'photo30','','hide',  'photo31','','hide',  'photo32','','hide',  'photo33','','hide',  'photo34','','hide',  'photo35','','hide', 'photo36','','hide',  'photo37','','hide',  'photo38','','hide',  'photo39','','hide',  'photo40','','hide',  'photo41','','hide', 'photo42','','hide',  'photo43','','hide',  'photo44','','hide',  'photo45','','hide',  'photo46','','hide',  'photo47','','hide', 'photo48','','hide',  'photo49','','hide',  'photo50','','hide',  'photo51','','hide',  'photo52','','hide',  'photo53','','hide', 'photo54','','hide',  'photo55','','hide',  'photo56','','hide',  'photo57','','hide',  'photo58','','hide',  'photo59','','hide', 'photo60','','hide',  'photo61','','hide',  'photo62','','hide',  'photo63','','hide',  'photo64','','hide',  'photo65','','hide', 'photo66','','hide',  'photo67','','hide',  'photo68','','hide',  'photo69','','hide',  'photo70','','hide',  'photo71','','hide',  'photo72','','hide',  'photo73','','hide',  'photo74','','hide',  'photo75','','hide',  'photo76','','hide',  'photo77','','hide',  'photo78','','hide',  'photo79','','hide',  'photo80','','hide',  'photo81','','hide',  'photo82','','hide',  'photo83','','hide','photo99','','hide','photo77','','hide','photo95','','hide','photo96','','hide','photo91','','hide','photo84','','hide');
}
function afficherdiv(onglet,etat){
if (ongletCourant != '') {
swapDisplay(ongletCourant,'masque');
}
//alert(ongletCourant);
ongletCourant = onglet;
swapDisplay(onglet,etat);
}

// fait un don
function faireUnDon(don)
{
	if(!donsPossibles[don])
		return;
		
	var formulaire = document.getElementById('formDons');
	if(!formulaire)
	{
		alert("Formulaire introuvable");
		return;
	}
	
	document.getElementById('formDons_itemName').value = "Don Urgence-Benin.org - "+donsPossibles[don][0];
	document.getElementById('formDons_amount').value = donsPossibles[don][1];
	
	formulaire.submit();
}

// défile les dernières news
var newsScroller_index = 0;
var newsScroller_pause = false;
var newsScroller_realWidth = new Array();
function newsScroller()
{
	var i=0;
	var newsDiv;

	for(i=0; newsDiv = document.getElementById('news_'+i); i++)
		newsDiv.style.display = 'none';

	window.onload = newsScrollerInit();
}

function newsScrollerInit()
{
	var i=0;
	var newsDiv;
	var container = document.getElementById('newsScrollerContainer');
	var oldContainerWidth = container.style.width;

	container.style.width = '';
	for(i=0; newsDiv = document.getElementById('news_'+i); i++)
	{
		newsDiv.style.display = '';
	}
	
	window.setTimeout(function(){newsScrollerInit_(oldContainerWidth);}, 10);
}

function newsScrollerInit_(oldContainerWidth)
{
	var i=0;
	var newsDiv;
	var container = document.getElementById('newsScrollerContainer');

	for(i=0; newsDiv = document.getElementById('news_'+i); i++)
	{
		newsScroller_realWidth[i] = newsDiv.offsetWidth;	// enregistrement de la largeur réelle du div
		newsDiv.style.display = 'none';
		newsDiv.style.position = 'relative';
	}
	container.style.width = oldContainerWidth;
	
	newsDiv = document.getElementById('news_0');
	newsDiv.style.left = '+480px';
	newsDiv.style.display = '';
	window.setInterval(newsScroller_,25);
}

function newsScroller_()
{
	if(newsScroller_pause)
		return;
		
	var newsDiv = document.getElementById('news_'+newsScroller_index);
	newsDiv.style.left = parseInt(newsDiv.style.left,10)-2+'px';	// scroll la news courante
	
	// si la news courante est complètement défilée
	if(parseInt(newsDiv.style.left,10) < newsScroller_realWidth[newsScroller_index] * -1)
	{
		newsDiv.style.display = 'none';	// masque la news courante
		
		// passe à la news suivante
		newsScroller_index++;
		if(!document.getElementById('news_'+newsScroller_index))
			newsScroller_index = 0;
			
		newsDiv = document.getElementById('news_'+newsScroller_index);
		newsDiv.style.left = '+480px';
		newsDiv.style.display = '';
	}
}

function newsScrollerPause()
{
	newsScroller_pause = true;
}

function newsScrollerPlay()
{
	newsScroller_pause = false;
}
 $(document).ready( function () {
        // On cache les sous-menus
        // sauf celui qui porte la classe "open_at_load" :
        $("ul.subMenu:not('.open_at_load')").hide();
        // On selectionne tous les items de liste portant la classe "toggleSubMenu"
    
        // et on remplace l'element span qu'ils contiennent par un lien :
        $("li.toggleSubMenu span").each( function () {
            // On stocke le contenu du span :
            var TexteSpan = $(this).text();
            $(this).replaceWith('<a href="" title="Afficher le sous-menu">' + TexteSpan + '</a>') ;
        } ) ;
    
        // On modifie l'evenement "click" sur les liens dans les items de liste
        // qui portent la classe "toggleSubMenu" :
        $("li.toggleSubMenu > a").click( function () {
            // Si le sous-menu etait deja ouvert, on le referme :
            if ($(this).next("ul.subMenu:visible").length != 0) {
                $(this).next("ul.subMenu").slideUp("normal", function () { $(this).parent().removeClass("open") } );
            }
            // Si le sous-menu est cache, on ferme les autres et on l'affiche :
            else {
                $("ul.subMenu").slideUp("normal", function () { $(this).parent().removeClass("open") } );
                $(this).next("ul.subMenu").slideDown("normal", function () { $(this).parent().addClass("open") } );
            }
            // On empêche le navigateur de suivre le lien :
            return false;
        });
    
    } ) ;