jQuery(function( $ ){
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'xy';
	
	$.localScroll({
		duration:1000,
		hash:false,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
//--------------------------------------------------gallery----------------------	
	$("a.zoom").fancybox({
				'titleShow'		: false
	});
//--------------------------------------------------form_validate----------------------	
	// проверка телефона
	var phone_filter = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]{7,}$/;
	$.validator.methods.phone = function(value, element, param) {
		return phone_filter.test(value);
	};
	// создаем картинку загрузки
	var loader = $('<div id="loader"><img src="images/wait_bottom.gif" alt="loading..." /></div>')
		.addClass('clear')
		.css("text-align", "right")
		.hide();
	// форма контактов
	$("#contact_form").validate({
		rules: {
			contact_email: { 
				required: true,
				email: true
			},
			contact_phone: { 
				required: true,
				phone: true
			},
			contact_message: { 
				required: true,
				minlength: 10
			},
			contact_antispam: { 
				required: true,
				equalTo: "#contact_expect"
			}
		},
		messages: {
			contact_email: { 
				required: "Вы не указали свой email!",
				email: "Укажите правильный email!"
			},
			contact_phone: {
				required: "Вы не указали свой телефон!",
				phone: "Это точно телефон?"
			},
			contact_message: { 
				required: "Ваше сообщение очень короткое!",
				minlength: "Напишите пару слов..."
			},
			contact_antispam: { 
				required: "Вроде не сложная задачка, Вы точно не робот?",
				equalTo: "Достаточно ввести цифру..."
			}
		},
		errorLabelContainer: $('div#result'),
		errorElement: "p",
		errorClass: "no",
		submitHandler: function(form) {
			loader.appendTo($('#contact_form').parent().get(0));
			$(form).ajaxSubmit({
				target: '#contact_form',
				replaceTarget: true,
				data: { ajax: '1' }
			});
		}
	});
	
	// форма заказа
	$("#order_form").validate({
		rules: {
			task: { 
				required:true,
				minlength: 5
			},
			budget: { 
				required:true,
				minlength: 5
			},
			vision_message: { 
				required: true,
				minlength: 10
			},
			order_antispam: { 
				required: true,
				equalTo: "#order_expect"
			},
			order_email: { 
				required: true,
				email: true
			},
			order_phone: { 
				required: true,
				phone: true
			}
		},
		messages: {
			task: { 
				required: "Вы не определили задачу сайта!",
				minlength: "Что-то надо написать..."
			},
			budget: { 
				required: "Вы не указали бюджет!",
				minlength: "Что-то надо написать..."
			},
			vision_message: { 
				required: "Вы ничего не написали о проекте!",
				minlength: "Напишите пару слов..."
			},
			order_antispam: { 
				required: "Вроде не сложная задачка, Вы точно не робот?",
				equalTo: "Достаточно ввести цифру..."
			},
			order_email: { 
				required: "Вы не указали свой email!",
				email: "Укажите правильный email!"
			},
			order_phone: {
				required: "Вы не указали свой телефон!",
				phone: "Это точно телефон?"
			}
		},
		errorLabelContainer: $('div#result'),
		errorElement: "p",
		errorClass: "no",
		submitHandler: function(form) {
			loader.appendTo($('#order_form').parent().get(0));
			$(form).ajaxSubmit({
				target: '#order_form',
				replaceTarget: true,
				data: { ajax: '1' }
			});
		}
	});
	
	$().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
	}).ajaxError(function(a, b, e) {
		throw e;
	});

});
