(function($){
	
		var horoscope_flag=false;
	
		function print_horoscope(day,sign,type) {
			try {
				var pars = {
					day: day,
					sign: sign,
					type: type
				};
				horoscope_flag=true;
				$('#horoscope-content').html('<img src="themes/fyru/css/images2/h_loader.gif" id="h-loader"/>');
				var options = {
						url: 'index.php?id=510',
						data: pars,
						dataType: 'json',
						timeout: 30000,
						async: true,
						success: function(data) {
							if (data.error==0) {
								$('#horoscope-content').html(data.horoscope);
								$('#h_day_0').html(data.yesterday);
								$('#h_day_1').html(data.today);
								$('#h_day_2').html(data.tomorrow);
								$('#h_day_3').html(data.tomorrow02);
							} else $('#horoscope-content').html('<span id="h_unknow">Нет данных</span>');
							if (type==2) $('#h_copyright').html('&copy; <a href="http://excimerclinic.ru">Клиника Эксимер</a>');
							else $('#h_copyright').html('&copy; <a href="http://ignio.ru">Ingio</a>');
							horoscope_flag=false;
						},
						error: function(data) {
							$('#horoscope-content').html('<span id="h_unknow">Нет данных</span>');
							horoscope_flag=false;
						}
				}
				$.ajax(options);
			} catch(e) {
			}		
		}
	
		$(function(){
			var day=1;
			var sign=0;
			var type=0;
			
			try {
				
				var cookie_h_sign = $.readCookie('h_sign');
				var cookie_h_type = $.readCookie('h_type');
				
				if (cookie_h_sign) sign = cookie_h_sign;
				if (cookie_h_type) type = cookie_h_type;
				
				$('#h_day_'+day).addClass('active');
				$('#h_sign_'+sign).addClass('active');
				$('#h_type_'+type).addClass('active');
				
				$('#horoscope-sign').bind('click',function(event) {
					if (horoscope_flag) return;
					var $target = $(event.target);
					if ($target.hasClass('h_sign') && !($target.hasClass('active'))) {
						$('#horoscope-sign .active').removeClass('active');
						$target.addClass('active');
						sign = $target.attr('sign');
						print_horoscope(day,sign,type);
						$.setCookie("h_sign", sign, {duration: 365});
					} 
				});
				
				$('#horoscope-days').bind('click',function(event) {
					if (horoscope_flag) return;
					var $target = $(event.target);
					if ($target.hasClass('h_day') && !($target.hasClass('active'))) {
						$('#horoscope-days .active').removeClass('active');
						$target.addClass('active');
						day = $target.attr('day');
						print_horoscope(day,sign,type);
					} 
				});
												
				$('#horoscope-type').bind('click',function(event) {
					if (horoscope_flag) return;
					var $target = $(event.target);
					if ($target.hasClass('h_type') && !($target.hasClass('active'))) {
						$('#horoscope-type .active').removeClass('active');
						$target.addClass('active');
						type = $target.attr('type');
						print_horoscope(day,sign,type);
						$.setCookie("h_type", type, {duration: 365});
					} 
				});
				
				print_horoscope(day,sign,type);
				
			} catch(e) {
			}				   
		});
		
})(jQuery);
