function WeatherControl()
{
	this.Width = 273;
	this.SliderWidth = 15;
	this.ActiveTime = 0;
	this.Periods = new Array();
}

WeatherControl.prototype = new GControl();

WeatherControl.prototype.SetTime = function () {
	var posX = Math.round(parseFloat(this.Slider.left) / parseFloat(18)) * 18
	this.ActiveTime = parseInt(posX / 18);
	this.SliderDiv.style.left =  (posX + 3) + "px";
	this.Slider.left = posX;
	document.getElementById("WeatherTime").innerHTML = this.Periods[this.ActiveTime].Date + " " + this.Periods[this.ActiveTime].Time;
	GEvent.trigger(this, "timeset");
}

WeatherControl.prototype.initialize = function (map) {

	var that = this;
			
	//Render
	var divContainer = document.createElement("div");
	divContainer.className = "GWeatherSliderContainer";
	divContainer.style.width = this.Width + "px";
		
	var div = document.createElement("div");
	div.className = "GWeatherSlider";
	div.style.width = this.SliderWidth + "px";
	divContainer.appendChild(div);
	
	var div2 = document.createElement("div");
	div2.id = "WeatherTime";
	div2.className = "GWeatherTime";
	divContainer.appendChild(div2);
	
	this.Slider = new GDraggableObject(div, {left:3,top:15,container:divContainer});
	this.SliderDiv = div;
	this.Container = divContainer;
	
	map.getContainer().appendChild(divContainer);
	
	GEvent.addListener(this.Slider, "dragend", function() {that.SetTime()});

	GDownloadUrl("/smhi/periods.aspx", function(data, responseCode) {that.Periods_Callback(data, responseCode)});
	
	return divContainer;
}

WeatherControl.prototype.Periods_Callback = function (data, responseCode)
{
		if (responseCode == 200)
		{
			var xml = GXml.parse(data);
			var periods = xml.documentElement.getElementsByTagName("period");
			var prevDay = "";
			for (var i = 0; i < periods.length; i++)
			{
				var date = periods[i].childNodes[0].data.split(" ")[0];
				var time = periods[i].childNodes[0].data.split(" ")[1];
				var day = periods[i].getAttribute("day");				
				if (day != prevDay)
				{
					//Render				
					var div = document.createElement("div");
					div.className = "GWeatherDay";
					div.innerHTML = day;
					div.style.left = (i * 18 + 3) + "px";
					this.Container.appendChild(div);
					prevDay = day;
				}
				//Push
				this.Periods.push({WeekDay:day,Date:date,Time:time});
			}						
		}	
}

WeatherControl.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(5, 20)); }

WeatherControl.prototype.printable = function() { return false; }

WeatherControl.prototype.selectable = function() { return false; }