﻿Ext.namespace("TwentyFour.Scripts.Weather");

TwentyFour.Scripts.Weather.Forecast7DayManager = function()
{
    var _renderToLocation;

     function forecast7DayCallBack(response)
     {   
        var panel = $(_renderToLocation);
        
        if (response.error === null && response.value != null)
        {
            var data = response.value;
            var forecast7DayTemplate = new Ext.XTemplate(
            '<div class="forecast7DayContainer">\
            <tpl for="Forecasts">\
                <div class="forecast7DayBlock">\
                    {WeekDay}<br/>\
                    <img src="Images/Icons/Forecasts/{Icon}.gif" /><br/>\
                    {LowTemp}&#176;C - {HighTemp}&#176;C\
                </div>\
            </tpl>\
            </div>',{index: 0}
            );
            
            forecast7DayTemplate.overwrite(panel,data);
        }
         else
            panel.update('No 7 Day Forecast is available for this area. Please select another city and try again.');
     }

    return {
        
        showDetail : function(cityId, renderLocation){    
            _renderToLocation = renderLocation;
            $(_renderToLocation).update('<img src="Images/loading.gif"/>&nbsp;loading...');
            TwentyFour.Weather.Web.Ajax.GetForecast7Day(cityId, forecast7DayCallBack);
        }
    };
};