/**
*	Localize Language Code
*	2011.7.26
*	@see /common/scripts/config.js
*/

var lang = 0;


/* weather */
$ (function () {
	$ ("div#weather").load (
		"/en/sg/weather.html div.weather-content",
		null,
		function () 
		{
			$ ("div.weather-content p.close a").click (function () {
				$ ("div#global-navigation ul li.weather-toggle a").click ();
				return false;
			});
			
			$.getJSON(nps_url,
			 function(json){
			    //stuff to do after event occurs;		
				var colors = city2Col(json.cities);
				//alert(colors);

				//backgrounds inside both sides of page
				$('#gradient').find('.node').each(function(index, element) {

					$(element).gradient({
						from:      colors[index][0],
						to:        colors[index][1],
						direction: 'vertical'
					});
				});
				
				
				$('#weather_report').find('.weather').each(function(index, element) {
					
					
					$(element).find("#weth_cndt").text(tbl_repo[json.cities[index].weather.toString()][lang]);
					
					var tmp = json.cities[index].temp;
					if(tmp==null)tmp=nps_tmp_default;
					$(element).find("#weth_tmp").text(tmp);

				});
				
				$('#weather_report').find('.name').each(function(index, element) {
					
					
					$(element).html("<em>"+tbl_ctry[json.cities[index].nps_country][lang]+"</em>").append("<br/>").append(tbl_city[json.cities[index].nps_country][lang]);

				});
				
				$('#weather_report').find('.color').each(function(index, element) {
					
					$(element).css({'background-color' : "#"+tbl_col[tbl_wth[json.cities[index].weather]]});

				});
				
				$('#weather_report').find('.flag').each(function(index, element) {
					
					$(element).addClass('t'+json.cities[index].nps_country);

				});
				
				//weather report time
				var formatTime=json.request.time;
				$('#weather_report_time').find("span").text(formatTime);
				
				


				//fill edges
				$('#left').css({'background-color' : "#"+colors[0][0]});
				$('#right').css({'background-color' : "#"+colors[colors.length-1][1]});


			});
			
			
		}
	);
});
