jQuery(function($){
    $('a.popup').placeicon('newwin');
    $('.content a[href ^="http:"]').placeicon('extlink');
    $('.content a[href ^="mailto:"]').placeicon('mail-closed');
    $('.content a[href ^="/ext/download"]').placeicon('circle-arrow-s');
});

jQuery.fn.placeicon = function(icon){
    var $icon = $('<img src="ext/images/spacer.gif" class="ui-icon ui-icon-'+icon+'" style="display:inline-block;position:relative;" />');
    this.each(function(){
        if( $(this).hasClass('no-icon') )
            return true;

        var $img = $(this).children('img:only-child');
        if( $(this).text() ) $img = false;
        if( $img && $img.length ){
            $(this)
                .mouseenter(function(){
                    $icon.position({
                        my: 'left top',
                        at: 'right top',
                        of: $img
                    });
                })
                .mouseleave(function(){
                    $icon.offset({top: 0, left: -20});
                });
        } else {
            $(this).append($icon.clone());
        }
    });
    $('body').append(
        $icon
            .css('position','absolute')
            .offset({top: 0, left: -20})
    );
    return this;
}

