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")
            }
        }
    }
    /*
    //comscore begins
    var __cs_c1 = 2;
    var __cs_c2 = "3005667";
    var __cs_c3 = "3005667";
    var __cs_c4 = escape(window.location.href);
    var __cs_c5 = MyGenericTagVar.prop22;
    var __cs_c6 = "";
    var __cs_c15 = "";
    var __cs_params = ["c1=", __cs_c1, "&c2=", __cs_c2, "&c3=", __cs_c3, "&c4=", __cs_c4, "&c5=", __cs_c5, "&c6=",
__cs_c6, "&c15=", __cs_c15].join('');
    document.write(unescape("%3Cscript src='" + (document.location.protocol == "https:" ? "https://sb" : "http://b") +
".scorecardresearch.com/beacon.js?" + __cs_params + "' %3E%3C/script%3E"));
    //comscore ends
    */
