/*jslint white: false, onevar: false
*/
/*global $ document location jQuery escape alert
*/

jQuery.trk = function(cb) {
    var now = Math.round(new Date().getTime()/1000.0);
    var uri = "?now=" + now + ";href=" + escape(location.href) + ";ref=" + escape(document.referrer);

    $("img").filter(function(){ return $(this).attr("src").match("^/trk") ? true : false; }).each(function(){

        $(this).attr("src", $(this).attr("src") + uri);

        if( cb )
            $(this).each(cb);

    });

    $("img.trk").filter(function(){ return $(this).attr("src").match("^/trk") ? false : true; }).each(function(){

        $(this).attr("src", "/trk/" + $(this).attr("src") + uri);

        if( cb )
            $(this).each(cb);

    });
};

