
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'] );


/*
		var trt = json['grafikon_temp'];
		var i = 0;
		for (x in trt) {
			gdata.setValue(i++,1,parseFloat(trt[x]));
		}
		chart.draw(gdata, {width: 150, height: 60, title: '', legend: 'none', lineWidth: 1, pointSize: 0, curveType: 'function', chartArea: {top:2, width:150, height: 48}});
*/
	} );
}

function unix_time() {
	var now = new Date();
	return parseInt(now.getTime().toString().substring(0,10));
}

