Statistic_wl = function(name){
	this.name      = name;
	this.str       = '';
	this.status    = 0;
	this.statistic = [];
	this.stat_wrd_arr = [];
	this.speed     = 0;
	this.fld_text  = null;
	this.fld_line  = null;
	this.fld_word  = null;
	this.wrds_by_speed = {'very_fast_words':'','fast_words':'','slow_words':'','very_slow_words':''};
	this.wrds_sorted_by_speed = [];
};


Statistic_wl.prototype.Reset = function(node){
	
	if(statistic_mods[typeTyping]){ 	
		this.wrds_by_speed = {'very_fast_words':'','fast_words':'','slow_words':'','very_slow_words':''};
		this.stat_wrd_arr = [];
	}
	this.statistic     = [];
	this.str       = '';
	this.status    = 0;	
	this.speed     = 0;
};

Statistic_wl.prototype.Start = function(){
	this.status = 1;	
	this.statistic[this.statistic.length] = {'startTime':(new Date()).getTime()};
	
}; 

Statistic_wl.prototype.Stop = function(){
	if(this.status == 0)return;
	
	
	this.status = 0;
	var i = this.statistic.length - 1;

	var ts = ((new Date()).getTime() - this.statistic[i].startTime);		
	var dt = new Date(ts);
	var _s = dt.getSeconds();
	
	var mls=  dt.getMilliseconds();
	
	var seconds = parseFloat(_s +"."+ (mls<100?'0'+mls:mls));
    
	if(dt.getMinutes() > 0)seconds += dt.getMinutes() * 60;
	this.str = this.str.replace(/&nbsp;/g, ' ');
	
	this.seconds = seconds;
	this.speed  			 = parseInt(this.str.length / (seconds / 60));
	
	this.statistic[i].word   = this.str;
	this.statistic[i].speed  = this.speed;
	
	//this.fld_word.innerHTML   = this.statistic[i].speed;
	this.str    = '';
	 
}; 

Statistic_wl.prototype.Break = function(){
	this.status = 0;		
	this.str    = '';
	this.statistic.pop();	
};

Statistic_wl.prototype.getBySpeed = function(){
	if(this.stat_wrd_arr.length != 0)return this.stat_wrd_arr;
	var a = '';
	var _cmp = function (a,b) { 
		if (a.speed<b.speed)  return -1;
		if (a.speed>b.speed)  return 1;
		return 0;	
	};	
	this.statistic.sort(_cmp);
	
	for(a in this.statistic){
		this.stat_wrd_arr[a] = this.statistic[a];
	}		
	return this.stat_wrd_arr;
};
function GetWordsBySpeed(speed){
	
	// Если массив уже заполнен
	if(wrds_by_speed){
		return wrds_by_speed[speed];
	}
	
	// Функция сортировки по скорости
	var arr_wrds = ws_w.getBySpeed();
	//ws_w.statistic.reverse();
	
	wrds_by_speed = {'very_fast_words':'','fast_words':'','slow_words':'','very_slow_words':''};
	var tmp_arr = [], w = '';
	var speeds  = ['very_fast_words','fast_words','slow_words','very_slow_words'];
	var j       = 0,
		text    = '',
		str     = '',
		wrd_arr = [],
		divider = 0;
	
	
	for(w in arr_wrds){
		tmp_arr[tmp_arr.length] = arr_wrds[w].word;
	}
	divider = Math.round(tmp_arr.length / 4);
	
	var j       = 0,
		text    = '',
		str     = '',
		wrd_arr = [],
		divider = Math.round(tmp_arr.length / 4);
	
	// Сортируем по 4рем скоростям. 
	for(var i=0; i<4; i++){	      
	       for(var j=0;  j<divider; j++){	
	            var t = tmp_arr.pop(); 
	            if(t)str += t;
	       }
	       wrds_by_speed[speeds[i]] = str;	       
	       str ='';
	}
	while(tmp_arr.length > 0){
		wrds_by_speed['very_slow_words'] = wrds_by_speed['very_slow_words']+tmp_arr.pop();
	}
	
	for(var x in wrds_by_speed){
		   str = wrds_by_speed[x];	
	       str = RemoveDuplicates(str);
	       str = StrSortByLength(str,'DESC').join(' ');
	       wrds_by_speed[x] = str; //AddDividerToString(str);		  
	}
	
	return wrds_by_speed[speed];
	  
		
};

function GetLinesBySpeed(speed){
	
	// Если массив уже заполнен
	if(lines_by_speed){
		return lines_by_speed[speed];
	}
	
	// Функция сортировки по скорости
	var arr_lines = ws_l.getBySpeed();
	//ws_w.statistic.reverse();
	
	lines_by_speed = {'very_fast_words':'','fast_words':'','slow_words':'','very_slow_words':''};
	var tmp_arr = [], w = '';
	var speeds  = ['very_fast_words','fast_words','slow_words','very_slow_words'];
	var j       = 0,
		text    = '',
		str     = '',
		wrd_arr = [],
		divider = 0;
	
	
	for(w in arr_lines){
		tmp_arr[tmp_arr.length] = arr_lines[w].word;
	}
	//tmp_arr = tmp_arr.reverse();
	var j       = 0,
		text    = '',
		str     = '',
		wrd_arr = [],
		divider = Math.round(tmp_arr.length / 4);
	
	// Сортируем по 4рем скоростям. 
	for(var i=0; i<4; i++){	      
	       for(var j=0;  j<divider; j++){	
	            var t = tmp_arr.pop(); 
	            if(t)str += t;
	       }
	       lines_by_speed[speeds[i]] = str;	       
	       str ='';
	}
	while(tmp_arr.length > 0){
		lines_by_speed['very_slow_words'] = lines_by_speed['very_slow_words']+tmp_arr.pop();
	}
	
	return lines_by_speed[speed];
	  
		
};

