// the flaggable that was clicked
var flaggableId = 0;

$(document).ready(function() {
   
   // change the href of the "flag" links so they use the ajax form
   // and register clicks
   $('a.flag').each(function(i, a) {
      
      var href = $(a).attr('href');
      var parts = href.split('/');
      
      // set the 'flag' part of the url to 'ajax-flag'
      if (parts.length > 2)
         parts[2] = 'ajax-flag';
      
      // reset the href   
      $(a).attr('href', parts.join('/') + '?width=600&amp;height=300');
      
      // register the click so that it sets flaggableId
      $(a).click(function() {
         
         // get the id part of the url and set the global
         var heef = $(this).attr('href');
         var parts = href.split('/');
         
         if (parts.length > 3)
            flaggableId = parts[3];
         
         return true;
      });
      
   });      
});
