// Rough idea for the Ajax call JS
//
var UpdateFavourites = {
    // JS Function for sending data
    // So your button onclick event would be something like
    // onclick="UpdateFavourites.SendData(this, 1, true); return false;"
    // where this is the current click link (only needed for the list page),
    // 1 would be the villa ID and 
    // true is if the call is from a list page.
    //
    // You need to code the PHP file to return a JSON string 
    // with an added property that is a boolean value. 
    // EG added = true
    // 
    // This is to be used in the 
    // update functions
    //
    SendData:function(Link, VillaId, IsListPage){
      $.post("../../ajaxfavourites.php", { villa: VillaId },
    
        // This is the callback function
        function(data){
          // alert("Data Loaded: " + data);

          if(IsListPage){
              // Update list page
              UpdateFavourites.UpdateListPage(Link, data);
          }else{
              // Update detail page
              UpdateFavourites.UpdateDetailPage(data);
          }
        }, "json");
    },
    
    // JS Function for updating list page
    UpdateListPage:function(Link, data){
        // Update function goes here
        // Each list link will need a seperate ID.
        if(data.added){
          // Set button to remove
          $("#" + Link.id + "img").src = "path to remove image"
        }else{
          // Set button to add
          $("#" + Link.id + "img").src = "path to remove image"
        }
    },
    
    // JS Function for updating detail page
    UpdateDetailPage:function(data){
        // Update function goes here
        if(data.added){
          // Set buttons to remove
          $("#link1").attr('src', 'http://www.thesicilianvillacompany.com/images/assets/remove-favourites.gif');
          $("#link2").attr('src', 'http://www.thesicilianvillacompany.com/images/assets/remove-favourites-prices.gif');
        }else{
          // Set buttons to add
          $("#link1").attr('src', 'http://www.thesicilianvillacompany.com/images/assets/add-favourites-summary.gif');
          $("#link2").attr('src', 'http://www.thesicilianvillacompany.com/images/assets/add-favourites-prices.gif');
        }
    }
}

// NOTE: not sure if $(#link1 img).src = "path to remove image"
// is the correct way to change an image src in JQuery, 
// so you'll have to check.
