/**
 * Плагин для построения календаря
 */
(function($){
	var methods = {
		// Функция инициализации
		init: function(){
			object = $(this);

			methods.loadWeather();

			return this;
		},
		draw: function(data){
			var img = '';
			if (data.tod==0){
				img = 'n.moon';
			}else{
				img = 'd.sun';
			}
			
			if (data.PHENOMENA.cloudiness==1) img += '.c2';
			if (data.PHENOMENA.cloudiness==2) img += '.c3';
			if (data.PHENOMENA.cloudiness==3) img += '.c4';

			if (data.PHENOMENA.precipitation==4) img += '.r2';
			if (data.PHENOMENA.precipitation==5) img += '.r4';
			if (data.PHENOMENA.precipitation==6) img += '.s2';
			if (data.PHENOMENA.precipitation==7) img += '.s2';
			if (data.PHENOMENA.precipitation==8) img += '.r4';

			if (data.PHENOMENA.spower==1) img += '.st';
			
			img += '.png';
			znak = '';
			if (data.TEMPERATURE.max>0)	znak = '+';
			
			object.html('<div class="weatherHeader">Погода от GISMETEO</div><div class="weatherContent"><div class="weatherCity">Ханты-Мансийск</div><div class="weatherState">Тюменская область / Россия</div><div class="weatherData"><div class="weatherTemp" style="background-image:url(\/images\/weather\/'+img+');">'+znak+data.TEMPERATURE.max+'°C</div><div class="weatherAddon"><div class="weatherDavlenie">'+data.PRESSURE.max+'<br /><span>мм рт. ст.</span></div><div class="weatherWind wind'+data.WIND.direction+'">'+data.WIND.max+'<br /><span>м/с</span></div></div><div class="clear"></div></div></div>');
		},
		loadWeather: function(){
			jQuery.post(
				'/api.post/structure_site.getWeather',
				'',
				function (data){
					methods.draw(data);
				},
				'json'
			);
		}
		
	}
	
	
	$.fn.weather = function ( method ) {
		if ( methods[method] ) {
		  return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
		  return methods.init.apply( this, arguments );
		} else {
		  $.error( 'Method ' +  method + ' does not exist on jQuery.calendar' );
		}
	};
	
})( jQuery );
