/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function controll_cart(force){
    // cart object
    var check = $("#cartHolder").css('display');

    if(force){
        if(force == 'show' && check != ''){
            $("#cartHolder").show("slow");
        }
    } else {
        if (check == 'none' || check == 'unknown'){
            $("#cartHolder").show("slow");
        } else {
            $("#cartHolder").hide("slow");
        }
    }

    
}

function addToCart(id){

    $.ajax({
      url: "/add_to_cart/"+id,
      cache: false,
      success: function(){
          setTimeout("generateCart()",500)
      }
    });
    controll_cart('show');
}

function generateCart(){
    $.ajax({
      url: "/show_cart",
      cache: false,
      success: function(html){
        $("#cartList").html(html);
      }
    });
    generateTotalPrice();
}
function generateTotalPrice(){
    $.ajax({
      url: "/show_total",
      cache: false,
      success: function(html){
        $("#cartTotal").html(html);
      }
    });
}

function removeFromCart(id){
      $.ajax({
          url: "/remove_from_cart/"+id,
          cache: false,
          success: function(){
              setTimeout("generateCart()",500)
          }
        });
}

function refreshCart(){
    var str = $("#cartForm").serialize();
    $.ajax({
            type: "POST",
            url: "/refresh_cart",
            data: str,
            success: function(){
              setTimeout("generateCart()",500)
          }
    });
}