$(document).ready(function() {

	//Запуск крутилки заглушек
	setTimeout(function() { bannersRotation(1) }, 6000);
	
    //выбор города в шапке
    var rddList = $('#region_drop_down_list');
    $(document).click(function(event) {
        if (!$(event.target).is('#region_link a, #region_selector, #region_drop_down_list li')){
            if (rddList.hasClass('open')) {
                rddList.slideUp('fast',     function() { rddList.toggleClass('open') });
            }
        } else if ($(event.target).is('#region_link a, #region_selector')) {
            if (!rddList.hasClass('open')) {
                rddList.slideDown('fast',   function() { rddList.toggleClass('open') });
            } else {
                rddList.slideUp('fast',     function() { rddList.toggleClass('open') });
            }
            //return false;
        }
    });
	
    //выбор города в шапке
    $('#region_drop_down_list li').click(function() {
		//var true_city = $('#region_drop_down_list').attr('class');
        var city_en = this.id.substr(7);
        var city_ru = $(this).text();
        var detectedcity = Base64.encode(city_ru);
        rddList.slideUp(0, function() { rddList.toggleClass('open') });
        if (getCookie('detectedcity') !== detectedcity) {
            $('#region_link a').text(city_ru);
            var d = new Date();// Текущая дата и время
            d.setTime ( d.getTime() + 86400000 );
            if(getCookie('detectedcity').length > 0){
                deleteCookie('detectedcity', '/', '.entuziast.ru');
            }
            setCookie('detectedcity', detectedcity, d, '/', '.entuziast.ru');
            location.reload(true);
        }
    });

    //поиск с подсказками
    $('#q').keyup(function(event) {
        var key;
            
        if(window.event) key = window.event.keyCode;
        else if (event) key = event.which;
        
        if(key == 27) {
            $('#search_results').hide('fast');
        }

        else if(this.value.length >= 2 && (key !== 38 & key !== 40)) {
            $.getJSON('http://www.entuziast.ru/modules/ajax.search.php?q=' + this.value + '&callback=?', function(data){
                    var search_result = '';

                    $.each(data, function(k, v) {
                        if(k == 'error') {
                            search_result += '<div class="result_str">';
                            search_result += '<div class="result_type">ошибка</div>';
                            search_result += '<div class="result_value">' + v + '</div>';
                            search_result += '</div>';
                        }
                        else if(k == 'groups') {
                            var groups = false;
                            $.each(v, function(kg, vg) {
                                search_result += '<div class="result_str">';
                                if(!groups)
                                    search_result += '<div class="result_type">группы</div>';
                                else
                                    search_result += '<div class="result_type"></div>';
                                search_result += '<div class="result_value" onmouseover="sel_result(this)" onmouseout="unsel_result(this)" onclick="location.href = \'http://www.entuziast.ru/' + vg['p'] + '\';"><img src="http://www.entuziast.ru/admin/images/img_resize.php?image=' + vg['i'] + '&width=30&height=30" alt=""> <strong>' + vg['n'] + '</strong></div>';
                                search_result += '</div>';
                                groups = true;
                            });
                        }
                        else if(k == 'producers') {
                            var producers = false;
                            $.each(v, function(kp, vp) {
                                search_result += '<div class="result_str">';
                                if(!producers)
                                    search_result += '<div class="result_type">производители</div>';
                                else
                                    search_result += '<div class="result_type"></div>';
                                search_result += '<div class="result_value" onmouseover="sel_result(this)" onmouseout="unsel_result(this)" onclick="location.href = \'http://' + vp['s'] + '.entuziast.ru/\';"><img src="http://www.entuziast.ru/admin/images/img_resize.php?image=' + vp['i'] + '&width=30&height=30" alt=""> <strong>' + vp['n'] + '</strong></div>';
                                search_result += '</div>';
                                producers = true;
                            });
                        }
                        else if(k == 'elements') {
                            var elements = false;
                            $.each(v, function(ke, ve) {
                                search_result += '<div class="result_str">';
                                if(!elements)
                                    search_result += '<div class="result_type">товары</div>';
                                else
                                    search_result += '<div class="result_type"></div>';
                                search_result += '<div class="result_value" onmouseover="sel_result(this)" onmouseout="unsel_result(this)" onclick="location.href = \'http://' + (ve['s'] ? ve['s'] : 'www') + '.entuziast.ru/' + ve['p'] + '\';"><img src="http://www.entuziast.ru/admin/images/img_resize.php?image=' + ve['i'] + '&width=30&height=30" alt=""> <strong>'  + ve['n'] + '</strong></div>';
                                search_result += '</div>';
                                elements = true;
                            });
                        }
                    });
                    $('#search_results').html(search_result);
                    $('#search_results').show('fast');
            });
        } else if (key !== 38 & key !== 40) {
            $('#search_results').html('');
            $('#search_results').hide('fast');
        }

    });
    
    $('#q').keydown(function(event) {

        var key;
		//var searchResElemNext = 0;
            
        if(window.event) key = window.event.keyCode;
        else if (event) key = event.which;
	
        if(key == 38 || key == 40) {
            var qtyElements = 0;
			if ($('#search_results').css('display') == 'block') {
				$('#search_results .result_str').each(function(i) {
					searchResElem[i] = $(this).find('.result_value');
					if($(this).find('.result_value').hasClass('result_value_selected')) { //.hasClass('.result_value_selected')
                        searchResElemSelected = i;
					}
				});
                qtyElements = searchResElem.length;
				if (key == 40) {
                    var i = searchResElemSelected + 1 == qtyElements ? 0 : searchResElemSelected + 1;
				} else if (key == 38){
                    searchResElemSelected = searchResElemSelected == -1 ? 0 : searchResElemSelected;
                    var i = searchResElemSelected == 0 ? qtyElements - 1 : searchResElemSelected - 1;
				}
                //alert('i = ' + i + ' ; searchResElemSelected = ' + searchResElemSelected);
                sel_result(searchResElem[i]);
                searchResElemHref = searchResElem[i];
                unsel_result(searchResElem[searchResElemSelected]);
			}
        } else if (key == 13) {
            searchResElemHref.trigger('click');
            $('#search > form').submit(function() {
                return false;
            });
        }
        
    });
    $('#search > form').submit(function() {
        if($('#q').val() !== '') {
            return true;
        } else {
            return false;
        }
    });
    

	//$('#ruler').css('height', getDocumentHeight());
	
    //корзина на страницах
    xajax_show_cart_pages();

    //сравнение на страницах
	xajax_show_compare_pages();

	$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['']));
	$(".datepicker").datepicker($.datepicker.regional['ru']);
	
	$("a.zoom").fancybox({
		'zoomSpeedIn' : 500,
		'zoomSpeedOut': 500
	});

	$("a.iframe").fancybox({
		'frameWidth' : 320,
		'frameHeight': 240,
		'hideOnContentClick': false
	});
	
	$("a.iframe-map").fancybox({
		'frameWidth' : 600,
		'frameHeight': 400,
		'hideOnContentClick': false
	});
	
	$("a.iframe-new-year").fancybox({
		'frameWidth' : 500,
		'frameHeight': 400
	});
	
	//if(location.hash == '#comments') show_tab(3);
	var number;
	switch (location.hash) {
		case '#description':
			number = 2;
			break;
		case '#comments':
			number = 3;
			break;
		case '#delivery-info':
			number = 4;
			break;
		//case '#manual-certificates':
		//	number = 5;
		//	break;
		case '#my-orders':
			number = 2;
			break;
		default: //#buy-goods'
			number = 1;
			break;
	}
	show_tab(number);
	
	//наличие товаров
	$('.availability').hover(
		function(){
			$(this).find('.availability_modal').fadeIn(100);
		}, function(){
			$(this).find('.availability_modal').fadeOut(100);
		}
	);
	
    /**
	 * Фильтры товаров
	 */
    var position = 0;
	// Диапазон цен
    var parentId = parseInt($('#filter #parent_id').val());
    var priceFrom = parseInt($('#filter #price_from').val());
    var priceTo = parseInt($('#filter #price_to').val());
    var priceMin = parseInt($('#filter #price_min').val());
    var priceMax = parseInt($('#filter #price_max').val());
    var Step = parseInt($('#filter #step').val());
    $( "#slider-range" ).slider({
        range: true,
        min: priceMin,
        max: priceMax,
		step: Step,
        values: [ priceFrom, priceTo ],
        slide: function( event, ui ) {
            //$( "#amount" ).val( ui.values[ 0 ] + " руб. - " + ui.values[ 1 ] + " руб." );
            $( "#filter #price_from" ).val( ui.values[ 0 ] );
            $( "#filter #price_to" ).val( ui.values[ 1 ] );
        },
        stop: function(event, ui) {
            position = $(this).position().top;
            ajaxFilter();
        }
		//$( "#amount" ).val( $( "#slider-range" ).slider( "values", 0 ) + " руб. - " + $( "#slider-range" ).slider( "values", 1 )  + " руб.");
    });
	/// Диапазоны характеристик
	var optionId;
	var optionFrom;
	var optionTo;
	var optionMin;
	var optionMax;
	var optionStep;
	var optionSelector;
	$('#filter_options .option').each(function(i){
		optionId = parseInt(this.id.slice(7));
		optionSelector = $(this);
		optionFrom 	= parseInt(optionSelector.find('.option_from').val());
		optionTo 	= parseInt(optionSelector.find('.option_to').val());
		optionMin 	= parseInt(optionSelector.find('.option_min').val());
		optionMax 	= parseInt(optionSelector.find('.option_max').val());
		optionStep 	= parseInt(optionSelector.find('.option_step').val());
		/*optionSelector.append(
			'<p style="border: 1px solid red; padding: 5px; margin: 5px;">.option_from = ' + optionFrom
			+ '<br />.option_to = ' + optionTo
			+ '<br />.option_min = ' + optionMin
			+ '<br />.option_max = ' + optionMax
			+ '<br />.option_step = ' + optionStep + '</p>'
		);*/
		$(this).find('.slider-range').slider({
			range: true,
			min: optionMin,
			max: optionMax,
			step: optionStep,
			values: [ optionFrom, optionTo ],
			slide: function( event, ui ) {
				//$( "#amount" ).val( ui.values[ 0 ] + " руб. - " + ui.values[ 1 ] + " руб." );
				$(this).parent().find( '.option_from' ).val( ui.values[ 0 ] );
				$(this).parent().find( '.option_to').val( ui.values[ 1 ] );
			},
			stop: function(event, ui) {
				position = $(this).position().top;
				//$(this).parent().append('<p style="border: 1px solid red; padding: 5px; margin: 5px;">' + position + '</p>');
				ajaxFilter();
			}
		});
	});
    
    $("#filter .filter_producer input[type=checkbox]").change(function(){
        position = $(this).position().top;
        ajaxFilter();
    });
    
    $("#filter input[type=text]").blur(function(){
        position = $(this).position().top;
        ajaxFilter();
    });
    
	var sort_price = false;
    function ajaxFilter() {
        position = Math.round(position);
        priceFrom = $('#filter #price_from').val();
        priceTo = $('#filter #price_to').val();
		
		if (priceFrom != priceMin | priceTo != priceMax) {
			priceFrom = priceFrom < priceMin ? priceMin : priceFrom;
			priceTo = priceTo > priceMax ? priceMax : priceTo;
		} else {
			priceFrom = 0;
			priceTo = 0;
		}
        var allProducers = new Object();
        var prId;
        var prId2;
        var allOptionsFrom = new Object();
        var allOptionsTo = new Object();
        
        $("#filter .filter_producer input[type=checkbox]:checked").each(function(i) {
            prId = (this.id.slice(9) + 0);
            prId2 = this.id;
            allProducers[prId2] = $(this).val();
        });
        
        $("#filter #filter_options .option").each(function(i) {
			optionId = parseInt(this.id.slice(7));
			optionSelector = $(this);
			optionFrom 	= parseInt(optionSelector.find('.option_from').val());
			optionTo 	= parseInt(optionSelector.find('.option_to').val());
			optionMin 	= parseInt(optionSelector.find('.option_min').val());
			optionMax 	= parseInt(optionSelector.find('.option_max').val());
			if (optionFrom != optionMin | optionTo != optionMax) {
				//alert('optionMin = ' + optionMin + ', optionFrom = ' + optionFrom + "\n\n" + 'optionMax = ' + optionMax + ', optionTo = ' + optionTo);
				allOptionsFrom[optionId] 	= optionFrom;
				allOptionsTo[optionId] 		= optionTo;
			}
        });
        $.get("/modules/ajax.filter.php",
            { pid: parentId, pf: priceFrom, pt: priceTo, aof: allOptionsFrom, aot: allOptionsTo, ap: allProducers },
            function(data){
                $('#result span').html(data.count);
                //$('#result a').attr('href', data.href);
                $('#result').css('top', position + 'px').fadeIn(500);
            	setTimeout(function() { $('#result').fadeOut(600); }, 6000);
            }, "json"
        );
    }
    
	// Создание урл для фильтрации
	$('#filter .filter_submit, #result a').click(function() {
		var path = $('#filter_path').val();
		var producers = '';
		var producer;
		var j = 0;
		var filters = '';
		var options = '';
		
		if (priceFrom == priceMin & priceTo == priceMax) {
			priceFrom = 0;
			priceTo = 0;
		}
		
		$('#filter_producers .filter_producer input:checked').each(function(i) {
			j = i + 1;
			if (producers == '') {
				producers = "producers=";
			} else {
				producers += "|";
			}
			producers += $(this).val();
			producer = $(this).val();
		});
		
		if(j != 1) {
			producer = 'www';
		} else {
			producers = '';
		}
		
		j = 0;
		$('#filter_options .option').each(function(i) {
			if ($(this).css('display') == 'block') {
				optionId = parseInt(this.id.slice(7));
				optionSelector = $(this);
				optionFrom 	= parseInt(optionSelector.find('.option_from').val());
				optionTo 	= parseInt(optionSelector.find('.option_to').val());
				optionMin 	= parseInt(optionSelector.find('.option_min').val());
				optionMax 	= parseInt(optionSelector.find('.option_max').val());
				if (optionFrom != optionMin | optionTo != optionMax) {
					//alert('optionMin = ' + optionMin + ', optionFrom = ' + optionFrom + "\n\n" + 'optionMax = ' + optionMax + ', optionTo = ' + optionTo);
					if (options == '') {
						options = "options=";
					} else {
						options += "|";
					}
					options += optionId + ':' + optionFrom + ':' + optionTo;
				}
			}
		});
		
		//var tail = '?pf=' + priceFrom + '&pt=' + priceTo + (producers != '' ? '&' + producers : '') + (options != '' ? '&' + options : '');
		sort_price = (priceFrom != 0 | priceTo != 0) ? true : false;
		var tail = sort_price == true ? ('?pf=' + priceFrom + '&pt=' + priceTo) : '';
		tail += (producers != '' ? (tail == '' ? '?' : '&') + producers : '');
		tail += (options != '' ? (tail == '' ? '?' : '&') + options : '');
		if ($('#more_options').hasClass('open')) {
			tail += (tail == '' ? '?' : '&') + 'qo=all';
		}
		
		//var fullPath = 'http://' + producer + '.entuziast.ru/' + path + tail;
		
		location.href = 'http://' + producer + '.entuziast.ru/' + path + tail;
		return false;
	});
	
	// отображение/скрывание части характеристик
	$('#more_options .more').click(function() {
		$('#more_options').addClass('open');
	});
	$('#more_options .less').click(function() {
		$('#more_options').removeClass('open');
	});
	
	//сравнение товаров
    $('.char_val img.del').click(function(){
        var elId = $(this).attr('rel');
        $.post("/compare/", { action: "del", id: elId },
            function(data) {
                charValWidth -= $('.el' + elId + ':first').outerWidth();
                $('.el' + elId).remove();
                if($('.characteristics .char_val th').length == 0) {
                    $('.characteristics').css('display', 'none');
                    $('.not_selected').css('display', 'block');
                }
                if(charValWidth > 0) {
                    $( "#slider" ).slider({
                        max: charValWidth
                    });
                } else {
                    $( ".char_val" ).css('margin-left', '');
                    $( "#slider" ).hide();
                }
                $('.char_val tr').each(function() {
                    $(this).find('td:last').addClass('td_boder_right_light_grey');
                });
            }
        );
        return false;
    });

    var th_height = 0;
    var td_height = 0;
    var td_num;
    var i;
    if ($.browser.msie) {
        $('#slider').css('top', '269');
        $('.char_th_right_bottom > div').height('246');
    } else if ($.browser.webkit) {
        $('#slider').css('top', '269px');
        $('.char_th_right_bottom > div').height('246px');
    }
    $('.char_name td').each(function(i) {
        td_height = $(this).outerHeight();
        td_num = $('.char_val tr:eq(' + (i + 1) + ') td');
        if (td_num.outerHeight() > td_height) {
            td_height = td_num.outerHeight();
        }
        $(this).height(td_height);
        td_num.height(td_height);
        $('.char_val tr').each(function() {
            $(this).find('td:last').addClass('td_boder_right_light_grey');
        });
    });

    charValWidth = ($( ".char_val" ).outerWidth() - 735);
    if(charValWidth > 0) {
        $( "#slider" ).slider({
            value:0,
            min: 0,
            max: charValWidth,
            slide: function( event, ui ) {
                $( ".char_val" ).css('margin-left', -ui.value);
                $('body').css('cursor', 'pointer');
            },
            stop: function( event, ui ) {
                $('body').css('cursor', 'auto');
            }
        });
        $( ".char_val" ).css('margin-left', -$( "#slider" ).slider( "value" ));
    }

	/**
	 * Плашка сравнения товаров
	 */
    $('#about_compare_float img.del').live('click', function(){
        var elId = $(this).attr('rel');
        $.post("/compare/", { action: "del", id: elId },
            function(data) {
                acRightWidth -= $('#el' + elId).outerWidth();
                $('#el' + elId).remove();
				if ($('#about_compare_float td').length == 0) {
					$('#about_compare_float').remove();
				}
                if(acRightWidth > 0) {
                    $( "#ac_slider" ).slider({
                        max: acRightWidth
                    });
			        $( "#ac_right table" ).css('margin-left', -$( "#ac_slider" ).slider( "value" ));
                } else {
                    $( "#ac_right table" ).css('margin-left', '');
                    $( "#ac_slider" ).hide();
                }
                //$('#about_compare_float tr td:last').addClass('td_boder_right_light_grey');
            }
        );
        return false;
    });
	
	/*Типа метод прогрессивного улучшения*/
	if($('#form').length) {
		if($('#form #main_phone').length) {
			$('#form input.phone').live('focus', function() {
									if($(this).hasClass('example_phone'))
										$(this).removeClass('example_phone').val('');
								})
								.live('blur', function() {
									if($(this).val() == '')
										$(this).addClass('example_phone').val('495 1234567');
								})
								.trigger('blur');
						
			if($('#form tr.extra_phone').length)
				$('#form tr.extra_phone:last').after('<tr><td></td><td><div id="extra_phone">Добавить дополнительный телефон</div></td></tr>');
			else
				$('#form #main_phone').after('<tr><td><div id="extra_phone">Добавить дополнительный телефон</div></td></tr>');		
		}
		
		if($('#form #main_address').length) {
			if($('#form tr.extra_address').length) {
				$('#form tr.extra_address:last').after('<tr><td colspan="2"><div id="extra_address">Добавить дополнительный адрес</div></td></tr>');
			}else{
				$('#form #main_address').after('<tr><td colspan="2"><div id="extra_address">Добавить дополнительный адрес</div></td></tr>');	
			}
		}
		
		/* Добавленеи дополнительных полей в форму*/
		$('#form #extra_address, #form #extra_phone').click(function() {
			if(this.id == 'extra_address')
				if($('#main_address input[name=user_address]').val() != '')
					$(this).parents('tr').before('<tr class="extra_address"><td class="bold">Адрес доставки - дополнительный</td><td nowrap><input style="width:280px; float: left;" class="input_normal" name="extra_address[]" type="text" value=""> <div class="remove_address">Удалить</div></td></tr>');
				else
					alert('Введите основной адрес!');
			else if(this.id == 'extra_phone') {
				if(($('#main_phone input[name=phone]').attr('type') == 'text' && !$('#main_phone input[name=phone]').hasClass('example_phone') && $('#main_phone input[name=phone]').val() != '') || $('#main_phone input[name=phone]').attr('type') == 'checkbox') {
					if($('#form tr.extra_phone').length)
						$(this).parents('tr').before('<tr class="extra_phone"><td></td><td nowrap><div><span>+7</span><input class="input_normal phone" name="extra_phone[]" type="text" value=""></div><div><span>добавочный:</span><input class="extension_phone" type="text" name="extension_extra_phone[]" value="" maxlength="50"></div><div class="remove_phone">Удалить</div></td></tr>');
					else{
						$(this).parents('tr').before('<tr class="extra_phone"><td nowrap><div><span>+7</span><input class="input_normal phone" name="extra_phone[]" type="text" value=""></div><div><span>добавочный:</span><input class="extension_phone" type="text" name="extension_extra_phone[]" value="" maxlength="50"></div><div class="remove_phone">Удалить</div></td></tr>');
						$(this).parent().before('<td></td>');
					}
					$('#form input.phone').trigger('blur');
				}else{
					alert('Введите основной телефон!');
				}
			}
		});
		
		/* Удаление дополнительных полей телефона и алреса */
		$('#form .remove_address, #form .remove_phone').live("click", function() {
			$(this).parents('tr').remove();
		});
		
		/* Срытие полей для юр. лиц */
		if(($('#tab1c .type_face input') && $('#tab1c .type_face input:checked').val() == '0') || ($('table.order_form input[name=type_face]') && $('table.order_form input[name=type_face]').val() == '0')) {
			$('table#form .legal_field').fadeOut();
		}
		
		/* Появление полей при выборе юр. лица */
		if($('#form .legal_field').length) {
			$('#form .type_face input[type=radio]').click(function() {
				if(this.value == '1') {
					$('table#form .legal_field').fadeIn();
				}else{
					$('table#form .legal_field').fadeOut();
				}
			});
			
			$('#legal').click(function() {
				if($('table.order_form input[name=type_face]').val() == '0') {
					$('.legal_field').fadeIn();
					$('table.order_form input[name=type_face]').val('1');
				}else{
					$('.legal_field').fadeOut();
					$('table.order_form input[name=type_face]').val('0');
				}
			});
			
		}else{
		
			$('#form .type_face input').click(function() {
				if(this.value == '1') {
					$('#form div.type_face').fadeIn();
				}else{
					$('#form div.type_face').fadeOut();
				}
			});		
		}
		
		if($('table.order_form').length) {
			$('#delivery_address').change(function() {
				if($('#delivery_address :selected').val() == '0')
					$('textarea[name=address]').fadeIn();
				else
					$('textarea[name=address]').fadeOut();
			});
			
			$('#method_pay').change(function() {
				if($('#method_pay :selected').val() == '2')
					$('#file_pay').fadeIn();
				else
					$('#file_pay').fadeOut();
			});
		}
		
		if($('#quick_buy').length) {
			$(document.createElement('script'))
				.attr('src', 'http://www.entuziast.ru/js/quick-buy.js')
				.appendTo('head');
		}
	}
	
			
	/*$('#tab1c input.phone, #form input.phone').keypress(function(event) {
		if(event.which && (event.which < 48 || event.which > 57)) {
			event.preventDefault();
		}
	});*/
	
	$('#group0 li').click(function() {
		var height = $('#menu_content').height();
		var h = Math.round(height / 300);
		if (h == 0)
			h = 1;
		h -= 1;
		$('#special_content ul li').each(function(index) {
			if(index > h)
				$(this).remove();
		});
	});
	
	$('#producer_name, #quick_buy > div').click(function(event) {
		$('#window').hide('fast');
		$('#overlay').fadeIn('fast');
		if($(event.target).is('#producer_name')) {
			$('#producer_popup').show('fast');
			$('#menu_block').css('position', 'absolute');
			$('#menu_block').css('z-index', '1001');
		}else
			$('#quick_buy_form').slideDown('fast');		
		$('#overlay').fadeTo(0, 0.6);
	});
	
	$('#quick_buy #buy_form button').click(function() {
		var id = $('#quick_buy #buy_form input[name=element]').val();
		var fio = $('#quick_buy #buy_form input[name=username]').val();
		var phone = $('#quick_buy #buy_form input[name=phone]').val();
		if($('#quick_buy #buy_form select[name=delivery_phone]').val() != '0')
			phone = $('#quick_buy #buy_form select[name=delivery_phone]').val();
		var email = $('#quick_buy #buy_form input[name=email]').val();
		var check = false;
		if($('#quick_buy #buy_form input[name=subscribe]').attr('checked') == true)
			check = true;
		var address = $('#quick_buy #buy_form textarea[name=address]').val();
		if($('#quick_buy #buy_form select[name=delivery_address]').val() != '0')
			address = $('#quick_buy #buy_form select[name=delivery_address]').val();
		var re = /.+/;
		if (!phone.match(re)) {
			alert('Не указан контактный телефон');			
		}else{
			$('#quick_buy').slideUp();
			xajax_quick_buy(id, fio, phone, email, check, address);
		}
	});
	
	$('#gitem #gitem_bottom .free_buy, #item #item_description #item_prices .free_buy').mouseover(function() {
		$(this).children('.buy_info').show();
	});
	
	$('#gitem #gitem_bottom .free_buy, #item #item_description #item_prices .free_buy').mouseout(function() {
		$(this).children('.buy_info').hide();
	});
	
	$('#order_content #pay').click(function() {
		$('#form_pay').submit();
	});
	
	if ($('#cart_data').length) {
		if ($('#cart_data').html().length < 50) $('#cart_data').html('Ваша корзина пуста');
	}
});
