$(".sel_box").selectbox();

document.onload = $(function () {
	//Уравнивание высоты
	//var qwerty = document.getElementById('contain').clientHeight; 
	//$('body').css( 'height', qwerty );	
	
	//Установка ширины экрана
	var win_width = $('#contain').width();
	if (win_width < 1200) {
		$('#centr_part').css({
			'overflow-x': 'hidden',
			'padding-bottom': '90px'});
	} else {
		//$('#centr_part').css('padding-bottom', '90px');
	}
	$(".sel_box").selectbox();
	
	$('#header .active_city').click(function () {
		$(".change_city").css('display','block');
	});
	
	$("#header .city").hover(function () {  
    	$(".change_city").css('display','none');
    });
	
	$('.p>ul>li:nth-child(odd)').addClass('white');
	
	$('.hovered').hover(function () {
		$(this).addClass('hover');
	},
	function () {
		$(this).removeClass('hover'); 
	});
	
	//Всплывающие окошки	
	
	var _timer = null,
		_timer_1 = null;
	
	$('.discount_qwe').hover(function () {	
			$('#discount_window_qwe').css({
				left: parseInt($(this).position().left - 160),
				top: parseInt($(this).position().top + 17),
				zoom: '1'
			}).show();

			},
		function () {
			_timer = setTimeout(function() {$('#discount_window_qwe').hide()}, 1000);
		});

		$('#discount_window_qwe').hover(function () {
			clearTimeout(_timer);
			$(this).show();
		},
		function () {
			$(this).hide();
		});

		
		$('.carts_qwe').hover(function () {	
			$('#cart_window_qwe').css({
				left: parseInt($(this).position().left - 210),
				top: parseInt($(this).position().top + 30),
				zoom: '1'
			}).show();
			
		},
		function () {
			_timer = setTimeout(function() {$('#cart_window_qwe').hide()}, 1000);
		});
		
		$('#cart_window_qwe').hover(function () {
			clearTimeout(_timer);
			$(this).show();
		},
		function () {
			$(this).hide();
		});
		


	$('.carts_rty').hover(function () {
		$('#cart_window_rty table tr:nth-child(even)').addClass('black');

			$('#cart_window_rty').css({
				left: parseInt($(this).position().left - 166),
				top: parseInt($(this).position().top + 30),
				zoom: '1'
			}).show();
			
			$('#insert_item_table').css('display','block');

			},
		function () {
			_timer_1 = setTimeout(function() {$('#cart_window_rty').hide()}, 1000);
		});
		
		$('#cart_window_rty').hover(function () {
				clearTimeout(_timer_1);
				$(this).show();
		},
		function () {
			$(this).hide();
		});
	
	
	
	
	
	$('.maps').toggle(function () {
		$(this).addClass('maximize');
	}, function () {
		$(this).removeClass('maximize');
	});
	
	/*if(location.hash){
		$('.fst_act').removeClass('fst_act');
		$('#content_vkl>div').hide();
		$($('#content_vkl>div').get(1)).show();
		$($('.tabs>li').get(1)).addClass('fst_act');
		$(".sel_box").selectbox();
	}*/

	
	$('.tabs>li').click( function () {
		$('.fst_act').removeClass('fst_act');
		$(this).addClass('fst_act');
		var _index=$('.tabs>li').index(this);
//		$('#content_vkl>div').hide();
//		$($('#content_vkl>div').get(_index)).show();
		$(".sel_box").selectbox();
	});

	{
		
		$('#menu_prod').bind('slide_start', function () {

			var _currentElement = $('.curr', this),
				_currentIndex = $('#menu_prod a').index(_currentElement),
				_currentGallery = $('.images').get(_currentIndex);		
			
			$('.first').show();
			$('.second').hide();

			$('.images').fadeOut(500);
			$(_currentGallery).fadeIn(500, function () {
				
				var _indexImage = 0;
			
				var slide = function () {
					
					var _image = $('.img_item', _currentGallery).get(_indexImage);
					
					if (!_image) {
						$('#menu_prod').trigger('next_gallery');
						return false;
					}
					
					$('.first', _image).fadeOut(1000);
					$('.second', _image).fadeIn(1000, function () {
						_indexImage += 1;
						slide();
					});
					
				}
					
				slide();
				
			});
				
		});
		
		$('#menu_prod').bind('slide_stop', function () {
			$('*').stop(true, false);
			$('.first, .second').css('opacity', 1);
		});
		
		$('#menu_prod').bind('next_gallery', function () {
			
			var _currentElement = $('.curr', this);
				//_next = _currentElement.next().is('a') ? _currentElement.next() : $(':first', this);
				
				_next = _currentElement.parents('td').next().is('td') ? $('a', _currentElement.parents('td').next()) : $('a:first', this);
			
			$('.curr', this).removeClass('curr');
			$('.scnd', this).hide();	// ie mustdie
			$('.fst', this).show();		// ie mustdie
			
			$(_next).addClass('curr');
			$('.scnd', _next).show();	// ie mustdie
			$('.fst', _next).hide();	// ie mustdie
			
			$('#menu_prod').trigger('slide_start');
			
		})
		
		
		var _timer = null;
		$('#menu_prod a').click(function () {
			
			clearTimeout(_timer);
			var _this =this;
			
			// Р·Р°С†РёС‚Р° РѕС‚ РґР°Р±Р»РєР»РёРє
			_timer = setTimeout(function () {
				
				$('.curr', $('#menu_prod')).removeClass('curr');
				$(_this).addClass('curr');
				
				$('#menu_prod').trigger('slide_stop');
				
				$('#menu_prod').trigger('slide_start');
			}, 500);
			
			return false;

		})
		
		$('#menu_prod').trigger('slide_start');
		
	}
	
	$('.table_gallery').each (function() {
		$('.table_gallery a').lightBox();
	});
	
	$('.light_box_gallery').each (function() {
		$('.light_box_gallery a').lightBox();
	});
		
})

function razvernyt(status) {
	if (status == 'on'){
		$('.search-form').addClass('razvernyt');
		$(".sel_box").selectbox();
	}else if (status == 'off'){
		$('.search-form').removeClass('razvernyt');
	}
}


