
var refresh = 30 //seconds timer

function tajmer() {
	var nesto = setTimeout(function(){
		getJSON();
		tajmer();
	}, refresh * 1000);
}

$(document).ready(function(){
	tajmer();
});

/**
 *
 * @access public
 * @return void
 **/
function getJSON(){
	// path defined in main layout
	$.getJSON(path+'/'+unix_time(), null, function(json) {

		// temperature
		$('#box_temperatura .podatak').html( json['data']['temperature'] + '°C' );
		$('#box_subj_temperatura .podatak').html( json['data']['wind_chill'] + '°C' );

		//pritisak
		$('#box_pritisak .podatak').html( json['data']['barometer'] + ' mb' );

		//vlaznost
		$('#box_vlaznost .podatak').html( json['data']['humidity'] + '%' );

		// vetar
		$('#box_vetar .podatak').html( json['data']['gust_windspeed'] + ' km/h' );
		$('#box_vetar #vetar_smer').css( 'background-position', json['smer_vetra_ikona'] + ' 0' );
		$('#box_vetar #vetar_opisno').html( json['smer_vetra_tekst'] );

		// vreme podataka
		$('#vreme_podataka .podatak').html( json['vreme_podataka'] );

	} );
}

function unix_time() {
	var now = new Date();
	return parseInt(now.getTime().toString().substring(0,10));
}
