var EE = {
	weather: {
		init: function() {
			EE.weather.run();
		},
		run: function() {
			$.get('weather.php', {}, function(response) {
				data = $.parseJSON(response);
				$container = $('#wb_weather_container');
				$('#wb_weather_icon img', $container).attr('src', 'images/weathericons/'+data.condition.code+'.png');
				$('#wb_weather_temp p.wb_weather_maxmin', $container).html(data.forecast.high+'&deg;C | '+data.forecast.low+'&deg;C');
				$('#wb_weather_info p.wb_weather_cond', $container).html(data.condition.text);
				$('#wb_weather_info p.wb_weather_wind', $container).html('wind '+data.wind.speed+'km/h'+data.wind.direction);

				$container.css({'visibility':'visible'});
			});
		}
	},

	news: {
		vars: {
			current:0,
			total:0,
			timer:null
		},
		init: function(options) {
			$.get('news.php', {}, function(response) {
				$container = $('#wb_news');
				data = $.parseJSON(response);
				EE.news.vars.total = data.length;

				$.each(data, function(i, el) {
					$('ul#wb_news_feed', $container).append('<li><a href="'+el.link+'" target="_blank">'+el.title+'</a></li>').hover(EE.news.pause, EE.news.resume);
				});

				EE.news.rotate();
			});
		},
		rotate: function() {
			if((EE.news.vars.current + 1) == EE.news.vars.total) {
				EE.news.vars.current = 0;
			}

			$('#wb_news ul#wb_news_feed li:eq('+EE.news.vars.current+')').show();
			$('#wb_news ul#wb_news_feed li:not(:eq('+EE.news.vars.current+')):visible').hide();

			EE.news.vars.current++;

			$('#wb_news_container').css({'visibility':'visible'});
			EE.news.resume();
		},
		pause: function() {
			clearTimeout(EE.news.vars.timer);
		},
		resume: function() {
			EE.news.pause();
			EE.news.vars.timer = setTimeout('EE.news.rotate()', 4000);
		}
	}
};
