/**
 * Hide your affiliate links using Javascript
 * 
 * Copyright 2008 Harvey Kane <code@ragepank.com>
 * 
 * See the enclosed file license.txt for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Harvey Kane <code@ragepank.com>
 * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
 * @link    http://www.ragepank.com
 *
 * define your affiliate links in the following format from line 22 onwards...
 * aff['http://www.domain.com/AFFILIATE_LINK/']             = 'http://www.domain.com/REGULAR_LINK/';
 * aff['http://www.domain.com/ANOTHER_AFFILIATE_LINK/']     = 'http://www.domain.com/ANOTHER_REGULAR_LINK/';
 * aff['http://www.domain.com/YET_ANOTHER_AFFILIATE_LINK/'] = 'http://www.domain.com/YET_ANOTHER_REGULAR_LINK/';
 * 
 */

var aff = new Array();

/* define your links here */
aff['/redirect/FlexBelt'] = 'http://www.theflexbelt.com';
aff['/redirect/ContourAbs'] = 'http://www.trycontour.com';

/* do not edit below this point */

/* reverse the key/value pairs so we can lookup based on value */
var aff_reverse = new Array();
for (k in aff) {
    aff_reverse[aff[k]] = k;
}

/* scan all links when the document loads */
$(document).ready(function(){
  $('a').attr('href',function(){
    
    /* if the link isn't listed above, do nothing */
    if (!aff[$(this).attr('href')]) {return $(this).attr('href');}
    /* ok, the link is in our list */
    $(this).click(function(){
        /* when the link is clicked on, revert it back to the affiliate link */
        //$(this).attr('href', aff_reverse[$(this).attr('href')]);
        return true;
    });
    $(this).mouseup(function(){
        /* Firefox ignores onclick event when the link is opened via middle mouse (new tab) */
        $(this).attr('href', aff_reverse[$(this).attr('href')]);
        return true;
    });
    $(this).mouseout(function(){
        /* revert back to non-aff link in case they opened in new tab */
        $(this).attr('href', aff[$(this).attr('href')]);
        return true;
    });
    /* change the affiliate link to a non-affiliate link */
    return aff[$(this).attr('href')];
  });
});