function faq_theme(data)
{
	$(".faq > p").unbind("click");
	$(".list_faq").empty().append(data);
	$(".faq > p").click(function(){$(this).parent().children(".otvet").toggle();});
}
function isEmail (email) {
	return (/^([a-z0-9_-]+.)*[a-z0-9_-]+@([a-z0-9][a-z0-9-]*[a-z0-9].)+[a-z]{2,4}$/i).test(email);
}
/*function myalert(data)
{
	alert(data);
}*/
function search(data)
{
	$(".result").show();

	if(data.length > 15)
	{
		$(".result div:first").empty().append(data);
		$(".result div:first div:first").addClass("first");
		$(".result div:first div").click(function(){
			window.location.href = $(this).children("a:first").attr("href");
		})
	}
	else
		$(".result").hide();
}

$(function(){

	// Общее
	$('.icons ul li')
		.eq(0).children().addClass("home").end()
		.eq(1).children().addClass("mail").end()
		.eq(2).children().addClass("map");
	$(".rebaks").hide();

	// Форма обратной связи
	$(".connect").submit(function(e){
		var mailtext = [], errors = [], form = $(this);
		e.preventDefault();
		$(this).find('.x-field').each(function(){
			var label = (
				$(this).attr('title')
					||
				($(this).parents('label').eq(0).children('b').text() || $(this).parents('p').eq(0).children('b').text()).replace(/[^\/\,a-zа-я ]/gi, '').replace(/\s+/g, ' ')
			), value;

			if (this.tagName.toLowerCase() === 'select') {
				value = $(this).find('option[value=' + $(this).val() + ']').text();
			} else if ($(this).attr('type') === 'radio') {
				value = form.find('input[type="' + $(this).attr('type') + '"][name="' + $(this).attr('name') + '"]').filter(':checked').parents('label').eq(0).text();
			} else {
				value = $(this).val();
			}

			if (this.className.match(/\brequired-field\b/) && !this.value) {
				errors.push(label);
			} else if (this.className.match(/\bemail-field\b/) && !isEmail(this.value)) {
				errors.push(label);
			}

			mailtext.push(['<p><b>', label, '</b>: ', value, '</p>'].join(''));
		});
		if (errors.length) {
			alert(['Не заполнены следующие поля:', errors.join("\n")].join("\n"));
		} else {
			$.post(
				$(this).attr('action'),
				{
					action: $(this).find('[name="action"]'),
					mailtxt: mailtext.join('')
				},
				function(res) {
					alert(res);
				}
			);
		}
	});

	//Прозрачность для осла
	try
	{
		$.ifixpng('/images/pixel.gif');
		$('div.menu a').ifixpng();
		$('div.grad').ifixpng();
	}
	catch(e) {}

	// Вопросы и ответы
	//$(".otvet").hide();
	//$(".faq > p").click(function(){$(this).parent().children(".otvet").toggle();});
	$(".theme").change(function(){$.post('/system/modules/ajax/faq.php',{theme: $(this).children("option:selected").attr("value")},faq_theme);});

	// Навигация
	//if ($(".pagenav .current").children("span").text() == 1){$(".pagenav .prev").html("<span>&#171;</span>");}else{$(".pagenav .prev").html("<a href=\"?page=" + ($(".pagenav .current").children("span").text() - 2) + $(".navigator").text() + "\">&#171;</a>");}
	//if ($(".pagenav .current").children("span").text() == $(".pagenav > ul > li:last").prev().children("span").text()){$(".pagenav .next").html("<span>&#187;</span>");}else{$(".pagenav .next").html("<a href=\"?page=" + ($(".pagenav .current").children("span").text() * 1) + $(".navigator").text() + "\">&#187;</a>");}

	// Поиск
	$(".search input").keyup(function(){
		vval = $(this).val();
		if (vval.length > 2)
		{
			$.post(
					'/system/modules/ajax/search.php',
					{text: $(this).val()},
					search
				);
		}
		else
		{
			$(".result").hide();
		}
	});

	// Валюта
	$(".euro").click(function(){$(".bg-check").animate({right : 158}, 300);$(".baks").removeClass("active");$(".euro").addClass("active");$(".reeuro").show();$(".rebaks").hide();})
	$(".baks").click(function(){$(".bg-check").animate({right : 114}, 300);$(".euro").removeClass("active");$(".baks").addClass("active");$(".reeuro").hide();$(".rebaks").show();})

	// Карусель
	$(".list .next").click(function(){
		if ($("#jcarousel").parent().parent().attr("class") == "gallery")
		{
			auto = 0;
		}
	})
	$(".list .prev").click(function(){
		if ($("#jcarousel").parent().parent().attr("class") == "gallery")
		{
			auto = 0;
		}
	})
});


	$(document).ready(function()
	{

		resizeWindow();
		$(window).bind('resize', function()
		{
			resizeWindow();
		});



	});


	function resizeWindow()
	{

		if($(".rightbg").width() >= 1280)
			$(".rightbg").css("width","1170px");

		if($(window).width() < 1280)
			global_w = $(window).width() - 110;
		else
			global_w = 1170;


		$(".rightbg").css("background-position",global_w + "px 0");

	}
	var auto = 1;
