document.write('\x3Cscript type="text/javascript" src="http://content.worldnow.com/global/interface/httprequest/httprequest.js">\x3C/script>');

//Weather Branding Feature
var mainTimer;
function CSlaunchWx(){
	if($wn("#wxBrandFeatureOuter").length){
		$wn("#wxBrandFeatureOuter").remove();
	}
	var wxbf = "<div id='wxBrandFeatureOuter'><div id='csWXBF'><ul id='wxInfo'><li id='wxLoc'></li><li id='wxTemp'></li><li id='wxFeel' class='text'></li><li id='wxCond' class='text'></li><li id='wxHilo' class='text'></li></ul><a id='wxRSS' class='icon' href='http://www.nbc29.com/story/5466825/nbc29-rss-feeds' target='_blank'></a><a id='wxForum' class='icon' href='http://www.nbc29.com/link/399704/nbc29-forums' target='_blank'></a><a id='wxFB' class='icon' href='http://www.facebook.com/NBC29' target='_blank'></a><a id='wxTwitter' class='icon' href='http://twitter.com/nbc29' target='_blank'></a><a id='wxDoppler' class='button' href='http://www.nbc29.com/category/118266/weather-images-local-radar' target='_blank'><div>Doppler Radar</div><img src='http://admin.nbc29.com/Weather/wideDMA_website_thumb.JPG' /></a><a id='wx7Day' class='button' href='http://www.nbc29.com/category/89668/weather-images-7-day-forecast' target='_blank'><div>7 Day Forecast</div><img src='http://admin.nbc29.com/Weather/7_Day_thumb.jpg' /></a><a id='wxState' class='button' href='http://www.nbc29.com/category/89667/weather-images-state-radar' target='_blank'><div>State Radar</div><img src='http://admin.nbc29.com/Weather/state_satrad_thumb.jpg' /></a></div></div>";
	
	$wn("#WNDS70").hide();
	var wxint;
	var stationNum = 0;
	var wxStations = [];
	wxStations[0] = new Array("http://data.wp.myweather.net/eWxII/?data=*22902", "Charlottesville");
	wxStations[1] = new Array("http://data.wp.myweather.net/eWxII/?data=*22401", "Staunton");
	wxStations[2] = new Array("http://data.wp.myweather.net/eWxII/?data=*22974", "Fluvanna");	
	var wxLength = wxStations.length;
	var br_url = wxStations[stationNum][0];
	var wxSavedData = [];	
	
	for(dd=0;dd<wxLength;dd++){
		wxSavedData[dd] = [];
	}
	
	function CSwxInit(){
		CSbrWeatherFeed(this);
	}
	
	function CSbrWeatherFeed(xml){
		$wn("#wxBrandFeature").hide();
		var fullFeed = xml.response.responseXML;
		var testFeed = $wn(fullFeed).find("currents location temp").text();
		if (isNaN(parseInt(testFeed))){
			stationChange();
		} else {
		  wxSavedData[stationNum][0] = $wn(fullFeed).find("currents location temp").text();
		  wxSavedData[stationNum][1] = wxStations[stationNum][1];
		  wxSavedData[stationNum][2] = $wn(fullFeed).find("currents location feelslike").text();
		  wxSavedData[stationNum][3] = $wn(fullFeed).find("forecasts location days:first day:first forecast:first").attr("high");
		  wxSavedData[stationNum][4] = $wn(fullFeed).find("forecasts location days:first day:first forecast:first").attr("low");
		  wxSavedData[stationNum][5] = $wn(fullFeed).find("currents location sky").text();
		  
		  $wn("#csWXBF").hide();
		  $wn("#csWXBF #wxInfo #wxLoc").html(wxSavedData[stationNum][1]);
		  $wn("#csWXBF #wxInfo #wxTemp").html(wxSavedData[stationNum][0] + "&deg;");
		  $wn("#csWXBF #wxInfo #wxFeel").html("Feels like " + wxSavedData[stationNum][2] + "&deg;");
		  $wn("#csWXBF #wxInfo #wxHilo").html("Hi " + wxSavedData[stationNum][3] + " / Lo " + wxSavedData[stationNum][4]);
		  $wn("#csWXBF #wxInfo #wxCond").html(wxSavedData[stationNum][5]);
		  $wn("#csWXBF").show();
		}
	}
	
	function CSinputSavedData(num){
		$wn("#csWXBF").hide();
		$wn("#csWXBF #wxInfo #wxLoc").html(wxSavedData[num][1]);
		$wn("#csWXBF #wxInfo #wxTemp").html(wxSavedData[num][0] + "&deg;");
		$wn("#csWXBF #wxInfo #wxFeel").html("Feels like " + wxSavedData[num][2] + "&deg;");
		$wn("#csWXBF #wxInfo #wxHilo").html("Hi " + wxSavedData[num][3] + " / Lo " + wxSavedData[num][4]);
		$wn("#csWXBF #wxInfo #wxCond").html(wxSavedData[num][5]);
		$wn("#csWXBF").show();
	}
	
	function CSstationChange(){
		clearTimeout(wxint);
		wxint = setTimeout(CSstationChange, 5000);
		stationNum++;
		if(stationNum >= wxLength){ stationNum = 0; }
		br_url = wxStations[stationNum][0];
		if(!wxSavedData[stationNum].length){
			WNHttpRequestManager.makeRequest(br_url, { onSuccess: CSwxInit, onError: CSwxError});
		} else {
			CSinputSavedData(stationNum);
		}
	}
	
	function CSwxError(){}
	
	WNHttpRequestManager.makeRequest(br_url, { onSuccess: CSwxInit, onError: CSwxError});
	if(wxLength>1){
		wxint = setTimeout(CSstationChange, 5000);
		$wn("#WNBranding").append(wxbf);
	}	
}

$wn(document).ready(function(){
	CSlaunchWx();
});

