var jq =
{
	jQuery:jQuery.noConflict(),
	events:{}
}

function change_month($y, $m)
{
	var text = '';
	var mon = '';
	var url = jq.jQuery('#href').val();
	var archive = jq.jQuery('#show_archive').val();

	if (archive)
	{
		url += '?show_archive=1';
	}
	
	jq.jQuery.ajax
	({
			type: "POST",
			url: url,
			data: "year="+$y+"&month="+$m,
			dataType:'json',
			success: function(msg)
			{
				text = '<table cellpadding="0" cellspacing="0" border="0"><tr class="month"><td><a href="javascript:change_month('+msg.prev_year+', '+msg.prev_month+');">««</a></td><td colspan="5">';
				switch (msg.month_text)
				{
					case 0:mon='Январь'; break;
					case 1:mon='Февраль'; break;
					case 2:mon='Март'; break;
					case 3:mon='Апрель'; break;
					case 4:mon='Май'; break;
					case 5:mon='Июнь'; break;
					case 6:mon='Июль'; break;
					case 7:mon='Август'; break;
					case 8:mon='Сентябрь'; break;
					case 9:mon='Октябрь'; break;
					case 10:mon='Ноябрь'; break;
					case 11:mon='Декабрь'; break;
				}
				text += mon;
				text += ' '+msg.year_text+'</td><td><a href="javascript:change_month('+msg.next_year+', '+msg.next_month+');">»»</a></td></tr><tr class="week"><td>П</td><td>В</td><td>С</td><td>Ч</td><td>П</td><td>С</td><td>В</td></tr>';
				var i = 0;
				var j = 0;
				for (i = 0; i < msg.week.length; i++)
				{
					text += '<tr>';
					for (j = 0; j < msg.week[i].length; j++)
					{
						if (msg.events[msg.week[i][j]])
						{
							text += '<td'+(msg.cur_day==msg.week[i][j] ? ' class="curent"' : '')+'><a href="index.php?date='+msg.week[i][j]+'.'+msg.cur_month+'.'+msg.cur_year+(archive ? '&show_archive=1' : '')+'">'+msg.week[i][j]+'</a></td>';
						}
						else
						{
							text += '<td'+(msg.cur_day==msg.week[i][j] ? ' class="curent"' : '')+'>'+msg.week[i][j]+'</td>';
						}
					}
					text += '</tr>';
				}
				text += '</table>';
				jq.jQuery('#calendar').html(text);
			}
	});
}

jq.events.reloadable=
{
	init: function()
	{

	}
}

jq.events.proceed=
{
	/*Инициализация обработчиков*/
	init: function()
	{
		jq.jQuery(document).ready(function()
		{
			jq.jQuery('a.lightbox').lightBox(
			{
				imageLoading: '/img/lightbox-ico-loading.gif',
				imageBtnClose: '/img/lightbox-btn-close.gif',
				imageBtnPrev: '/img/lightbox-btn-prev.gif',
				imageBtnNext: '/img/lightbox-btn-next.gif'
			}
			);
			/*Собственно события*/
			jq.jQuery('.menu_item').click(jq.events.proceed.show_menu);
			jq.jQuery('#calendar_toggle').click(jq.events.proceed.toggle_calendar);
			jq.jQuery('.menu div').live('mouseenter', jq.events.proceed.show_menu);
			jq.jQuery('.menu div').live('mouseleave', jq.events.proceed.hide_menu);
			jq.jQuery('#search').focus(jq.events.proceed.search_focus);
			jq.jQuery('#search').blur(jq.events.proceed.search_focus_lost);
		});
	},
	
	/*Код обработчиков*/
	
	search_focus_lost : function (e)
	{
		var value = jq.jQuery(this).val();

		if (value == '')
		{
			jq.jQuery(this).val('Поиск по сайту');
		}
	},
	
	search_focus : function (e)
	{
		var value = jq.jQuery(this).val();

		if (value == 'Поиск по сайту')
		{
			jq.jQuery(this).val('');
		}
	},
	
	toggle_calendar : function (e)
	{
		e.preventDefault();
		jq.jQuery('#calendar').toggle();
	},
	
	show_menu : function (e)
	{
		jq.jQuery(this).children('ul').fadeIn(600);
	},
	
	hide_menu : function (e)
	{
		jq.jQuery(this).children('ul').fadeOut(600);
	}
}

//jq.events.reloadable.init();
jq.events.proceed.init();
