function Velocimetro(){
	this.url = "./";
	
	this.initialize = function(){
		this.url = (arguments[0]) ? arguments[0] : "./";
		this.mesureSpeed();
	}
	
	this.mesureSpeed = function(){
		this.startCounter();
		this.getGarbageFile();
	}
	
	this.startCounter = function(){
		time=new Date();
		this.starttime=time.getTime();
	}
	
	this.endCounter = function(){
		time=new Date();
		endtime=time.getTime();
		if (endtime==this.starttime){
			downloadtime=0
		} else {
			downloadtime=(endtime-this.starttime)/1000;
		}
		
		kbytes_of_data = this.ajax.getResponseHeader("Content-Length")/1024;
		
		linespeed=kbytes_of_data/downloadtime;
		
		//velocidade de conexao
		this.kbps=(Math.round((linespeed*8)*10*1.024))/10;
		
		this.ksec=Math.round(this.kbps * 8,2);
		this.mbps=Math.round(this.ksec/1024,2);
		this.msec=Math.round(this.ksec /8,2);
		
		this.writeResults();
	}
	
	this.getGarbageFile = function(){
		time=new Date();
		footime=time.getTime();
		url = this.url+'lixo_velocimetro.html?foo='+footime;
		
		this.ajax = new AJAX();
		this.ajax.url = url;
		this.ajax.metodo = "GET";
		
		var pai = this;
		this.ajax.processaResultado = function(){
			pai.endCounter();
		}
		
		this.ajax.onerror = function(e){
			alert(e);
		}
		
		this.ajax.conectar();
	}
	
	this.calcBaixa = function(tam,kbps){
		if(kbps){
			speed=(kbps * 1024);
			bits=8;
			calc=(tam * bits);
			
			/* Divide os bits pela Velocidade do Modem*/
			mins=(calc/ speed);
			
			/* Calcula 0h:00m*/
			h_m=Math.floor(mins/ 3600);
			
			/* Calcula 0m:00m*/
			m_m=Math.floor(mins/ 60);
			
			/* Calcula 0m no caso de horas*/
			hm_m=Math.round((mins%3600)/ 60);
			
			s_m=Math.round(mins%60);
			
			if (h_m>0){
				modem=h_m+'h:'+hm_m+'m';
			} else if(m_m>0){
				modem=m_m+'m:'+s_m+'s';
			} else if (s_m>0){
				modem=s_m+'s';
			} else {
				modem='menos de 1s';
			}
			return modem;
		} else {
			return 0;
		}
	}
	
	this. writeResults = function(){
		var v=Math.round(this.kbps)+" KB/segundo";
		var x=this.ksec+" kbps";
		
		alert("Taxas: "+x+" ("+v+")");
	}
}