﻿function fixedTime(t){
	var add=0;
	if(t.search('pm') > 0) add = 1200;
	tm = t.substring(0,t.length-2).split(':');
	tr = Number(tm[0]+tm[1]) + add;
	return tr;
}
function grab(feed) {
	var w = feed.value.items[0];
	$('#we_cond').html(w.condition.text);
	$('#we_temp').html(w.condition.temp + "&#176;" + w.units.temperature);
	$('#we_like').html(w.wind.chill + "&#176;" + w.units.temperature);
	$('#we_humi').html(w.atmosphere.humidity + "%");
	$('#we_wind').html(w.wind.speed  + " " + w.units.speed);
	
	// check day or night
	var cur_time = w.condition.date.substring(17,w.condition.date.length-3);
	var curAst="d";
	if(fixedTime(cur_time)>fixedTime(w.astronomy.sunrise) && fixedTime(cur_time)<fixedTime(w.astronomy.sunset)) curAst="n";
	
	// set the image
	$('#we_img').attr({ 
		  src: "http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/"+w.condition.code+curAst+"s.png",
		  title: w.condition.text,
		  alt: w.condition.text
	});
	// $(document).pngFix();
}

