//window.onload = initWview;
var xmlhttp
var first_run = false;
var wview = [];
  wview[0] = "stationTime";
  wview[1] = "outsideHumidity";
  wview[2] = "windDirection";
  wview[3] = "windSpeed";
  wview[4] = "outsideDewPt";
  wview[5] = "barometer";
  wview[6] = "windDirectionDegrees";
  wview[7] = "rainRate";
  wview[8] = "dailyRain";
  wview[9] = "baromtrend";
  wview[10] = "stationDate";
  wview[11] = "outsideTemp";
  wview[12] = "outsideHeatIndex";
  
  
  

$(document).ready(function(){   getWV();  });

//$("#outsideTemp").click(function() {
//$(this).slideUp();
//$("#showChart").html("<img src='../dev1/temp.png'></img>");
//});

/*
$(".leftRadar").click(function() {
//$(this).slideUp();
$("#showChart").html("<img src='http://radblast-mi.wunderground.com/cgi-bin/radar/WUNIDS_map?station=MLB&brand=wui&num=1&delay=15&type=N0R&frame=0&scale=1.000&noclutter=0&t=1246297005&lat=27.19614029&lon=-80.21172333&label=Stuart%2C+FL&showstorms=0&map.x=400&map.y=240&centerx=400&centery=240&transx=0&transy=0&showlabels=1&severe=0&rainsnow=0&lightning=0&smooth=0'></img>");
});
*/
//$("#progressbar").progressbar({ value: 37 });






function getWV(){
jQuery.getJSON('../dev1/wviewData.php', { format: "json", time: new Date().getTime()}, updateWV );
//
//alert("here");
setTimeout(getWV, 10 * 1000);
}

function updateWV(wvD) {
//alert(wvD.wviewVersion);
var wvDate = new Date(wvD.stationDate*1000);//wvDate = wvDate.toDateString();
var wvDatePA = (wvDate.getHours() >= "12")?"PM":"AM";
var wvLocations = new Array ("wxMainSt","wxSm");
var ot = "";
var oh = "outsideHumidity";
var cls;
var wvDateFull = (wvDate.getMonth()+1)+"/"+wvDate.getDate()+"/"+wvDate.getFullYear()+" "+((wvDate.getHours() > 12)?(wvDate.getHours()-12):(wvDate.getHours()))+":"+((wvDate.getMinutes() < 10)?"0"+wvDate.getMinutes():wvDate.getMinutes())+" "+((wvDate.getHours() >= "12")?"PM":"AM");

  for (cls in wvLocations)
{

    jQuery("."+wvLocations[cls] + "> #outsideTemp").html(wvD.outsideTemp+"&#xB0;F");
    jQuery("."+wvLocations[cls] + "> #outsideHumidity").html(wvD.outsideHumidity+"%");
    jQuery("."+wvLocations[cls] + "> #barometer").html(parseFloat(wvD.barometer).toFixed(2)+"&#x8B;in&#x9B;");
    jQuery("."+wvLocations[cls] + "> #windSpeed").html(wvD.windSpeed+"&#x8B;mph&#x9B;");
    jQuery("."+wvLocations[cls] + "> #windSpeedDir").html(wvD.windSpeed+"&#x8B;mph&#x9B; "+wvD.windDirection);
    jQuery("."+wvLocations[cls] + "> #windDirection").html(wvD.windDirection+"&#x8B;mph&#x9B; &#xBB; ");
    jQuery("."+wvLocations[cls] + "> #outsideDewPt").html(wvD.outsideDewPt+"&#xB0;F");
    jQuery("."+wvLocations[cls] + "> #rainRate").html(wvD.rainRate+"&#x8B;in/hr&#x9B;");
    jQuery("."+wvLocations[cls] + "> #dailyRain").html(wvD.dailyRain+"&#x8B;in&#x9B;");
    jQuery("."+wvLocations[cls] + "> #totalRain").html(wvD.totalRain+"&#x8B;in&#x9B;");
    jQuery("."+wvLocations[cls] + "> #monthlyRain").html(wvD.monthlyRain+"&#x8B;in&#x9B;");
    jQuery("."+wvLocations[cls] + "> #baromtrend").html(wvD.baromtrend);
    jQuery("."+wvLocations[cls] + "> #outsideHeatIndex").html(wvD.outsideHeatIndex+"&#xB0;F");
}

//jQuery("#stationDate").html(function () {var wvDate = new Date(wvD.stationDate); return wvDate.toDateString()});


jQuery("#stationDate").html( wvDateFull);
//jQuery("#stationDate").append(wvD.stationDate);
/*
jQuery(".wvD > #").html(wvD.);
jQuery(".wvD > #").html(wvD.);
jQuery(".wvD > #").html(wvD.);
jQuery(".wvD > #").html(wvD.);
*/
//setTimeout(getWV(), 60 *1000);
}
function setWviewData() { }

function setWviewData(wvData,location){}


 
/*
function initWview()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
getData();
  }
  function getData()
  {

var url="../dev1/wviewData.php";  

 for (var j=0;j<wview.length;j++){
	if (j==0)
	{
	url=url+"?wview"+j+"="+wview[j]+"&";
	}
	else
	{
	url=url+"wview"+j+"="+wview[j]+"&";
	}
	}
url=url+"length="+wview.length;

xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.send(null);



setTimeout(getData,60 * 1000);
}
function resetColor()
{
    if (!first_run){
	
	for (var j=0;j<wview.length;j++){
/*   
  
	try{
		document.getElementById(wview[j]).style.color="black";
		
	}
	catch(e){
	continue;
	}
}

//$(".leftWx2").css("color","blue");
//$(".wviewDate").css("color","white");
//$("#"+wview[j]).css("color","yellow");
jQuery("#"+wview[j]).removeClass("dataUpdate");
}
}

}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  
  var result=xmlhttp.responseText;
  //alert(result);
  var wvData = result.split(",");
  //alert(wvData);
  //document.getElementById("temp1").innerHTML=escape(wvData[0]);
   for (var j=0;j<wview.length;j++){
   
   if (first_run){
	try{
	document.getElementById(wview[j]).innerHTML=wvData[j];   
	}
	catch(e){
	continue;
	}
   }
   else{
   
	try{
	if	(document.getElementById(wview[j]).innerHTML!=wvData[j]){
		document.getElementById(wview[j]).innerHTML=wvData[j];
		jQuery("#"+wview[j]).addClass("dataUpdate");
		//document.getElementById(wview[j]).style.color="red";
		setTimeout(resetColor,5000);   
		}
	}
	catch(e){
	continue;
	}
   }
   }

   first_run = false;
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
*/


