$(document).ready(function() {
	$('.b-order-action input#item').live('click',function(){
		if ($(this).attr('checked'))
			$('.b-order-action input.checkbox').removeAttr('checked');
		else
			$('.b-order-action input.checkbox').attr('checked','checked');
	});
	$('span.b-delete-item').live('click',function(e){
		var ids = new Array();
		$('.b-order-action input.checkbox:checked').each(function(){
			if ($(this).attr('id')!='item')
				{
				var el = $(this);
					$.get('/basket/delitem',{id:$(this).attr('id').substring(5)},function(data){
						if (data)
						{
							el.parent().parent().remove();
							if ($('.b-order-itemtr').size() == 0)
							{
								if (window.location.toString().match('\/basket\/order'))
								{
									window.location.reload();
								}
								$('.b-shadow').hide();
								$('.b-minicart').hide();
								
							}
						}
					})
				}
		});
		refreshBasketStats();
	});
	
	$('.input-count').live('keyup',function(){
		if ($(this).val()!='')
		{
			var price = parseInt($(this).parent().siblings('.b-order-price').html());
			$(this).parent().siblings('.b-order-summ').html(price*parseInt($(this).val()));
			var summEl = $('.b-total-summ span.total-price');
			var summ = 0;
			$('.b-order-summ').each(function(e){
				summ+=parseInt($(this).html());
			});
			summEl.html(summ);
			
		}
	});
	  refreshBasketStats();
	  getCompareItems();
	  FilerOnEnter("#price_from");
	  FilerOnEnter("#price_to");
	  
	  //if ($('.b-phone').children().size() < 2) {
//		  $('.b-panel-search').css({'top':160});
//		  $('.b-container').css({'padding-top':210})
//	  }
		$('.b-search-icon').live('click',function(e){
			if ($('input[name=searchtext]').val()!='')
				javascript:document.forms.searchForm.submit();
			else
			{
				$('input[name=searchtext]').focus();
			}
		});
		$('.b-search-item').live('click',function(e)
		{
			e.stopPropagation();
			$('.b-search-active').attr('id',$(this).attr('id'));
			$('.b-search-active').html($(this).html());
			$('.b-search-list').hide();
		});
		$('.searchForm').live('submit',function(e)
		{			
			e.preventDefault();
			var search = $('.input-search').val();
			if (search=='')
				return false;
			var url = "/catalog/search/"+search;
			if ($('.b-search-active').attr('id')!='s_all')
			{
				var catId = parseInt($('.b-search-active').attr('id').substr(2));
				url = url+'/catid/'+catId;
			}
			window.location = url;
		});
		$('.b-search-icon').live('click',function(e){
			
			$('.searchForm').submit();
		})

});
  

