you need to put the javascript in a template and call the template with your plugin code.
for example create a template called mystatcounter, dump your block of code in there and save it. Then create a statcounter plugin with something like :
PHP Code:
eval('$statcounter .= "' . fetch_template('mystatcounter') . '";');
then you just need to place $statcounter where ever you want the code to execute... HTH