$(document).ready(function()
{
	//Инициализация галлереи
	$('.gallery a').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.4,
		imageLoading: '../images/lightbox-ico-loading.gif',
		imageBtnClose:'../images/lightbox-btn-close.gif',
		imageBtnPrev: '../images/lightbox-btn-prev.gif',
		imageBtnNext: '../images/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Изображение',
		txtOf: 'из'
	});

	// Ф-ия обработки раскрытия менюшек
	$("div.quick_menu").hover(
		function() {
			switch ($(this).find("div.border_container").attr("id")) {
				case "151":
					$(this).find("div.inner_box").css("background-color", "#075700");
					$(this).find("b").css("background-color", "#075700");
					break;
				case "152":
					$(this).find("div.inner_box").css("background-color", "#88380f");
					$(this).find("b").css("background-color", "#88380f");
					break;
				case "154":
					$(this).find("div.inner_box").css("background-color", "#464a05");
					$(this).find("b").css("background-color", "#464a05");
					break;
				case "254":
					$(this).find("div.inner_box").css("background-color", "#c94820");
					$(this).find("b").css("background-color", "#c94820");
					break;
				case "153":
					$(this).find("div.inner_box").css("background-color", "#67135c");
					$(this).find("b").css("background-color", "#67135c");
					break;
				case "156":
					$(this).find("div.inner_box").css("background-color", "#28007a");
					$(this).find("b").css("background-color", "#28007a");
					break;
				case "222":
					$(this).find("div.inner_box").css("background-color", "#115e68");
					$(this).find("b").css("background-color", "#115e68");
					break;
			}
			$(this).find("div.border_container").show(150);
		},
		function(){
			$("div.second_level").hide();
			$(this).find("div.border_container").hide(150);
		}
	);

	$("div.inner_box a").hover(
		function() {
			if ($(this).attr("href") == "/yellowpages/") {
				$("div.second_level").show();
			}
			else {
				$("div.second_level").hide();
			}
		},
		function() {
		}
	);

	//Обработка выбора даты (поиск)
	$('#date-box').datepicker({
		dateFormat:'yy-mm-dd',
		onSelect:function(date) {
			//alert('Вы выбрали дату: ' + date);
			//$('#date-box-text').text(date);
			//$('#full_date').val(date);
			document.location = '/news/?do=search_news&full_date='+date;
		}
	});

	//Обработка фокуса поля "поиск"
	$("input[name='search_text']")
		.css('color', '#999999')
		.focus(function()
		{
			if ($(this).val()=='Поиск по новостям') $(this).val('');
			$(this).css('color', '#000000');
		})
		.blur(function()
		{
			if ($(this).val()=='') $(this).val('Поиск по новостям');
			$(this).css('color', '#999999');
		});

	//Обработка фокуса поля "e-mail"
	$("input[name='email']")
		.css('color', '#999999')
		.focus(function()
		{
			if ($(this).val()=='Электронный адрес') $(this).val('');
			$(this).css('color', '#000000');
		})
		.blur(function()
		{
			if ($(this).val()=='') $(this).val('Электронный адрес');
			$(this).css('color', '#999999');
		});

	//Обработка фокуса поля "Имя"
	$("input[name='name']")
		.css('color', '#999999')
		.focus(function()
		{
			if ($(this).val()=='Имя') $(this).val('');
			$(this).css('color', '#000000');
		})
		.blur(function()
		{
			if ($(this).val()=='') $(this).val('Имя');
			$(this).css('color', '#999999');
		});

	//Обработка фокуса текстового поля
	$("textarea[name='text']")
		.css('color', '#999999')
		.focus(function()
		{
			if ($(this).val()=='Текст сообщения') $(this).val('');
			$(this).css('color', '#000000');
		})
		.blur(function()
		{
			if ($(this).val()=='') $(this).val('Текст сообщения');
			$(this).css('color', '#999999');
		});
});

/*
 * Определение типа браузера
 */
function output_choice(x1, x2, x3)
{
	if (browser.isFirefox || browser.isOpera || browser.isSafari) document.write(x1);
	else if (browser.isIE)
	{
		if (browser.isIE55up) document.write(x2);
		else document.write(x3);
	}
}

/*
 * Функция раскрытия планки новостей офисов по туризму
 */
function open_panel()
{
	if (document.getElementById('country').style.display=='none')
	{
		document.getElementById('corner').style.background='url(\"/images/f_right_mid.gif\") no-repeat bottom right';
		document.getElementById('corner').innerHTML='<img width=\"6\" height=\"6\" src=\"/images/f_left_mid.gif\"/>';
		document.getElementById('country').style.display='block';
	}
}

/*
 * Функция закрытия планки новостей офисов по туризму
 */
function close_panel()
{
	if (document.getElementById('country').style.display=='block')
	{
		document.getElementById('corner').innerHTML='<img width=\"6\" height=\"6\" src=\"/images/corner_fill_bottom_left.gif\"/>';
		document.getElementById('corner').style.background='url(\"/images/corner_fill_bottom_right.gif\") no-repeat bottom right';
		document.getElementById('country').style.display='none';
	}
}

/*
 * Функция проверки переполнения
 */

function check_overflow()
{
	if (i==(max-0)) i=0;
}

/*
 * Функция подстановки бегущей строки
 */
function change_line()
{
		document.getElementById('line_text').innerHTML='<marquee id=\'slide_text\' behavior=\'slide\' direction=\'up\' scrollamount=\'1\' scrolldelay=\'128\' height=\'22px\' width=\'512px\'>'+text_in_line[i]+'</marquee>';
		i++;
		check_overflow();
		setTimeout('change_line()',5000);
}

/*
 * Проверка e-mail
 */
function check_subscribe_form()
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.subscribe_form.email.value)) document.subscribe_form.submit();
	else
	{
		alert('Введите корректный e-mail');
		document.subscribe_form.email.value='';
		document.subscribe_form.email.focus();
	}
}

/*
 * Проверка формы обратной связи
 */
function check_feedback_form()
{
	var msg="";

	if (document.feedback_form.name.value=='Имя' || document.feedback_form.name.value=='') msg+='\n • Введите Ваше имя';
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.feedback_form.email.value))) msg+='\n • Введите корректный e-mail';
	if (document.feedback_form.text.value=='Текст сообщения' || document.feedback_form.text.value=='') msg+='\n • Введите текст сообщения';

	if (msg!='') alert('Исправьте следующие ошибки:\n'+msg);
	else document.feedback_form.submit();
}

/*
 * Проверка формы вопросов
 */
function check_question_form()
{
	var msg="";

	if (document.question_form.name.value=='Имя' || document.question_form.name.value=='') msg+='\n • Введите Ваше имя';
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.question_form.email.value))) msg+='\n • Введите корректный e-mail';
	if (document.question_form.text.value=='Текст сообщения' || document.question_form.text.value=='') msg+='\n • Введите текст сообщения';

	if (msg!='') alert('Исправьте следующие ошибки:\n'+msg);
	else document.question_form.submit();
}