

function add_comp(pid,event)
{
var comp_count=$("#comp_count").html();

if(comp_count=="")
{
comp_count=0;
}
comp_count=parseInt(comp_count);

var status=$("#comp_"+pid).attr("status");
if(status=="none")
{


jQuery.post('jsgate.php', { action: "add_to_comp", productID: pid },function(data) {
if(data=="done")
{
$("#comp_"+pid).html("Убрать из сравнений");
$("#comp_"+pid).attr("status","in_comp");


//animate
var blk=$("#"+pid).html();
var curs=mousePageXY(event);
var posx=curs.x-174;
var posy=curs.y-400;
var rand=Math.floor(Math.random()*11);
blk="<div style='position: absolute;z-index: 1; left: "+posx+"px; top: "+posy+"px ; border-radius: 5px; -moz-border-radius: 5px;-webkit-border-radius: 5px;opacity: 0.9 ;display:none' id='animate-me"+rand+"'>"+blk+"</div>";

$("html").append(blk);
$("#animate-me"+rand).fadeIn(500);
if(anim_block('animate-me'+rand)!=true)
{
$('#animate-me'+rand).remove();
}
//


}
});
comp_count++;
}
else if(status=="in_comp")
{
jQuery.post('jsgate.php', { action: "del_comp", productID: pid },function(data) {
if(data=="done")
{
$("#comp_"+pid).html("Добавить к сравнению");
$("#comp_"+pid).attr("status","none");

}
});

comp_count--;
}

//update block
if(comp_count>0)
{
$("#comp_count").html(comp_count);
$("#comparison_block").show();
}
else
{
$("#comp_count").html(comp_count);
$("#comparison_block").hide();
}



}












function mousePageXY(e)
{
  var x = 0, y = 0;

  if (!e) e = window.event;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  return {"x":x, "y":y};
}


function anim_block(id)
{



$("#"+id)
.animate({top: '-=200'}, 1000)
.animate({left: '+=500',opacity: 0.1}, 600)
.fadeOut('slow', function()
{
$("#"+id).remove();
}
);


return true;






}






function AddProdInCard(pid)
{
    var url_php  = '/ajax_addtocard.php';
	 // document.getElementById('isnewprodajaxtmp').innerHTML="<div class='loadin' align='center'><img src='images/loading.gif' /></div>"         
   
    /*$('#isnewprodajax').fadeOut("slow");    
    document.getElementById('isnewprodajaxtmp').innerHTML="";*/
      mleft=parseInt($(window).width()/2 - $('#hiddenpopdiv').width()/2);
      mtop=parseInt($(window).height()/2 - $('#hiddenpopdiv').height()/2);
      
      $('#hiddenpopdiv').css({'left':mleft,'top':mtop});
      
      $('#hiddenpopdiv').fadeIn('medium')
      .animate({opacity: "0.9"}, "slow");
	  
$.post('jsgate.php', { action: "add_to_cart", productID: pid },function(data) {

if(data=="done")
{
        $('#hiddenpopdiv').html('<h3>Товар добавлен в корзину!</h3>')
        .animate({opacity: "0.9", top: "-="+parseInt(mtop-100)}, "slow")
        .animate({opacity: "0", left: "+=270"}, "slow")
        .fadeOut("slow");

update_cart();

}
});
}
