
$(function() {

    /**
     *  loads similar artist info
     *  
     *  @param artistId
     *  
     */

    function getSimilarArtists( artistId ) {
        
        $.ajax({
            type: 'GET',
            url: '/json/similarArtists/' +artistId,
            success: function( responseText ) {

                var related = $( '<ul/>' );

                eval( 'var artists = ' +responseText );

                for ( var i=0; i<artists.length; i++ ) {
                    var artist = artists[ i ];
                    $( '<li/>' )
                       .append(
                           $( '<a/>' )
                               .attr({ href: '/browse/artist/' +artist.id.substring(2) })
                               .html( artist.name )
                       )
                       .appendTo( related );
                }

                $( '.artist-' +artistId ).append( related );

            }
        });
        
    }

    //
    //  look for related divs with artist info
    //

    if ( Properties.get("www.similarArtists.disable") != 'yes' ) {

        $( '.related' ).each(function(){

            var classes = $(this).attr('class').split( ' ' );

            for ( var i=0; i<classes.length; i++ ) {
                var name = classes[ i ];
                var info = name.match( /artist-(\d+)/ );
                if ( info ) {
                    getSimilarArtists( info[1] );
                }
            }

        });

    }

});