$(document).ready(function(){
	$('#xcart').jqm();	
	$('#xbcart').jqm();
	updmc();
	if (ppage==true) {
		$(".product_price").html(pprice+' <span class="rubl">руб</span><br><br><a href="order.php" class="tocart" id="'+pindex+'"><img src="images/vkor.png"></a>&nbsp;<a href="order.php" class="bp" id="'+pindex+'"><img src="images/bpok.png"></a>');
		//$('#xbcart').load("/shop/borderform.php?item="+pindex);		
	}
	$(".tocart").live("click",function(){
		$("#xcart").load("/shop/addtocart.php?item="+this.id,function (response, status, xhr) {
			$('#xcart').jqmShow();
			updmc();
		});		
		return false;
	});
	$(".bp").live("click",function(){
		$('#xbcart').jqmShow();		
		return false;
	});
	$("#xcart .del_from_cart").live("click",function(){
		if (confirm("Вы уверены?")) 
		{ 
			$("#xcart").load("/shop/del_from_cart.php?item="+this.id,function (response, status, xhr) {				
				updmc();
			});			 
		}
		return false;
	});
	
	$(".showcart").live("click",function(){
		$("#xcart").load("/shop/cart.php",function (response, status, xhr) {	
			$('#xcart').jqmShow();
		});
	});
	
	$("#recount").live("click",function(){
		var query = '?';
		$(".item_count").each(function (k,v) {
			query = query + v.id + "=" + $("#"+v.id).val()+"&";
		});
		$("#xcart").load("/shop/recount.php"+query, function (response, status, xhr) {				
			updmc();
		});			 
	});
	
	$(".jqmClose").live("click",function(){
		$('#xcart').jqmHide();
	});
	$(".BPjqmClose").live("click",function(){
		$('#xbcart').jqmHide();
	});
	
	$(".catalog_buttons").each(function (k,v) {
		var fhref = $(this).children("a:first").attr("href");
		var item = fhref.replaceAll(".php","");
		var lhref = $(this).children("a:last").attr("href");
		if (fhref!=lhref) {
			$(this).children("a:last").attr("class","tocart");
			$(this).children("a:last").attr("id",item);
			$(this).children("a:last").children("img").attr("src", "/images/vkor.png");
			$(this).children("a:last").children("img").attr("width", "100");
			$(this).children("a:last").children("img").attr("height", "22");		
		}
		$(this).children("a:first").children("img").attr("src", "/images/podro.png");
		$(this).children("a:first").children("img").attr("width", "100");
		$(this).children("a:first").children("img").attr("height", "22");
		
	});
	
	
});
function updmc(){
		$("#mincart").load("/shop/mincart.php");
	}

String.prototype.replaceAll = function(search, replace){
  return this.split(search).join(replace);
}

