var weatherxml = initajax();
var timeoutid = false;
function getweatherdata(){
	weatherxml = initajax();
	if(weatherxml!=false){
		if(timeoutid!=false){
			clearTimeout(timeoutid);
		}
		weatherxml.onreadystatechange=parseweather;
		weatherxml.open("GET","/xml/xml.xml",true);
		weatherxml.send(null);
	};
};

function parseweather(){
	if(weatherxml.readyState==4){
		var xml=weatherxml.responseXML;
		var weather = document.getElementById("weather");
		var tags = weather.getElementsByTagName('span');
		for(i=0;i<tags.length;i++){
			var tag = tags[i];
			var t_id = tag.getAttribute("class");
			var tree = t_id.split("-");
			var leaf = xml.getElementsByTagName("weatherdata").item(0);
			for(var j in tree){
				sub = tree[j];
				leaf = leaf.getElementsByTagName(sub).item(0);
			}
			var thedata = leaf.firstChild.data;
			tag.innerHTML = thedata;
		}
	/*
		if(window.updatewindgraph){
			var wind = xml.getElementsByTagName("weatherdata").item(0).getElementsByTagName("wind").item(0);
			window.updatewindgraph(wind.getElementsByTagName("direction").item(0).getElementsByTagName("degrees").item(0).firstChild.data, wind.getElementsByTagName("current").item(0).firstChild.data, wind.getElementsByTagName("unit").item(0).firstChild.data);
			document.getElementById("graphs").style.visibility = "visible"
		};
*/
		
		timeoutid = setTimeout('getweatherdata()',60000);
	};
}
function initajax(){
	var xmlHttp;
	try{
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
};