/* Javascript: Features functionality
 * Params: none:
 *
 * Use: Attaches a click event to links with class = feature-link and when these links
 *      are clicked, it fires off an AJAX post request to the features/toggle action.  
 *      If a game_id is present (it's taken from the id of the link: toggle-featured-game-<game_id>),
 *      it's sent as a POST parameter along with the object_type and object_id.
 */

$("a.feature-link").click(function(ele) {
   var link = $(ele.target);
   var url = '';
   	if(obj_type == 'Video_Model')
		url = "/videos/toggle/"
	else
		url = "/screenshots/toggle/"

   if(link.attr('id') == 'toggle-featured') {
    $.post(url, {object_type:obj_type, object_id:obj_id}, function(data) {link.replaceWith(data['status']);}, "json");
   } else {
       var link_id = link.attr('id');
       var tmp = link_id.split('-');
       var game = tmp.pop();
       $.post(url, {object_type:obj_type, object_id:obj_id, game_id:game}, function(data) {link.replaceWith(data['status']);}, "json");
   }
});