function changeBgColor(myEvent, cityBgColor,dotBgColor,opacity,pointId,triggeredByCity)
{

	if (!myEvent)
	myEvent=window.event;
	if (!myEvent)
	return;
	var firingElement=null;
	// Internet Explorer
	if (myEvent.srcElement)
	firingElement=myEvent.srcElement;  

	// Netscape and Firefox
	else if (myEvent.target)
	firingElement=myEvent.target;    

	if (firingElement)
	{
	
		// if the mouse hoverd the city = hilight city and the right point
	    if (triggeredByCity == true)
		{
			firingElement.originalBgStyle=firingElement.style["backgroundColor"];
			firingElement.originalOpacity=firingElement.style["opacity"];
			firingElement.originalOpacityIE=firingElement.style["filter"] * 100;
			
		
			
			firingElement.originalPointColor=  $("#"+pointId).css("background-color");
			
			
			firingElement.style["backgroundColor"]=cityBgColor;
			firingElement.style["opacity"]=opacity;
			$(firingElement).css({filter:"alpha(opacity="+opacity*100+")"});

			$("#"+pointId).css("background-color",dotBgColor);
			
		} else {
		
			// save city original colors
			firingElement.originalBgStyle=$("#"+pointId).css("background-color");
			firingElement.originalOpacity=$("#"+pointId).css("opacity");
			firingElement.originalOpacityIE=$("#"+pointId).css("filter") * 100;
			
			// save point original color
			firingElement.originalPointColor= firingElement.style["backgroundColor"];
			
			
			
			
			firingElement.style["backgroundColor"]=dotBgColor;
			$("#"+pointId).css("background-color",cityBgColor);
			// if the mouse hovred the point = hilight the point and the right city
			
			
		}
		
	}	 
}

function displayResult(where,what)
{
	
		//$("body").append("<div id='bMap'><div id='myMaps'></div></div>");
		$("#franceMap").css("display","none");

		//map.setView({center:new Microsoft.Maps.Location(46.46140902,5.066554925)});
		$("#myMaps").css("display","block");

		$("#results_container").css("display","block");
		$("#results").css("display","block");

		
		$("#searchbar").attr("value", what);
		//currentActivityName = what;
		$.post('index.php/ajax/setMapView',
		{ 'ville':'jujurieux' , 'depNb':'01'},
		function(result) {
			// if there is a result, fill the list div, fade it in 
			// then remove the loading animation
			if(result) {
				
			
			    //alert(result);
				var infos = result.split(';'); // split on commas	
			
				OnPageLoad(infos[0],infos[1]);
				

			}
		});		
}

function restoreBgColor(myEvent,pointId,triggeredByCity)
{
	if (!myEvent)
	myEvent=window.event;
	if (!myEvent)
	return;
	var firingElement=null;
	// Internet Explorer
	if (myEvent.srcElement)
	firingElement=myEvent.srcElement;  

	// Netscape and Firefox
	else if (myEvent.target)
	firingElement=myEvent.target;    


	if (firingElement)
	{
		if (triggeredByCity == true)
		{
			
			firingElement.style["backgroundColor"]=firingElement.originalBgStyle;
			$(firingElement).css("opacity",firingElement.originalOpacity);
			$(firingElement).css({filter:"alpha(opacity="+firingElement.originalOpacity+")"});
			
			$("#"+pointId).css("background-color",firingElement.originalPointColor);
			
		} else {
		
		
			//restore point
				
			$(firingElement).css("background-color",firingElement.originalPointColor);
			
			// restore city
			$("#"+pointId).css("background-color",firingElement.originalBgStyle);
			$("#"+pointId).css("opacity",firingElement.originalOpacity);
			$("#"+pointId).css({filter:"alpha(opacity="+firingElement.originalOpacity+")"});
			
		}

	}	 
}

this.departementManager = function(){	

	xOffset = 50;
	yOffset = -30;


	$("div.departementManager,span.departementManager").click(function(e){

		$("#tooltip").remove();

		if ( this.ville == 'Fermer') {
			//tb_remove();

			$.fancybox.close();

		} else {


			//	tb_remove();
			$.fancybox.close();
			//$("body").append("<div id='bMap'><div id='myMaps'></div></div>");
			$("#franceMap").css("display","none");

			//map.setView({center:new Microsoft.Maps.Location(46.46140902,5.066554925)});
			$("#myMaps").css("display","block");

			$("#results_container").css("display","block");
			$("#results").css("display","block");

			//	$("#bMap").css("visibility","hidden");

			//	document.getElementById("txtQuery").value = this.ville;

			//	document.getElementById('depNb').value = this.depNb;

			this.depNb = $(this).attr("depNb");
			
		
			$.post('index.php/ajax/setMapView',
			{ 'ville':this.ville , 'depNb':this.depNb},
			function(result) {
				// if there is a result, fill the list div, fade it in 
				// then remove the loading animation
				if(result) {
					
					
					var infos = result.split(';'); // split on commas	
				
					OnPageLoad(infos[0],infos[1]);
					

				}
			});
			
		}

	});
	$("div.departementManager, span.departementManager").hover(function(e){		

		this.ville = $(this).attr("ville");
		this.visible = $(this).attr("visible");
		//alert($(this).attr("ville"));
		if (this.visible == '0'){ //opera//firefox

			this.t = this.ville;
			//this.nb = this.depNb;
			//this.alt = "";									  
			$("body").append("<p id='tooltip'>"+ this.t +"</p>");
			$("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");	

			if (this.ville == 'Fermer') {
				$("#back_france").attr("src","pictures/back_france_green.png");	
			}			

		}	

	},
	function(){
		if (this.visible == '0'){
			this.ville = this.t;		
		} else {
			//this.ville = "";

		}

		if (this.ville == 'Fermer') {
			$("#back_france").attr("src","pictures/back_france.png");	
		}
		$("#tooltip").remove();

	});	
	$("div.departementManager,span.departementManager").mousemove(function(e){

		if (this.ville == 'Fermer') {
			$("#back_france").attr("src","pictures/back_france_green.png");	
		}

		if (this.alt != ""){
			$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
		}
	});

};

