/* functions to handle ajax request/response for artist similar thumbs/up down voting
// any user who is logged in can do this, so I am not putting this in the artist_similar.js file, which is only for admin
//
// @author jonathan.zuckerman@cnet.com
//
//
// to make this more generic, add ref_type, target and data to the parameters,
// change the 'ref_type=13' in the data variable to be a parameter,
// and then we can integrate this into js/thumbs.js and use the same code for all thumb functions
*/

function voteSimilar(ref_id, direction, clear_cache_id) {

    // give the user some positive feed back that their vote is being counted
    $('similar_thumb_vote_' + ref_id).setHTML('Voting... please wait.');

    // then perform the action
    var target = MP3_BASE_URL + '/index.php';
    var data = 'type=Thumbs&event=Response&action=vote&ref_type=13&id=' + ref_id + '&dir=' + direction + '&ccid=' + clear_cache_id; // 13 = REF_TYPE_MP3_SIMILAR_ARTIST
    new Ajax(target, {
                      postBody: data,
                      method: 'post',
                      onComplete: processVoteResponse
                     }
             ).request();
    return false;
}

function processVoteResponse(results) {
    if (results) {
        // set the data array to be the response of the ajax
        var json_results = Json.evaluate(results);

        var ref_id = json_results['ref_id'];

        var slider = new Fx.Slide('similar_thumb_vote_'+ref_id, {duration: 300});

        slider.slideOut().chain(function() {
            $('similar_thumb_vote_' + ref_id).setHTML(json_results['content']);
            slider.slideIn();
        });
        //$('similar_thumb_vote_' + ref_id).setStyle('display', 'block');
    }
}