			(function($) {
				$(function() {
					/* [Управляем панелью в футере] */
					function bottomPanel() {
						var _panel = $('#bottom_panel'),
							_panel_height = _panel.find('div:eq(0)').outerHeight(true),
							_panel_btn = $('#quick_search'),
							_footer = $('#footer'),
							_footer_height = _footer.outerHeight(true) + parseInt($('#container').css('padding-bottom')),
							_panel_close = $('#btmpanel_close'),
							_toggle = true,
							_timer = 400;
						_panel.css({
							'visibility': 'visible',
							'height': '0px',
							'opacity': '0',
							'bottom': '0px'
						});
						
						_panel_btn.bind('click', function() {
							if(_toggle) {
								_panel.css({
										'visibility': 'visible'
									}).animate({
									'bottom': _footer_height + 'px'

								}, _timer / 2, function() {
								
								}).delay(_timer / 4).animate({
									'height': _panel_height,
									'opacity': 1.0										
								}, _timer);
							} else {
								_panel.animate({
									'height': 0 + 'px',
									'opacity': 0.0										
								}, _timer, function() {
									_panel.css({
										'visibility': 'hidden'
									});
								}).delay(_timer / 2).animate({
									'bottom': 0 + 'px'
								}, _timer);
							}
							_toggle = !_toggle;
						});
						_panel_close.bind('click', function() {
							if(!_toggle) {
								_panel.animate({
									'height': '0px',
									'opacity': 0.0										
								}, _timer, function() {
									_panel.css({
										'visibility': 'hidden'
									});
								}).delay(_timer / 2).animate({
									'bottom': '0px'
								}, _timer);
								_toggle = !_toggle;
							}
						});
					}
					bottomPanel();
					/* [/Управляем панелью в футере] */
					/* [Выводим рандомное фото в заголовке] */
					var randomnumber = Math.floor(Math.random()*10); var random = '';
					switch(randomnumber) {
						case 0: case 1: case 2: case 3: random = 'picture_1'; break;
						case 4: case 5: case 6: case 7: random = 'picture_2'; break;
						case 8: case 9: case 10: default: random = 'picture_3'; break;
					}
					$('body').eq(0).addClass(random);
					/* [Скроллинг новостей на главной странице] */
					var index_news_block = $('#index_news_block'),
						index_news_scrlelm = index_news_block.find('li'),
						index_news_len = index_news_scrlelm.size(),
						index_news_height = index_news_block.find('ul').height(),
						current_index = 0,
						next_index = 0,
						timer = 0;
					index_news_scrlelm.css({
						'position': 'absolute'
					});
					index_news_scrlelm.not(':eq(0)').css({
						'top': -1 * index_news_height
					});
					function animate_news() {
						if(next_index < (index_news_len - 1)) {
							next_index += 1;
						} else {
							next_index = 0;
						}
						index_news_scrlelm.eq(next_index).animate({
							'opacity': 1.0,
							'top': 0
						}, {'easing': 'linear', 'queue': false, 'duration': 600, 'complete': function() {
							
						}});
						index_news_scrlelm.eq(current_index).animate({
							'opacity': 0.0,
							'top': index_news_height
						}, {'easing': 'linear', 'queue': false, 'duration': 600, 'complete': function() {
							$(this).css({
								'top': -1 * index_news_height
							});
						}});
						clearTimeout(timer);
						timer = 0;
						timer = setTimeout(animate_news, 5000);
						current_index = next_index;
					}
					if(index_news_len > 1) {
						animate_news();
					}
					
					/* [/Скроллинг новостей на главной странице] */
					/* [Проверка форм контента] */
					$('form.checkform').validate();				
					$("a[rel=example_group]").fancybox({
						'opacity'			: true,
						'overlayShow'		: true,			
						'transitionIn'		: 'elastic',
						'transitionOut'		: 'elastic',
						'titlePosition' 	: 'outside',
						'showCloseButton'	: true,
						'padding'			: 10,
						'overlayColor'		: '#111111',
						'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
							return '<span id="fancybox-title-over">' + (title.length ? '' + title : '') + '</span>';
						}
					});
					/* [Увеличение фото] */
					$('.zoom_photo').fancybox({
						'opacity'			: true,
						'overlayShow'		: true,			
						'transitionIn'		: 'elastic',
						'transitionOut'		: 'elastic',
						'titlePosition' 	: 'outside',
						'showCloseButton'	: true,
						'padding'			: 10,
						'overlayColor'		: '#111111',
						'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
							return '<span id="fancybox-title-over">' + (title.length ? '' + title : '') + '</span>';
						}
					});
					/* [/Увеличение фото] */
					/* [Переключение вкладок в каталоге кратко/подробно] */
					if($('#noactive').length > 0 && $('#active').length > 0 && $('.short_list').length > 0 && $('.long_list').length > 0) {
						$('.long_list').hide();
						$('#active').bind('click', function() {
							$('#noactive').removeClass('noactive').addClass('active');
							$('#active').removeClass('active').addClass('noactive');
							$('.long_list').show();
							$('.short_list').hide();
						});
						$('#noactive').bind('click', function() {
							$('#noactive').removeClass('active').addClass('noactive');
							$('#active').removeClass('noactive').addClass('active');
							$('.long_list').hide();
							$('.short_list').show();
						});						
					}
					/* [/Переключение вкладок в каталоге кратко/подробно] */
					/* [Клик на ссылке "Увеличить фото"] */
					$('.zoom').bind('click', function() {
						$('.zoom_photo').click();
					});	
					/* [Всплывающее окно с видео] */
					$('.zoom_video').each(function(index) {
						$(this).fancybox({
							'opacity'			: true,
							'content'           : $(this).attr('ret'),
							'overlayShow'		: true,			
							'transitionIn'		: 'elastic',
							'transitionOut'		: 'elastic',
							'titlePosition' 	: 'outside',
							'showCloseButton'	: true,
							'padding'			: 10,
							'overlayColor'		: '#111111',
							'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
								return '<span id="fancybox-title-over">' + (title.length ? '' + title : '') + '</span>';
							}
						});
					});
					/* [/Всплывающее окно с видео] */
					/* [Всплывающее окно с формой авторизации] */

					$('a.input').each(function(index) {
						$(this).fancybox({
							'hideOnContentClick': false,
							'titleShow'         : false,
							'transitionIn'		: 'none',
							'transitionOut'		: 'none',
							'autoScale'     	: false,
							'width'				: 320,
							'height'			: 360,
							'scrolling'   		: 'no',
							'showCloseButton'	: true,
							'padding'			: 10,
							'overlayColor'		: '#111111'
						});
						/*
						$(this).fancybox({
							'titleShow'     : false,
							'transitionIn'		: 'none',
							'transitionOut'		: 'none',
							'autoScale'     	: false,
							'width'				: 320,
							'height'			: 360,
							'scrolling'   		: 'no',
							'showCloseButton'	: true,
							'padding'			: 10,
							'overlayColor'		: '#111111'
							,'content'           : $('#authorize_form').html().clone().children('input[type=submit]').click(function() {alert("888")})
						});
						*/
						/* [/Всплывающее окно с формой авторизации] */

						$(this).bind('click', function() {
							$('form#form_authorize').css({
								'position': 'relative',
								'height': 'auto',
								'visibility': 'visible'
							});					
							$('#fancybox-wrap').addClass("iframe");
						});

					});
					if($('#capcha').attr('src') == '') { 
						$('#capcha').css({
							'visibility': 'hidden'
						});
					}
					$('form.form_authorize:last input').live('click', function() {
						if($(this).val() == 'Логин' && $(this).attr('type') == 'text') $(this).val('');
						if($(this).val() == 'Пароль' && $(this).attr('type') == 'password') $(this).val('');
					});
					$('form.form_authorize').live('submit', function(event) {
						var form_array = $.find('form.form_authorize');
						var form_length = form_array.length;
						var login_val = $(form_array[form_length - 1]).find('input[name=login]').val();
						var passw_val = $(form_array[form_length - 1]).find('input[name=password]').val();
						var popup_authorize = $(form_array[form_length - 1]).find('input#popup_authorize').val();
						
						var form_width = parseInt($(form_array[form_length - 1]).parent('div.authorize_form').width());
						var form_height = parseInt($(form_array[form_length - 1]).parent('div.authorize_form').height());
						$(form_array[form_length - 1]).parent('div.authorize_form').css({
							'position': 'relative'
						});
						var div_elm = $('<div/>').css({
							'height': form_height,
							'width': form_width,
							'opacity': 0.80
						}).addClass('form_loader');
						$(form_array[form_length - 1]).parent('div.authorize_form').append(div_elm);
						$.ajax({
							type: "GET",
							url: "/users/login_do/?" + "login=" + login_val + "&password=" + passw_val + "&popup_authorize=" + popup_authorize,
							beforeSend: function(xhr) {
								//xhr.overrideMimeType( 'text/plain; charset=x-user-defined' );
							},
							success: function(data) {
								div_elm.css({
									'background-image': 'none'
								});
								if(data == 'redirect') {
									div_elm.append($('<p/>').text('Добро пожаловать!'));
									if(String(window.location).indexOf('users/login_do/') != -1) {
										div_elm.append($('<small/>').text('Через несколько секунд Вы будете перенаправлены на главную страницу'));
									} else {
										div_elm.append($('<small/>').text('Через несколько секунд страница обновится'));
									}
									$(this).data('timeout', setTimeout($.proxy(function(){
										if(String(window.location).indexOf('users/login_do/') != -1) {
											window.location.replace('/');
										} else {
											window.location.reload(true);
										}
										
									}, this), 1000));									
								} else {
									div_elm.append($('<p/>').text('Неверный логин или пароль'));
									div_elm.append($('<small/>').text('Попробуйте заполнить еще раз'));
									$(this).data('timeout', setTimeout($.proxy(function(){
										div_elm.remove();
									}, this), 2000));
								}
							}
						});
						return false;
					});
					/* [/Всплывающее окно с формой авторизации] */
					/* [Куки для форм] */

					$('form.checkform').each(function(index) {
						if($(this).attr('id') == 'settings' || $(this).attr('id') == 'request' || $(this).attr('id') == 'purchase') {
							return;
						}
						var forms = $(this);
						forms.find('input[type=submit]').bind('mousedown', function() {
							$('form.checkform:eq(' + index + ') input[type=text]').each ( function(index_field) {
								if($(this).attr('id') != 'captcha') {
									var COOKIE_NAME = 'checkform' + forms.attr('id') + '_' + index_field;
									var options = { path: '/', expires: 10 };
									$.cookie(COOKIE_NAME, $(this).val(), options);
								}
							});
							$('form.checkform:eq(' + index + ') textarea').each ( function(index_field) {							
								if($(this).attr('id') != 'captcha') {
									var COOKIE_NAME = 'checkform' + forms.attr('id') + '_textarea' + index_field;
									var options = { path: '/', expires: 10 };
									$.cookie(COOKIE_NAME, $(this).val(), options);
								}
							});
						});

						$('form.checkform:eq(' + index + ') input[type=text]').each ( function(index_field) {
							var COOKIE_NAME = 'checkform' + forms.attr('id') + '_' + index_field;
							if($.cookie(COOKIE_NAME) && $(this).attr('id') != 'captcha') {
								$(this).val($.cookie(COOKIE_NAME));
							}
						});
						$('form.checkform:eq(' + index + ') textarea').each ( function(index_field) {							
							if($(this).attr('id') != 'captcha') {
								var COOKIE_NAME = 'checkform' + forms.attr('id') + '_textarea' + index_field;
								$(this).val($.cookie(COOKIE_NAME));
							}
						});
					});

					/* [/Куки для форм] */

					/* [Кастомизация селектов] */
					$('.select_long').customStyleLong();
					$('.select_short').customStyleShort();
					/* [/Кастомизация селектов] */
					/* [Подсветка таблиц] */
					$('.centercolumn').eq(0).find('table').each(function(index) {
						$(this).find('tr:nth-child(even)').addClass('even');
						$(this).find('tr:nth-child(odd)').addClass('odd');
					});
					/* [/Подсветка таблиц] */
					/* [Скроллинг страницы] */
					var _this_pos = [];
					$('#inner h3.pos').each(function(index) {
						if(index == 0) $("<div/>").addClass('short_list_href').insertAfter('div.centercolumn h1');
						_this_pos[index] = $(this);
						var a = $("<a></a>").text($(this).text()).attr('href', 'javascript:void(0)').addClass('podsection').bind('click', function() {
							$.scrollTo(_this_pos[index], { duration: 2500, easing: 'easeInOutQuart' });
						});
						if($(this).hasClass("section_href")) {
							a.addClass("section_href");
						}
						$('div.short_list_href').eq(0).append(a);
					});
					/*
					$('.podsection').each(function(index) {
						$(this).bind('click', function() {
							$.scrollTo($('#' + $(this).attr('re')), { duration: 2500, easing: 'easeInOutQuart' });
						});
					});
					*/
					/* [/Скроллинг страницы] */
					/* [Щелчок на существующем адресе и заполнение полей формы адреса доставки] */
					$('.delivery_address_exist').each(function(index) {
						$(this).bind('click', function() {
							var _this,
								_id_delivery_del;
							if(this.tagName.toLowerCase() == 'label') {
								_this = $(this);
							} else if(this.tagName.toLowerCase() == 'input') {
								_this = $(this).parents('dl').eq(0).find('label.delivery_address_exist').eq(0);
							}
							_id_delivery_del = _this.attr('re');
							// Запоминаем ID адреса, чтобы перезаписать именно его
							$('#purchase').find('input[name=delivery_del]').val(_id_delivery_del);
							_this.find('span.rightcol').each(function(span_index) {
								var _this_span = $(this);
								var _re = _this_span.attr('re');
								var _re_txt = _this_span.text();
								if($('input#' + _re).length > 0 && _re != 'metro' && _this_span.attr('re') != 'date') {
									$('input#' + _re).val(_this_span.text());
								}
								if($('textarea#' + _re).length > 0) {
									$('textarea#' + _re).val(_this_span.text());
									
								}
								if($('select#' + _re).length > 0 && _re == 'metro') {
									$('select#' + _re + ' option').removeAttr('selected');
									$('select#' + _re + ' option').each(function() {
										var _this_metro = $(this);
										if(_re_txt == _this_metro.text()) {
											_this_metro.attr('selected', 'selected');
											$('select#' + _re).next('span').find('span.customStyleSelectBoxInner').eq(0).text(_this_metro.text());
										}
									});
								}
							});
						});
					});
					$('.delivery_address_new').each(function(index) {
						$(this).bind('click', function() {
							var _this,
								_id_delivery_del;
							if(this.tagName.toLowerCase() == 'label') {
								_this = $(this);
							} else if(this.tagName.toLowerCase() == 'input') {
								_this = $(this).parents('dl').eq(0).find('label.delivery_address_exist').eq(0);
							}
							_id_delivery_del = _this.attr('re');
							// Запоминаем ID адреса, чтобы перезаписать именно его
							$('#purchase').find('input[name=delivery_del]').val(_id_delivery_del);
							_this.find('span.rightcol').each(function(span_index) {
								var _this_span = $(this);
								var _re = _this_span.attr('re');
								var _re_txt = _this_span.text();
								if($('input#' + _re).length > 0 && _re != 'metro' && _this_span.attr('re') != 'date') {
									$('input#' + _re).val('');
								}
								if($('textarea#' + _re).length > 0) {
									$('textarea#' + _re).val('');
								}
								if($('select#' + _re).length > 0 && _re == 'metro') {
									$('select#' + _re + ' option').removeAttr('selected');
									$('select#' + _re + ' option').each(function() {
										var _this_metro = $(this);
										if(_this_metro.text().toLowerCase() == 'выбрать') {
											_this_metro.attr('selected', 'selected');
											$('select#' + _re).next('span').find('span.customStyleSelectBoxInner').eq(0).text(_this_metro.text());
										}
									});
								}
							});
						});
					});					
					$('input.delivery_address_exist').eq(0).click();
					/* [/Щелчок на существующем адресе и заполнение полей формы адреса доставки] */
					
					/* [Работа с FastOperator] */
					// Подтверждение авторизации на авторизованного пользователя
					$('form#authorize_purchase input.submit_btn:eq(0)').bind('click', function() {
						var loader_sm = $('<span></span>').addClass('sm_loader'),
							_this = $(this).parents('form').eq(0),
							Login = _this.find("input#e-mail").val(),
							FIO = _this.find("input#imya").val(),
							PersonType = _this.find("input#contact_phone").val(),
							Code = _this.find("input#prefiks").val(),
							Number = _this.find("input#e-mail").val(),
							CityName = _this.find("input#city").val(),
							StationName = _this.find("input#metro").val(),
							StreetName = _this.find("input#street").val(),
							House = _this.find("input#house").val(),
							Flat = _this.find("input#houseroom").val();
							if(_this.find("input#e-mail").val().length <= 1) {
								Login = _this.find("input#email").val()
							}
						loader_sm.insertBefore(_this.find('input.submit_btn').eq(0)); // Ставим загрузчик после кнопки
						
							$.get('/fastoperator/getlogin_exist.php?email=' + Login, function(data) {
								var _result = $(data).text().replace(/\s/g, '');
								if(_result == 'true') {
									_this.submit();
								} else {
									alert("Извините! Такого пользователя нет в системе.");
								}
								loader_sm.remove();
							});

						return false;
					});
					
					// Проверка при регистрации на существование пользователя в FastOperator
					$('form#not_authorize_purchase input.submit_btn:eq(0)').bind('click', function() {
						var loader_sm = $('<span></span>').addClass('sm_loader'),
							_this = $(this).parents('form').eq(0),
							Login = _this.find("input#e-mail").val(),
							FIO = _this.find("input#imya").val(),
							PersonType = _this.find("input#e-mail").val(),
							Code = _this.find("input#prefiks").val(),
							Number = _this.find("input#contact_phone").val().replace(/[^0-9]/gi, ''),
							CityName = _this.find("input#city").val(),
							StationName = _this.find("select#metro option:selected").html(),
							StreetName = _this.find("input#street").val(),
							House = _this.find("input#house").val(),
							Flat = _this.find("input#houseroom").val(),
							Corpus = _this.find("input#korpus").val(),
							Building = _this.find("input#dom_stroenie").val(),
							Porch = _this.find("input#podezd").val(),
							Floor = _this.find("input#etazh").val(),
							DoorCode = _this.find("input#kod_podezda").val();
							
							if(_this.find("input#e-mail").val().length <= 1) {
								Login = _this.find("input#email").val()
							}
						loader_sm.insertBefore(_this.find('input.submit_btn').eq(0)); // Ставим загрузчик после кнопки
											
						var _this = $(this).parents('form').eq(0),
							Login = '';
						Login = _this.find("input#e-mail").val();
						if(Login.length <= 1) {
							Login = _this.find("input#email").val()
						}
				
						$.get('/fastoperator/getlogin_exist.php?email=' + Login, function(data) {
							var _result = $(data).text().replace(/\s/g, '');
							if(_result == 'true') {
								//alert("Извините! Такой пользователь уже зарегистрирован в системе.");
								_this.submit();
							} else {

								$.post("/fastoperator/user_send.php",
								{
									'EditCustomer[Customer][Login]': Login,
									'EditCustomer[Customer][FIO]': FIO,
									'EditCustomer[Customer][PersonType]': PersonType,
									'EditCustomer[Phone][Code]': Code,
									'EditCustomer[Phone][Number]': Number,
									'EditCustomer[Address][CityName]': CityName,
									'EditCustomer[Address][StationName]': StationName,
									'EditCustomer[Address][StreetName]': StreetName,
									'EditCustomer[Address][House]': House,
									'EditCustomer[Address][House]': House,
									'EditCustomer[Address][Flat]': Flat,
									'EditCustomer[Address][Corpus]': Corpus,
									'EditCustomer[Address][Building]': Building,
									'EditCustomer[Address][Porch]': Porch,
									'EditCustomer[Address][Floor]': Floor,
									'EditCustomer[Address][DoorCode]': DoorCode,
									
									'action': "EditCustomer"					
								},
								function(data) {
									var _result = $(data).text().replace(/\s/g, '');
									if(_result == 'true') {
										_this.submit();
									} else {
										alert("Извините! У нас произошел сбой, попробуйте еще раз");
									}
									loader_sm.remove();
								});	

							}
						});
						return false;
					});
					
					
					// Лоадер загрузки в момент последнего клика на кнопке "Продолжить"
					$('form#select_delivery input.submit_btn:eq(0)').bind('click', function() {
						var loader_sm = $('<span></span>').addClass('sm_loader'),
							_this = $(this).parents('form').eq(0);
						loader_sm.insertBefore(_this.find('input.submit_btn').eq(0)); // Ставим загрузчик после кнопки
						$(this).unbind('click');
					});
					
					
					// Отправка запроса при регистрации
					$('form#registrate input.submit_btn:eq(0)').bind('click', function() {
						var _this = $(this).parents('form').eq(0),
							Login = '';
						Login = _this.find("input#e-mail").val();
						if(Login.length <= 1) {
							Login = _this.find("input#email").val()
						}
						
						$.get('/fastoperator/getlogin_exist.php?email=' + Login, function(data) {
							var _result = $(data).text().replace(/\s/g, '');
							if(_result == 'true') {
								alert("Извините! Такой пользователь уже зарегистрирован в системе.");
								return false;
							} else {
								var loader_sm = $('<span></span>').addClass('sm_loader'),
									FIO = _this.find("input#fname").val() + " " + _this.find("input#lname").val() + " " + _this.find("input#father_name").val(),
									PersonType = _this.find("input#contact_phone").val(),
									Code = _this.find("input#prefiks").val(),
									Number = _this.find("input#contact_phone").val();

								
									
								loader_sm.insertBefore(_this.find('input.submit_btn').eq(0)); // Ставим загрузчик после кнопки
								
								
								$.post("/fastoperator/user_send.php",
								{
									'EditCustomer[Customer][Login]': Login,
									'EditCustomer[Customer][FIO]': FIO,
									'EditCustomer[Customer][PersonType]': PersonType,
									'EditCustomer[Phone][Code]': Code,
									'EditCustomer[Phone][Number]': Number,
									'action': "EditCustomer"					
								},
								function(data) {
									var _result = $(data).text().replace(/\s/g, '');
									if(_result == 'true') {
										_this.submit();
									} else {
										alert("Извините! У нас произошел сбой, попробуйте еще раз");
									}
									loader_sm.remove();
								});
								return false;
							}
						});
						return false;
					});
					/* [Работа с FastOperator] */
				});
							
				
			})(jQuery);




var site = {};

site.utils = {};
site.utils.getObjectType = function(obj) {
	var toString = Object.prototype.toString,
		obj_type = false;
	switch (toString.call(obj)) {
		case "[object Array]": obj_type = 'array'; break;
		case "[object Object]": obj_type = 'object'; break;
		case "[object String]": obj_type = 'string'; break;
		case "[object Number]": obj_type = 'number'; break;
		case "[object Boolean]": obj_type = 'boolean'; break;
		case "[object Function]": obj_type = 'function'; break;
	}
	return obj_type;
};

site.utils.js = {};
site.utils.js.init = function(src) {
	switch (site.utils.getObjectType(src)) {
		case "array": for (i in src) this.init(src[i]); break;
		case "string": this.include(src); break;
	}
	return true;
};

site.utils.js.include = function(src) {
	jQuery("<script/>", {
		"charset" : 'utf-8',
		"type"    : 'text/javascript',
		"src"     : src
	}).appendTo("head");
};

site.utils.js.init([
	'/js/client/utilities.js',
	'/js/client/basket.js',
	'/js/site/basket.js',
	'/js/site/forms.js',
	'/js/site/message.js',
	'/js/site/captcha.js',
	'/js/jquery/jquery.cookie.js',
	'/js/jquery/jquery.jgrowl_minimized.js'
]);
