	
	var cls_enter = false;
	var time = 0;
	var sendInterval = 10; // sec
	var closeInterval = 0.5; // sec
	
	closeCartPopup = function(){
		if (cls_enter){
			jQuery('.cart_popup').hide();
		}
	}
	
	sendCart = function(){
		var objDate = new Date()
	    var newTime = objDate.getTime();
		if ( newTime   - time > sendInterval*1000 ){
			jQuery('.cart_content').html('');
			jQuery('.cart_content_loader').show();
			jQuery.post('/checkout/cart/popup',function(data){
				jQuery('.cart_content_loader').hide();
				jQuery('.cart_content').html(data);
			});
			time = newTime;
		}
	}
	
	jQuery(document).ready(function() {
		
		jQuery('.cart_close').click(function(){
			cls_enter = true;
			closeCartPopup();
		});
		
		jQuery('#cart, .cart_popup').bind('mouseenter', function() {
			sendCart();
			jQuery('.cart_popup').show();
			cls_enter = false;
		});
	
		jQuery('#cart, .cart_popup').bind('mouseleave', function() {
			cls_enter = true;
			setTimeout(closeCartPopup, closeInterval*1000);
		});
		
	});
	
	function updateCart() {
	    var currentItems = parseInt(jQuery('.summary strong').html());
	    if (jQuery('.summary').length == 0) {
		jQuery('.block-cart').append('<div class="summary"></div>');
		currentItems = 0;
	    }
	    var _word = 'украшений';
	    if (currentItems > 1) {
		currentItems --;
		if (currentItems > 1 || currentItems < 5) {
		    _word = 'украшения';
		}
		jQuery('.summary').html('В корзине <strong>' + currentItems + '</strong> ' + _word + ' и <strong style="color:#489FA8;">подарок</strong>');
	    } else {
		jQuery('.summary').html('<span style="color:black; text-decoration:none;">В вашей корзине уже лежит</span> <span style="color:#489FA8;">подарок</span>');
	    }
	    jQuery('.block-cart').click(function() {
		setLocation(_baseUrl + 'checkout/cart/');
	    });
	    jQuery('.block-cart').css('cursor', 'pointer');
	}

	function cartDel(_this,id, url) {
		var item = document.getElementById(id);
		
		jQuery.ajax({
			url: url,
			beforeSend: function(xhr) {
				jQuery('#del_'+id).html('Удаление&nbsp;<img src="/skin/frontend/nebovalmazah2/default/images/ajax-loader-circ.gif" width="10">');
			},
			success: function(data){
				jQuery('#cluetip-inner').html(data);
				item.remove();
				updateCart();
			}


		});

	}
