// <![CDATA[
/**
 * 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['http://ad.zanox.com/ppc/?15542233C109563131T&ULP=[[http://viaggi.kelkoo.it/ni/d-vacanze,2010-08,Europa,Italia,Sardegna,Orosei-171101]]'] = 'http://viaggi.kelkoo.it/';
aff['http://ad.zanox.com/ppc/?15542238C2100800387T&ULP=[[http://www.vacanzerei.com/index.php/Sardegna/mare-italia-sardegna]]'] = 'http://www.vacanzerei.com/';
aff['http://ad.zanox.com/ppc/?15554685C1085107655T&ULP=SARDEGNA]]'] = 'http://www.tui.it/';
aff['http://ad.zanox.com/ppc/?8935711C1769385198T'] = 'http://www.moby.it/';
aff['http://ad.zanox.com/ppc/?15549826C1007259145T'] = 'http://www.meridiana.it/';
aff['http://ad.zanox.com/ppc/?14458300C1908356182T'] = 'http://www.it.lastminute.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')];
  });
});
// ]]>
