
	$(document).ready(function()
	{
		// смена спецпредложений
		setInterval(function() {  
			$("#special_offers_container .special_offer:last-child").clone().prependTo('#special_offers_container');
			$("#special_offers_container .special_offer:last-child").fadeOut(function(){
				$(this).remove();
			});
		}, 4500);
		
		// смена блоков на главной
		setInterval(function() {  
			$("#index_blocks_container .index_block:last-child").clone().prependTo('#index_blocks_container');
			$("#index_blocks_container .index_block:last-child").fadeOut(function(){
				$(this).remove();
			});
		}, 4500);
		
		var $paneTarget = $('body');
		$('.scroll_link').click(function(){
			var $target = $paneTarget.find('#' + $(this).attr('goto'));
			if ($target.length)
			{
				$paneTarget.stop().scrollTo( $target , 500);
			}
		});

		$(".slideToggle").click(function(){
			$(this).next().slideToggle("normal");
		});
		

		setTimeout(function () {
			$(".alert_ok").fadeOut(function(){
				$(this).remove();
				});

			}, 4000);

		$("a[rel=album]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over'
		});
		
		$("a.lightbox").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over'
		});
		/*
		$.fancybox(
			$('#login_popup').html(),
			{
				
			}
		);	*/
		
		$('#feedback_link').click(function(e){
			e.preventDefault();
			e.stopPropagation();
			$.fancybox({
				'href'				: '#feedback_box',
				'autoDimensions'	: true,
				'width'         	: 530,
				'height'        	: 'auto',
				'padding'		: '20',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		});
		
		$('#callback_link').click(function(e){
			e.preventDefault();
			e.stopPropagation();
			//e.stopImmediatePropagation();
			$.fancybox({
				'href'				: '#callback_box',
				'autoDimensions'	: true,
				'width'         	: 330,
				'height'        	: 'auto',
				'padding'		: '20 30',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		});
		
		$('.hide_search_panel_link').click(function(e){
			$("#catalog_search_panel").slideUp('normal', function() {
				$("#show_catalog_search_panel_block").fadeIn(); //css('display', 'block');
			  });
		});
		
		$('.show_search_panel_link').click(function(e){
			$("#show_catalog_search_panel_block").css('display', 'none');
			$("#catalog_search_panel").slideDown('normal');
		});
		
		$("#catalog_items_list .item_block_view").hover(
			function(){
				$(this).addClass('hover');
			},
			function(){
				$(this).removeClass('hover');
			}
		);
	
		$(".digit_input").keypress(function (e) {
			//Если символ - не цифра, ввыодится сообщение об ошибке, другие символы не пишутся
			if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) && e.which != 13 && e.which != 46 && e.which != 44)
			{
				return false;
			}    
		});
		
		
		
		
		
		
		
		
		// Changes the cursor to an hourglass
		function cursor_wait() {
			$('#ajax_loader_img').css('display', 'block');
			$("body").bind('mousemove', function(e){
				$('#ajax_loader_img').css({left: e.pageX + 5, top: e.pageY-30});
			});
			$('#questions_tab').unbind('mousemove');
		}

		// Returns the cursor to the default pointer
		function cursor_clear() {
			$('#ajax_loader_img').css('display', 'none');
			$("body").unbind('mousemove');
			$('#questions_tab').bind('mousemove',function(event){
				$('#ajax_loader_img').css({left: event.pageX+5, top: event.pageY-30});
			});
		}
		
		// отправка скрытой формы
		$('.search_form_link').live('click', function(e){
			if ($('#is_search').size() > 0 && $('#is_search').val() == '1')
			{
				e.preventDefault();
				var link = $(this).attr('href');
				if (link != '')
				{
					$('#search_hidden_form').attr('action', link);
				}
				
				$('#search_hidden_form').submit();
			}
		});
	
		/*
		$(".reserve_link").live('click', function(e) 
		{
			e.preventDefault();
			var item_id = $(this).attr("item_id");

			var item_price = $(this).attr("item_price");
			var item_name = $(this).attr("item_name");
			var item_qty = $('input.item_quantity[item_id="'+item_id+'"]').val();
			
			cursor_wait();
			$.ajax({
				type: "POST",
				url: BASEURL + "catalog/reserve/" + item_id,
				data: "id=" + item_id + '&qty=' + item_qty + '&price=' + item_price,
				beforeSend: function(){
					cursor_wait();
				},
				complete: function(){
					cursor_clear();
				},
				success: function(data){
					
					$('#item_reserve_container').html(data);
					$.fancybox({
						'href'  : '#item_reserve_container',
						//'title' : 'Зарезервировать товары',
						'width' : 400,
						'padding': 20,
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}); 
				}
			});
		});
		
		$('#item_reserve_container #form_submit_container input').live('click', function(e){
			e.preventDefault();
			var order_name = $('input[name="order_name"]').val();
			var order_email = $('input[name="order_email"]').val();
			var order_phone = $('input[name="order_phone"]').val();
			var order_comment = $('textarea[name="order_comment"]').val();
			
			var item_id = $('#order_item_id').val();
			var item_qty = $('div.primary_count input.item_quantity').val();
			var item_price = $('div.primary_count input.item_quantity').attr('item_price');
			
			cursor_wait();
			$.ajax({
				type: "POST",
				url: BASEURL + "catalog/reserve/" + item_id,
				data: "id=" + item_id + '&qty=' + item_qty + '&price=' + item_price + '&order_name=' + order_name + '&order_email=' + order_email + '&order_phone=' + order_phone + '&order_comment=' + order_comment,
				beforeSend: function(){
					cursor_wait();
				},
				complete: function(){
					cursor_clear();
				},
				success: function(data){
					
					$('#item_reserve_container').html(data);
					$.fancybox({
						'href'  : '#item_reserve_container',
						//'title' : 'Зарезервировать товары',
						'width' : 400,
						'padding': 20,
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}); 
				}
			});
		});
		
		// пересчет стоимости
		$('.item_quantity').live('keyup', function() {
			$('.item_quantity').val($(this).val());
			var item_id = $(this).attr('item_id');
			var item_qty = parseFloat($(this).val().replace(',', '.'));
			var item_price = parseFloat($(this).attr('item_price'));
			
			// обновляем цену за данный товар
			var item_price = item_qty * item_price;
			item_price = item_price.toFixed(2) + ''; 
			item_price = item_price.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
			if (item_price == 'NaN')
			{
				item_price = '0.00';
			}
			$('.item_price[item_id='+item_id+']').html(item_price);
		});
		
		// загрузка сразу же страницы, если она была в адресной строке
		if (window.location.hash.length > 1)
		{
			var action = window.location.hash.substr(1);
			if (action == 'order')
			{
				var main_object = $('.reserve_link');
				var item_id = $(main_object).attr("item_id");

				var item_price = $(main_object).attr("item_price");
				var item_name = $(main_object).attr("item_name");
				var item_qty = $('input.item_quantity[item_id="'+item_id+'"]').val();
				
				cursor_wait();
				$.ajax({
					type: "POST",
					url: BASEURL + "catalog/reserve/" + item_id,
					data: "id=" + item_id + '&qty=' + item_qty + '&price=' + item_price,
					beforeSend: function(){
						cursor_wait();
					},
					complete: function(){
						cursor_clear();
					},
					success: function(data){
						
						$('#item_reserve_container').html(data);
						$.fancybox({
							'href'  : '#item_reserve_container',
							//'title' : 'Зарезервировать товары',
							'width' : 400,
							'padding': 20,
							'transitionIn'		: 'none',
							'transitionOut'		: 'none'
						}); 
					}
				});
			}
		}
		*/
	
});
	

