function ajax_cart(add_link){
  $.ajax({
    method: "GET",
    url: add_link.attr('href'),
    success: function(out){
      if(out){
        add_link.show();
        out=eval("("+out+")");
        add_link.parent().parent().find('span').html(out.add+' в <a href="cart.php">тележку<\/a> ('+out.count+' шт.)');
        add_link.html('<img src="img/cart.png" border="0" \/> добавить');
        add_link.parent().find('span').html('ещё '+out.one);
        $('#cart').html(out.cart);
        add_link.parent().parent().animate({ backgroundColor: "#fdfeae" }, "slow")
      }
      else{
        add_link.show();
        add_link.parent().parent().find('span').html('<span style="color:red">ошибка!<\/span>');
        add_link.html('<img src="img/cart.png" border="0" \/> положить');
        add_link.parent().find('span').html('в тележку');
      }
    },
    error: function(){
      add_link.show();
      add_link.parent().parent().find('span').html('<span style="color:red">ошибка!<\/span>');
      add_link.html('<img src="img/cart.png" border="0" \/> положить');
      add_link.parent().find('span').html('в тележку');
    }
  });

  return 1;
}
function ajax_cart2(add_link){
  $.ajax({
    method: "GET",
    url: add_link.attr('href'),
    success: function(out){
      if(out){
        add_link.show();
        out=eval("("+out+")");
        add_link.parent().find('div').show();
        add_link.parent().find('div').css({color:"#000000"});
        add_link.parent().find('div').html(out.add+' в <a href="cart.php">тележку<\/a> ('+out.count+' шт.)');
        add_link.html('<img src="img/cart.png" border="0" \/> добавить');
        add_link.parent().find('span').html('ещё '+out.one);
        $('#cart').html(out.cart);
        //add_link.parent().parent().animate({ backgroundColor: "#fdfeae" }, "slow")
      }
      else{
        add_link.show();
        add_link.parent().find('div').show();
        add_link.parent().find('div').css({color:"red"});
        add_link.parent().find('div').html('ошибка!');
        add_link.html('<img src="img/cart.png" border="0" \/> положить');
        add_link.parent().find('span').html('в тележку');
      }
    },
    error: function(){
        add_link.show();
        add_link.parent().find('div').show();
        add_link.parent().find('div').css({color:"red"});
        add_link.parent().find('div').html('ошибка!');
        add_link.html('<img src="img/cart.png" border="0" \/> положить');
        add_link.parent().find('span').html('в тележку');
    }
  });

  return 1;
}
$(document).ready(function(){

  $('a.add_link').click(function(){
    $(this).hide();
    $(this).parent().find('span').html('<img src=\"img\/0.gif\" height=\"18\" width=\"1\" \/>добавление&#8230;');
    ajax_cart($(this));
    return false;
  });
  $('a.c_add_link').click(function(){
    $(this).hide();
    $(this).parent().find('span').html('<img src=\"img\/0.gif\" height=\"18\" width=\"1\" \/>добавление&#8230;');
    ajax_cart2($(this));
    return false;
  });
  $('.login').click(function(){
    if(!$('.login_form').length){      //создать див
      $(this).after("<div class=\"login_form\"><a href=\"index.php\" class=\"login_close\"><span>закрыть</span></a><form name=\"form1\" method=\"post\" action=\"login.php\"><ul><li><span>e-mail:</span><input class=\"text\" type=\"text\" name=\"email\" /></li><li><span>пароль:</span><input class=\"text\" type=\"password\" name=\"pass\" /></li><li><input class=\"submit\" type=\"submit\" value=\"Войти\" /></li></ul></form><a class=\"reg\" href=\"register.php\">регистрация</a></div>");
      $('.login_form').animate({height:"200px",width:"300px"},'fast',function(){$('.login_form .text:first').focus();});
    }
    else{      $('.login_form').animate({height:"50px",width:"50px"},'fast',function(){
        $('.login_form').remove();
      });
    }
    return false;
  });
  $('.login_close').livequery('click',function(){    if($('.login_form').length){      $('.login_form').animate({height:"50px",width:"50px"},'fast',function(){        $('.login_form').remove();      });
    }
    return false;
  });
});
