

t = null;

initTxtLigne = function(){
	var milliseconds = refreshTime*1000;
	t=setTimeout("afficherTxtLigne()",milliseconds);
	
	var element = jQuery('.scroll-pane').jScrollPane({showArrows:true,autoReinitialise:true});
	var api = element.data('jsp');
	api.reinitialise();
}

afficherTxtLigne = function(){
	

	if($('#etat_service').hasClass('fr')){
		var urlMsg = "http://www.stm.info/AffichageDynamiqueSTMInfo/InterMetro.aspx?noLigne=1&lang=F";
		$('#etat_service_help').text('La STM diffuse les interruptions de service de plus de 20 minutes.');
	}else{
		var urlMsg = "http://www.stm.info/AffichageDynamiqueSTMInfo/InterMetro.aspx?noLigne=1&lang=E";
		$('#etat_service_help').text('The STM post service disruptions lasting 20 minutes and more.');
	}
	
	$.ajax({
		url:urlMsg,
		data: '',
		dataType: 'jsonp',
		type: 'GET',
		
		success:function(data){
			
		aLignes = data.body.split('|');
		
		t_orange(aLignes[3],aLignes[2]);
		t_verte(aLignes[1],aLignes[0]);
		
		t_jaune(aLignes[5],aLignes[4]);
		t_bleu(aLignes[7],aLignes[6]);
		t_ascenceurs(aLignes[8]);
		initTxtLigne();
	}});
	
}
t_help = function(f){
	
	$('#etat_service_help').text(f);
}
t_ascenceurs = function(f,b){
	
	$('#etat_service_ascenseurs .in p').text(f);
	
	var words = $('p.ascen').text().split(' '); 

	var html = ''; 
	var bln= -1;
    $.each(words, function() {
		//alert(this[0]);
		if (this.charAt(0) == '(')
			bln=0;
			
		if (this == '*')
			{
			bln=0;
			}
			
		if (this == ':')
			bln=1;
	
		if (bln == 1)
			{
			html += this + ' '; 
			}
		else if (bln == 0)
			{
			if (this == '*')
				{
				html += '<br /><br />'; 
				}
			else
				html += '<span style="font-weight:bold">'+this+'</span>'+ ' '; 
			}
		else
			{
			html += this + ' '; 
			}
		
	}); 
	$('p.ascen').html(html); 
	
	/*if(b != ""){
		$('#etat_service_ascenseurs .see_more').text(b);
		$('#etat_service_ascenseurs').addClass('more');
		setMouseOver('on',$('#etat_service_ascenseurs.on'));
	}else{
		$('#etat_service_ascenseurs').removeClass('more');
		setMouseOver('off',$('#etat_service_ascenseurs.on'));
	}*/
}

t_verte = function(f,b){
	
	$('#etat_service_metro #green .etat_bottom').text(f);
	
	if(b != ""){
		$('#etat_service_metro #green .see_more').text(b);
		$('#etat_service_metro #green .see_more').html('<span>' + b + '</span>');
		$('#etat_service_metro #green').addClass('on');
		setMouseOver('on',$('#etat_service_metro #green'));
	}else{
		$('#etat_service_metro #green').removeClass('on');
		setMouseOver('off',$('#etat_service_metro #green'));
	}
	$('#etat_service_metro #green .etat_bottom').html('<span>' + f + '</span>');
	/*$('#etat_service_metro #green .etat_bottom').html('<span>' + 'Aucune interruption importante' + '</span>');*/
	
}
t_orange = function(f,b){
	
	$('#etat_service_metro #orange .etat_bottom').text(f);
	
	if(b != ""){
		$('#etat_service_metro #orange .see_more').text(b);
		$('#etat_service_metro #orange .see_more').html('<span>' + b + '</span>');
		$('#etat_service_metro #orange').addClass('on');
		setMouseOver('on',$('#etat_service_metro #orange'));
	}else{
		$('#etat_service_metro #orange').removeClass('on');
		setMouseOver('off',$('#etat_service_metro #orange'));
	}
	$('#etat_service_metro #orange .etat_bottom').html('<span>' + f + '</span>');
}
t_jaune = function(f,b){
	
	$('#etat_service_metro #yellow .etat_bottom').text(f);
	
	if(b != ""){
		$('#etat_service_metro #yellow .see_more').text(b);
		$('#etat_service_metro #yellow .see_more').html('<span>' + b + '</span>');
		$('#etat_service_metro #yellow').addClass('on');
		setMouseOver('on',$('#etat_service_metro #yellow'));
	}else{
		$('#etat_service_metro #yellow').removeClass('on');
		setMouseOver('off',$('#etat_service_metro #yellow'));
	}
	$('#etat_service_metro #yellow .etat_bottom').html('<span>' + f + '</span>');
}
t_bleu = function(f,b){
	
	$('#etat_service_metro #blue .etat_bottom').text(f);
	
	if(b != ""){
		$('#etat_service_metro #blue .see_more').text(b);
		$('#etat_service_metro #blue .see_more').html('<span>' + b + '</span>');
		$('#etat_service_metro #blue').addClass('on');
		setMouseOver('on',$('#etat_service_metro #blue'));
	}else{
		$('#etat_service_metro #blue').removeClass('on');
		setMouseOver('off',$('#etat_service_metro #blue'));
	}
	$('#etat_service_metro #blue .etat_bottom').html('<span>' + f + '</span>');
}

setMouseOver = function(etat,who){
	
	if(etat == 'on'){
		$(who).bind('mouseenter', function(){
			$(this).find('.see_more').show();
		}).bind('mouseleave', function(){
			$(this).find('.see_more').hide();
		});
	}else{
		$(who).unbind('mouseenter');
	}


}
