/**
 * JS Routing System for Ajax.
 */
var Routing = {

  cache : false,
  routes : {},

  registerRoutes : function(routes) {
    this.routes = jQuery.extend(this.routes, routes);
  },
  /**
   * Returns a registered route, if it exists.
   */
  getRoute : function (route_name)
  {
    if (this.routes)
      if (this.routes[route_name])
        return this.routes[route_name];
    return false;
  },
  /**
   * Starts the Sync
   */
  startSync : function () 
  {
    var callback = arguments[0] || jQuery.noop;
    
    if (!jQuery.isFunction(callback))
      callback = jQuery.noop;
    $.ajax( {
      cache: this.cache,
      type : 'GET',
      url : this.routes['startSync'],
      data : null,
      success : callback
    });
  },
  /**
   * Returns Sync Status
   */
  getStatus : function ()
  {
    var callback = arguments[0] || jQuery.noop;
    
    if (!jQuery.isFunction(callback))
      callback = jQuery.noop;
    $.ajax( {
      cache: this.cache,
      type : 'GET',
      url : this.routes['getStatus'],
      data : null,
      success : callback
    });
  },
  /**
   * Will get a Picture in big
   */
  getPicture : function (picture_id)
  {
    var callback = arguments[1] || jQuery.noop;
    
    if (!jQuery.isFunction(callback))
      callback = jQuery.noop;
    $.ajax( {
      cache: this.cache,
      type : 'POST',
      url : this.routes['getPicture'],
      data : {
        "picture_id" : picture_id
      },
      success : callback
    });
  },
  /**
   * Will remember the provided vehicle in the user session.
   */
  rememberVehicle : function(id) {
    var callback = arguments[1] || jQuery.noop;
    if (!jQuery.isFunction(callback))
      callback = jQuery.noop;
    $.ajax( {
      cache: this.cache,
      type : 'POST',
      url : this.routes['rememberVehicle'],
      data : { "vehicle_id" : id },
      success : callback
    });
  },
  forgetVehicle : function(id) {
    var callback = arguments[1] || jQuery.noop;
    if (!jQuery.isFunction(callback))
      callback = jQuery.noop;
    $.ajax( {
      cache: this.cache,
      type : 'POST',
      url : this.routes['forgetVehicle'],
      data : { "vehicle_id" : id },
      success : callback
    });
  }
};

