var noticies = new Array();

var noticies_vel = 2;
var rellotge;

function inicia_noticies(){

	for( var i = 0; i < noticies.length; i++ ){
		noticies[i][1] = document.getElementById( "not_text" + ( i + 1 ) );
		noticies[i][2] = 0;
	}
	
	/*S'estableix l'ordre inicial*/
    
    for( var j = 1; j < noticies.length; j++ ){
    	noticies[j][2] = noticies[(j-1)][2] + noticies[(j-1)][1].offsetWidth;
    }
  	
	for( var l = 0; l < noticies.length; l++ ){
		noticies[l][1].style.left = noticies[l][2] + "px";
	}
	/*****************************/
	
	var visor = document.getElementById( "not_visor" );
	
	visor.onmouseover = function(){
		window.noticies_vel = 0;
	}
	
	visor.onmouseout = function(){
		window.noticies_vel = 2;
	}
	
	window.rellotge = setTimeout( "mou_noticies()", 1000 );
}

function mou_noticies(){
    
    var referencia = 0;
    	
   	for( var i = 0; i < noticies.length; i++ ){
   		
    	if( ( noticies[i][2] <= 0 ) && ( noticies[i][2] > ( noticies[i][1].offsetWidth * -1 ) ) ) referencia = i;
    }
    
    noticies[referencia][2] = noticies[referencia][2] - window.noticies_vel;
    
    for( var j = ( referencia + 1 ); j < noticies.length; j++ ){
    
    	noticies[j][2] = noticies[(j-1)][2] + noticies[(j-1)][1].offsetWidth;
    }
    
    for( var k = 0; k < referencia; k++ ){
    
    	if( k == 0 ){
    		noticies[k][2] = noticies[(noticies.length - 1)][2] + noticies[(noticies.length - 1)][1].offsetWidth;
    	}else{
    		noticies[k][2] = noticies[(k-1)][2] + noticies[(k-1)][1].offsetWidth;
    	}
    }
		
	for( var l = 0; l < noticies.length; l++ ){
	
		noticies[l][1].style.left = noticies[l][2] + "px";
	}
	
	window.rellotge = setTimeout( "mou_noticies()", 50 );
}
