var widgets = {

	addToCart: function(shop_id, product_id, price, obj) {

		var amount = 1;
		product_id = Number(product_id);

      	if (!isNaN(shop_id)&&(shop_id>0)&&!isNaN(product_id)&&(product_id>0)&&!isNaN(price)&&!isNaN(amount)&&(amount>0)) {      

          var total = readCookie('CART_TOTAL_'+shop_id);
          var cart = unescape(readCookie('CART_'+shop_id));
          var cart_split = cart.split(';');
          var cart_new = "";
          var cart_item_split;
          var found = false;

          if (total=="") total = 0;

          for (var i=0; i < cart_split.length; i++){

             cart_item_split = cart_split[i].split("=");

             if (cart_item_split.length == 2){
                 
                if (!found&&cart_item_split[0] == product_id) {

                     //total = total - price*cart_item_split[1];
                     total = Number(total) + Number(price*amount);
                     var total_amount = Number(amount)+Number(cart_item_split[1]);
                     found = true;

                     if (cart_new!="") cart_new = cart_new + ";";                     
                     cart_new = cart_new + product_id + "=" + total_amount;

                } else {
                     
                     if (cart_new!="") cart_new = cart_new + ";";                     
                     cart_new = cart_new + cart_item_split[0] + "=" + cart_item_split[1];

                }
               
             }

          }

          if (!found) {

                if (cart_new!="") cart_new = cart_new + ";";                     
                cart_new = cart_new + product_id + "=" + amount;
                total = Number(total) + Number(price*amount); 

          }    
                    
          total = Math.round(total*100)/100;           
                    
          createCookie('CART_'+shop_id,cart_new,10); 
          createCookie('CART_TOTAL_'+shop_id,total,10);

          if (document.getElementById('cart_total')) document.getElementById('cart_total').innerHTML = total;
		  
		var pos = findPos(obj);
			
		var d = document.createElement("DIV");
	
		if (d) {
	
			d.style.position = 'absolute';
			d.innerHTML = 'добавлено...';
			d.style.display = 'block';
			d.className = 'added-to-cart';
			d.style.left = (pos.x+obj.offsetWidth) + 'px';
			d.style.top = (pos.y+obj.offsetHeight) + 'px';
			document.body.appendChild(d);

	
			window.setTimeout(function(){if (d&&d.parentNode)d.parentNode.removeChild(d); delete d;},1500);
		
	}	
         
          return true;  
     }

     return false;     
		
	}
	
}

function findPos(obj){

		var result = {};

		result.x = 0;
		result.y = 0;

		if (obj.offsetParent) {
		
			while (obj.offsetParent) {
				result.y += obj.offsetTop;
				result.x += obj.offsetLeft;
				obj = obj.offsetParent;
			}
			
		} else {
			if (obj.x) result.x += obj.x;
			if (obj.y) result.y += obj.y;
		}

		return result;

}<!--LiveInternet counter--><script type="text/javascript"><!--
				document.write("<a href='http://www.liveinternet.ru/click' "+
				"target=_blank><img src='http://counter.yadro.ru/hit?t2.0;r"+
				escape(document.referrer)+((typeof(screen)=="undefined")?"":
				";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
				screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
				";"+Math.random()+
				"' alt='' title='LiveInternet: показано число просмотров и"+
				" посетителей за 24 часа' "+
				"border='0' width=1 height=1><\/a>")
				//--></script><!--/LiveInternet-->
