/**
 * BAFTA URL Maps
 * Maps a JS method to a Django URL, this means urls can be altered without affecting the JS app
 * POKE London
 * Chris Reeves
 */
 
/**

  USAGE
  =====

  BASIC
  ----------------
  Each url is degined as a method, for example BAFTA.urls.example() would return a url
  to www.example.com/example.

  ADVANCED
  ----------------
  Some urls may require placeholder arguments for django to perform the reverse url method, so we might define this like:
  {[%] url example1 arg1,arg2 [%]}
  This script has a method fo swapping placeholder args with the desired correct args, for example:
  BAFTA.urls.example2 = function(arg1, arg2) {
    dict = {
     arg1: {
       placeholder: 'arg1',
       arg: arg1
     },
     arg2: {
       placeholfer: 'arg2',
       arg: arg2
     }
     return this.replace_holders('{[%] url exaple2 arg1,arg2 [%]}', dict);
    }
  }
  this will return back a url with the corret arguments, you can then call this:
  BAFTA.urls.example2(21312, 4823);
  which will return something like:
  www.example2.com/example2/21312/4823/
  Which you can then use in an ajax call 

  There is probably a more eligant way of achieving this, if you think of a way let me know :)

  Note: django template ({%) tags in these comments are noted as {[%] url [%]} to prevent django from interpreting these as real
  requests.
  
**/

BAFTA.urls = {}

BAFTA.urls.replace_holders = function(url, dict, type) {
    if(!type) {
        type = 'url'
    }
    for(arg in dict) {
        var obj = dict[arg];
        if(type == 'url') {
           url = url.replace('/' + obj.placeholder + '/', '/' + obj.arg + '/'); 
        }
        if(type == 'filename') {
           url = url.replace('/' + obj.placeholder, '/' + obj.arg); 
        }
    }
    return url;
}

BAFTA.urls.static_url = function() {
    return 'http://cdn.bafta.orange.co.uk/cdn/1329918847/static/';
}

BAFTA.urls.media_url = function() {
    return 'http://cdn.bafta.orange.co.uk/cdn/media/';
}

BAFTA.urls.alter_nominee_position = function() {
    return '/rising-star-award/alter_nominee_position/';
}

BAFTA.urls.get_event_url = function(arg1) {
    dict = {
        arg1: {
            placeholder: 'arg1.json',
            arg: arg1 + '.json'
        }
    }
    return this.replace_holders('/calendar/event/arg1.json', dict, 'filename');
}
