var serverURL

//populates weather controls for pages that get screen scraped headers
$(document).ready(function(){
         $.getJSON(serverURL + "/Controls/Weather/WeatherJSON.ashx?jsoncallback=?", 
         function(data)
         {   
             //set variables
             var City = data.city;
	         var Temp = data.temp;
             var Cond = data.cond;
             var Sponsor = data.spon;
             var SponsorURL = data.sponURL;
             var Image = data.image;
             
             //make sure the URL entered contains http:// if not add it
             if (!SponsorURL.match("http://")){
                SponsorURL = "http://" + SponsorURL;
             }
             //grab the npURL for long range forecasts
             var Url = serverURL + "/weather.aspx";
  
             if(City != "" && Temp != "" && Cond != "")
			 {
			    var root = $('<div id="Weather1_Weather"><div id="newWeatherContainer" style="float:right;"></div></div>');    
			    var WeatherTop = $('<a id="weatherTop" href="'+ Url + '" title="' + City + '"></a>');
			    var TempAndImage = $('<div id="tempNum">' + Temp + '<img src="' + serverURL + '/images/degree-cel.gif" alt="Celcius"></img></div>');   
                var CondImage = $('<div id="weatherDetail"><img src="' + serverURL + Image + '" alt="' + Cond + '" />');
                var CondCity = $('<div id="weatherDetailText"><div class="clearLine" />' + City + '<div class="clearLine" /><div id="weatherCondition">' + Cond + '</div>');
                var WeatherBottom = $('<div id="weatherBottomFilled"></div>');
                var WeatherSponsor = $('<span style="font-size:12px;"><a href="' + SponsorURL + '" target="_blank" title="' + Sponsor + '">' + Sponsor + '</a></span>');   
                var Spacer = $('<div class="spacer" />');
                    $("#" + find_div_class()).append(root);    
                    $("#newWeatherContainer").append(WeatherTop);
                    $("#newWeatherContainer").append(WeatherBottom);
                    $("#weatherTop").append(TempAndImage);
                    $("#weatherTop").append(CondImage);
                    $("#weatherDetail").append(CondCity);
                    $("#weatherBottomFilled").append(WeatherSponsor);
                    $("#" + find_div_class()).after(Spacer);
             }
		});
     });
	 
	 function find_div_class() 
	 {
        var divCollection = document.getElementsByTagName("div");
        
        for (var i = 0; i < divCollection.length; i++) 
        {
            if(divCollection[i].getAttribute("id") == "lbWeather") {
                return divCollection[i].getAttribute("id");
            }
            else if(divCollection[i].getAttribute("id") == "ctl00_lbWeather") {
                return divCollection[i].getAttribute("id")
            }
        }
    }