var lastCurrent=0;

function zpracujPrubeh(text){
  if(text){
    data = json_parse(text);
    document.getElementById('progress_bar').style.width=395*(data['current']/data['total'])+"px";
	ob = 'Celkem hotovo <strong>'+round((data['current']/data['total'])*100,1)+'%</strong> - '+round(data['current']/1048576,2)+' z '+round(data['total']/1048576,2)+' MB<br />';
	if(lastCurrent > 0) {
      rychlost = (data['current']-lastCurrent)/2;
	  ob += 'Uplynulý čas: ' + time_format(data['elapsed']) + '; Zbývá cca ' + time_format((data['total']-data['current'])/rychlost) + '<br />';
	  ob += 'Rychlost nahrávání: <strong>' + round(rychlost/1024,0) + '</strong> kB/s ('+round(rychlost/1024,0)*8+'kbps)<br />';
	}
	ob += 'Soubor: ' + maxLength(data['filename'],40) + '<br />';
	if(data['done']==1){
	  bezi=false;
	  if(data['cancel_upload'] > 0){
	    ob += '<br /><span style="color: #ff0000"><strong>Nahrávání bylo přerušeno!</strong></span>';
	  }
	}
	lastCurrent = data['current'];
	document.getElementById('upload_info').innerHTML = ob;
  }
}

function maxLength(text, delka){
  if(text.length>delka){
    return text.substr(0, delka) + '...';
  } else {
    return text;
  }
}

function time_format(sekund){
  if(sekund > 3600){
    hodin = Math.floor(sekund / 3600);
	minut = Math.round((sekund - (hodin * 3600))/60);
	return hodin + 'h, ' + minut + 'min';
  } else {
    minut = Math.floor(sekund / 60);
	rel_sekund = Math.round(sekund - (minut * 60));    
	return minut + 'min, ' + rel_sekund + 's';
  }
}



function round(cislo, desmist){
  if(desmist==0){
    return Math.round(cislo);
  } else {
    return Math.round(cislo * (desmist*10)) / (desmist*10);
  }
}
