// JavaScript Document
//Ajax.flXHRproxy.registerOptions("http://leganavalemeteo.dyndns.org",{instancePooling:true,autoUpdatePlayer:true,xmlResponseText:false,loadPolicyURL:"http://leganavalemeteo.dyndns.org:51101/crossdomain.xml"});
Ajax.flXHRproxy.registerOptions("http://85.41.62.19",{instancePooling:true,autoUpdatePlayer:true,xmlResponseText:false,loadPolicyURL:"http://85.41.62.19/crossdomain.xml"});
var oldvalueGust = 0;
var oldvalueAverage = 0;
var urlLogger = 'http://85.41.62.19/windraw.txt';
var arrow_dir='../images/wra-';
var ext = '.png';
var arrowImage;
var oldWindDirText = "";

//var urlLogger = "http://leganavalemeteo.dyndns.org:51101/meteohtml.cgi?file=windraw";
var counterSecs = 0;

		function update() {
			// Some Ajax code or whatever to get live data....
			// Your live values/data go here.
			
			var opzioni = {
				method: 'get',
				frequency: 10,
				decay: 1,
				onSuccess: function(transport){
      							var windResponse = transport.responseText.split(" "); 
								if (windResponse[1] == "wind0") {
               						
									var windAvg = parseFloat(windResponse [4]);//get the values....
									var windGust = parseFloat(windResponse [3]);
									var windDir = windResponse [2];
									var windDirText = windResponse [6];	
									arrowImage = arrow_dir + windDirText + ext;
									
									document.iogauge.SetVariable("avg_in_value", oldvalueGust);// Set the gauges value...
									document.iogauge.SetVariable("avg_out_value", oldvalueAverage);
									
									document.iogauge.SetVariable("in_value", windGust); 
									document.iogauge.SetVariable("out_value", windAvg);
									
									document.dpgaugenew.SetVariable("dValue", windDir);
									
									if (!arrowoverlay) { arrowoverlay = new rosaOverlay(bounds, arrowImage, map);} //set first arrow...
									else if (windDirText != oldWindDirText) { //if wind shifted then redraw arrow....
										arrowoverlay = arrowoverlay.setMap(); 
										arrowoverlay = new rosaOverlay(bounds, arrowImage, map);
									}
									
									
									oldvalueGust = windGust; //remember old values
									oldWindDirText = windDirText;
									oldvalueAverage = windAvg;
									counterSecs = 0; // reset counter....
                				}
      							//alert("Success! \n\n" + response);
    						},
    			onFailure: function(){ alert('Something went wrong...') }
			  };
			new Ajax.PeriodicalUpdater('livevals', urlLogger, opzioni);
			
		}
		
		//Event.observe(window, 'load', update);
		
