How to load a view with ajax with all js files needed?
What you did is a HardCode solution ,I suggest you instead of loading JS on block, put your JS in .JS files and add ( or attached) to page you want, with simple if your JavaScript just works for you, and remain only one problem, how pass NID to JS?

Pass it with something like     

drupal_add_js(array('YOURMODULE' =&gt; array('nid' =&gt; $nid)), array('type' =&gt; 'setting'));


and get it on your js with 

nid = Drupal.settings.YOURMODULE.nid;


1
down vote

There is a lot of documentation about how to include a JS file into a custom module or into your theme in general. Here is the official article: https://www.drupal.org/node/304255

There are plenty of examples and you can inspire yourself with it.