$(document).ready (
	function() {
		// Start code after page loading - same as "window.onload = function ..."
		// La fonction sera appelée quand l'arbre dom est chargé
		// le onload, lui, attend le chargement de tous les éléments de la page html
		
		// Init
		InitBulle("black","white","black",1);
		
		$('#bckSuggestionsBox').click(function() {
			hideLayerHTML()
		});
		
		/*
		$('a').click(function() {				
				var newLi = document.createElement("li");								
				newLi.innerHTML =  'Please wait...Loading...'
				$('#autoSuggestionsList').empty()
				$('#autoSuggestionsList').append(newLi)				
				getLayerHTML(0,0)
		})
		*/		
		
		//Récupérer les éléments du breadcrumb
		var arrayOfBreadcrumbItems = new Array()
		$('#breadcrumb img').each(
			function(i) {
				var tempString = $(this).attr('id')
				tempString = tempString.substr(9,tempString.length) // bdcb_img_
				
				arrayOfBreadcrumbItems.push(tempString)
			}
		)
		var listBreadcrumbItems = arrayOfBreadcrumbItems.join('|')
		
		// Récupérer les frères de chaques éléments du breadcrumb
		$.getJSON("typo3conf/ext/cfwb_breadcrumb_brother/services/getJsonBrothers.php?listBreadcrumbItems="+listBreadcrumbItems,					
			        function(data){
					  $.each(data.page, function(i,page){				  	
						
						$('#bdcb_img_'+page.uid).attr('src','typo3conf/ext/cfwb_breadcrumb_brother/Bouton-Deroulement.jpg')
						$('#bdcb_img_'+page.uid).click(function() {
							var debug_output = ''
							var output = ''							 
							  							
							if (!getLayerHTML(page.uid,0)) {								
								return
							}
							
							$('#autoSuggestionsList').empty()
							$.each(page.brothers, function(j,brother) {
								debug_output = debug_output + "\t" + brother.uid + "\n"
								//output = output + '<li><a href="' + brother.url + '" alt="' + brother.title + '" title="' + brother.title + '"><span class="suggestionList">' + brother.title + '</span></a></li>'
								
								var newLi = document.createElement("li");								
								newLi.id = 'bdcb_li_' + brother.uid
								newLi.innerHTML =  brother.title
								//$(newLi).addClass('suggestionList')
								
								if (brother.current == 1) {
									$(newLi).addClass('suggestionListCurrent')
								} else {
									$(newLi).click(function(){
										document.location.href = brother.url
									})									
								}
								
								$('#autoSuggestionsList').append(newLi) 
								
							})

						})
						
					  });
					  //alert(debug_output)
					});		
	}
)


/****************************************************************************************************/
/****************************************************************************************************/
//D'autres scripts sur http://www.toutjavascript.com
//Si vous utilisez ce script, merci de m'avertir !  < webmaster@toutjavascript.com >
//Auteur original :Olivier Hondermarck  <webmaster@toutjavascript.com>
//Modifs compatibilité Netscape 6/Mozilla : Cédric Lamalle 09/2001 <cedric@cpac.embrapa.br>
//Correction Mac IE5 (Merci Fred)

var IB=new Object;
var posX=0;posY=0;
var xOffset=35;yOffset=5;
var isHidden = 1;

function hideLayerHTML() {
		isHidden = 1;
		$('#bckSuggestionsBox').fadeOut("slow")
		$('#suggestions').fadeOut("slow")
		//$('#suggestions').slideUp("slow")
		//$('#suggestions').hide()	
}

function getLayerHomeHTML(uid,type) {
	//ajaxCallDynamicPage (","displayTextCore","self","Chargement en cours...","border:solid 0px orange;background:#FFFFFF;padding:0px;font-weight:bold;position:relative;");
	$('#autoSuggestionsList').empty()
	
	/*
	var newImg = document.createElement("img");								
	newImg.src = 'typo3conf/ext/cfwb_breadcrumb_brother/ajax-loader3.gif'
	$(newImg).css('margin','0')
	$(newImg).css('padding','0')
	//$(newImg).css('position','absolute')
	$('#autoSuggestionsList').append(newImg)
	*/
	$('#autoSuggestionsList').html(('Chargement en cours...'))
	
	$('#autoSuggestionsList').load("typo3conf/ext/etnic_plugins/services/cfwb_portail_display_infos_submenu.php?uid="+uid+"&type="+type+"")
	getLayerHTML()	
}

function getLayerHTML() {

	if (!isHidden) {
		hideLayerHTML()
	  	return false
	}
	
	isHidden = 0;
	var finalPosX=posX-xOffset;
	if (finalPosX < 0) {
		finalPosX = 0;
	}	
	var finalPosY=posY+yOffset;
		
	$('#suggestions').css('top',""+finalPosY+"px")
	$('#suggestions').css('left',""+finalPosX+"px")
	$('#suggestions').fadeIn("slow")
	$('#CloseBox').click(function(){
		hideLayerHTML()
	})
	
	$('#suggestions').css('opacity);',50)
	$('#bckSuggestionsBox').fadeIn("slow")
	//$('#suggestions').slideDown("slow")
	//$('#suggestions').show()
	
	return true
}


function AffBulle(texte) {
	/*
  if (!isHidden) {
  	HideBulle();  	
  	return;
  }
  isHidden = 0;
  */
  
  contenu="<TABLE id='idBulle' border=0 cellspacing=0 cellpadding="+IB.NbPixel+" style='width:260px;'><TR bgcolor='"+IB.ColContour+"'><TD><TABLE width='100%' border=0 cellpadding=5 cellspacing=0 bgcolor='"+IB.ColFond+"'><TR><TD>"+texte+"</TD></TR></TABLE></TD></TR></TABLE>";
  var finalPosX=posX-xOffset;
  if (finalPosX<0) finalPosX=0;
  if (document.layers) {
    document.layers["MCFBulle"].document.write(contenu);
    document.layers["MCFBulle"].document.close();
    document.layers["MCFBulle"].top=posY+yOffset;
    document.layers["MCFBulle"].left=finalPosX;
    document.layers["MCFBulle"].visibility="show";
    document.layers["ContainerMCFBulle"].visibility="show";
    }
  if (document.all) {
    //var f=window.event;
    //doc=document.body.scrollTop;
    MCFBulle.innerHTML=contenu;
    document.all["MCFBulle"].style.top=posY+yOffset;
    document.all["MCFBulle"].style.left=finalPosX;//f.x-xOffset;
    document.all["MCFBulle"].style.visibility="visible";
    document.all["ContainerMCFBulle"].style.visibility="visible";
  }
  //modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
  else if (document.getElementById) {
    document.getElementById("MCFBulle").innerHTML=contenu;
    document.getElementById("MCFBulle").style.top=posY+yOffset+"px";
    document.getElementById("MCFBulle").style.left=finalPosX+"px";
    document.getElementById("MCFBulle").style.visibility="visible";
    document.getElementById("ContainerMCFBulle").style.visibility="visible";    
  }
}

function getMousePos(event) {
  event = event || window.event
  	posX=event.clientX
  	posY=event.clientY
}

function InitBulle() {
	if (document.layers) {
		window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=getMousePos;
	}
	if (document.all) {
		document.onmousemove=getMousePos;
	}
	//modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
	else if (document.getElementById) {
	        document.onmousemove=getMousePos;
	}
}
