title: Integrating Javascript functions with Grails application
body: <p>I'm in the process of shifting a web application from a PHP/MySQL backend to the Grails framework.  However, the app has a fair bit of legacy javascript code written for it that I'd like to use with minimal re-writing.  Its currently not working, and I'm not sure why.</p>
  
  <p>A friend wrote a fade out slideshow script that requires an array initialized as</p>
  
  <pre><code>var images[3];
  images[0] = ['path to image', 'link to somewhere', 'target'];
  </code></pre>
  
  <p>When writing in PHP, I just used the relative path and double quotes for the link and target, ie</p>
  
  <pre><code>images[0] = ["../images/file.jpg", "", ""]
  </code></pre>
  
  <p>Shifting to Grails, I want to have the slideshow visible on all pages, thus resuling in insertion in main.gsp.</p>
  
  <p>I've declared the javascript link in the head as</p>
  
  <pre><code>&lt;g:javascript src="fade_in.js" /&gt;
  </code></pre>
  
  <p>The way the original script worked was the image array was initalized in the script, then passed in via a function call in the body code.  Since I don't know if its possible to use a Grails <code>createLinkTo</code> function call in a js file, I initialized the array and called the function with</p>
  
  <pre><code>&lt;div id="slideshow"&gt;
    &lt;script type="text/javascript"&gt;
          var images[3];
          images[0] = ["&lt;g:createLinkTo dir='images' file='nsf.jpg' /&gt;", "", ""]
          images[1] = ["&lt;g:createLinkTo dir='images' file='east.jpg'/&gt;", "", ""]
          images[2] = ["&lt;g:createLinkTo dir='images' file='usm_horz.png' /&gt;", "", ""]
          new fadeshow(fadeimages,200,118,0,8000,1,"R");                          
    &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>According to firebug, the paths to the files is correct, but they're not showing up in the specified div position.  I can see where the images should be, and its empty.</p>
  
  <p>So, what needs to be done to integrate this functionality with a Grails app?</p>