function change_legend(num) {
		var de=document.getElementById("legend_depth");
		var ma=document.getElementById("legend_mag");
		if(num==0) {de.style.display="block"; ma.style.display="none"; change_to_depth(); }
		else {de.style.display="none"; ma.style.display="block"; change_to_mag(); }
		//alert(num);
	}
	
	
	function change_to_mag() {
		var mg=0;
		var colooo="";
		for (var i=0;i<tab_p.length ;i++) {
			mg=(Math.floor(tab_p[i].mag)+diff_mag);
			colooo=document.getElementById("CL_"+mg).style.backgroundColor;
			//if(i==2) alert(colooo);
			tab_p[i].element.className="CL_"+mg+" iebug";
			tab_p[i].element.style.backgroundColor=colooo;
		}	
	}	
	
	function change_to_depth() {
		var n="";
		var colooo="";
		for (var i=0;i<tab_p.length ;i++) {
			n=tab_p[i].cl_ori.substr(3,tab_p[i].cl_ori.length);
			colooo=document.getElementById("CL_"+n).style.backgroundColor;
			tab_p[i].element.className=tab_p[i].cl_ori;
			tab_p[i].element.style.backgroundColor=colooo;
		}
	}	
	function change_cumul(num) {
		if(num==0) cumul=true;
		else cumul=false;
	}	
	function change_interval(num) {
		if(num==0) current_interval=day_interval;
		else current_interval=hour_interval;
	}	
	
	var mag_min=1; var mag_max=10; var depth_min=0; var depth_max=1000;
	
	var current_time=time_end;
	var current_interval=day_interval;
	var cumul=true;
	var run_stop=false;
	var is_start=true;
	var speed=513; //min=50 max=2000
	var anim_is_stop=true;

	function run() {	
		
			anim_is_stop=false;
			if((!cumul) || is_start) {is_start=false; hide_all();}
			update_time();
			var ln=tab_p.length;
			for (var i=0;i<ln ;i++) {
				if((tab_p[i].time >= current_time)&&(tab_p[i].time <= (current_time+current_interval))) {
					if(((tab_p[i].mag >= mag_min) && (tab_p[i].mag <= mag_max)) && ((tab_p[i].depth >= depth_min) && (tab_p[i].depth <= depth_max))) {
						if(tab_p[i].element.style.visibility=="hidden") {
							nb_on_map++;
							tab_p[i].element.style.visibility="visible";  
						}	
					}
				}	
			}
			current_time=current_time+current_interval;
			set_nb_earthquakes();
			if((current_time < time_end) && run_stop) setTimeout("run()",speed);
			else anim_is_stop=true;
	}
	
	function set_nb_earthquakes() {
		document.getElementById("nb_earthq").innerHTML=nb_on_map+lab_nb;
	}	

	function hide_all() {
		var ln=tab_p.length;
		for (var i=0;i<ln ;i++) {
			tab_p[i].element.style.visibility="hidden";
		}
		nb_on_map=0;
		set_nb_earthquakes();
	}
	
	function hide_specific(begin,end) {
		var ln=tab_p.length;
		for (var i=0;i<ln ;i++) {
			if((tab_p[i].time >= begin)&&(tab_p[i].time <= end)) {
					if(tab_p[i].element.style.visibility=="visible") {
						nb_on_map--;
						tab_p[i].element.style.visibility="hidden"; 
					}	
			}
		}	
		set_nb_earthquakes();
	}
	
	function show_all_evt() {
		//nb_on_map=0;
		var ln=tab_p.length;
		for (var i=0;i<ln ;i++) {
			if(((tab_p[i].mag >= mag_min) && (tab_p[i].mag <= mag_max)) && ((tab_p[i].depth >= depth_min) && (tab_p[i].depth <= depth_max)))  {
					if(tab_p[i].element.style.visibility=="hidden") {
						nb_on_map++;
						tab_p[i].element.style.visibility="visible"; 
					}	
			}
		}	
		set_nb_earthquakes();
	}
	
	function start_all() {
		run_stop=true;
		if(current_time>=time_end) {is_start=true; current_time=time_begin; hide_all();}
		run(); 
	}	
	function stop() { run_stop=false; }
	function prev() { 
		run_stop=false; 
		var new_time=current_time-(2*current_interval); 
		if(time_begin <= new_time) {
			is_start=false;
			hide_specific(new_time,current_time); 
			current_time=new_time; 
			run(); 
		}	
	}
	function next() { 
		run_stop=false; 
		if(current_time < time_end) {is_start=false; run(); }
	}
	function reset() { 
		stop();
	//	alert("here");
		var f = new Date().dateFormat("Y-m-d H:i:s","", new Date(time_end+diff_js_php));
			//alert("here2");
		document.getElementById("my_datetime").innerHTML=f+" UTC";
	
		current_time=time_end; 
		wait_end();
		
	}
	function wait_end() {
		if(anim_is_stop) { 	
			show_all_evt(); 
			is_start=true; 
		}
		else setTimeout("wait_end()",200);
	}	
	
	function update_time() {
		var date=new Date((current_time+current_interval)+diff_js_php);
		var f = new Date().dateFormat("Y-m-d H:i:s","", date);
		document.getElementById("my_datetime").innerHTML=f+" UTC";
	}	
	
	/*** equation
		50(vitesse max)=A* 100 (max curseur) +B
		2000 (vitesse min)=A * 0 (min curseur) +B
	****/	
	function SLIDER_MOVE(slider_val) {
		var B=2000;
		var A=-19.5;
		speed=(slider_val*A)+B;
	}
	
	function modif_sett(typ,val) {
		val=parseFloat(val);
	if((typ=="mag_min")&&(val>=0)&&(val<=10)) mag_min=val;	
	else if((typ=="mag_max")&&(val>=1)&&(val<=10)) mag_max=val;	
	else if((typ=="depth_min")&&(val>=0)&&(val<=1000)) depth_min=val;	
	else if((typ=="depth_max")&&(val>=1)&&(val<=1000)) depth_max=val;	
	
	efface_spec();
	}	
	
	function efface_spec() { 
		for (var i=0;i<tab_p.length ;i++) {
			if((tab_p[i].mag < mag_min)||(tab_p[i].mag > mag_max)||(tab_p[i].depth < depth_min)||(tab_p[i].depth > depth_max)) {
				if(tab_p[i].element.style.visibility=="visible") {
					nb_on_map--;
					tab_p[i].element.style.visibility="hidden";  
				}	
			}
		}	
		set_nb_earthquakes();
	}	
