title: Link should open fancybox ($.fancybox.pos) with the help of the click function
body: <p>I want a button which opens the fancybox rel-group with a certain picture. I'm not quite sure if this works but I'll give it a try. My problem is that I want to execute jQuery if the user clicks on a link. This is the code I have</p>
  
  <pre><code>var js = "jQuery.fancybox.pos("+currentImage+");";
  // create a new function from the "js" string
  var newclick = new Function(js);
  
  jQuery("a.enlarge").click(newclick);
  </code></pre>
  
  <p>The code is based on <a href="https://stackoverflow.com/q/826697/426227">this answer</a>. I hope that 
  <code>jQuery.fancybox.pos(2)</code> works. But currently I'm not getting the click function to work. What I'm doing wrong?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>My current setup:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    var currentImage = 0;
  
    function getCurrImage(carousel, state){
       currentImage = carousel.first-1;
  
       jQuery("a.enlarge").click(function() {
         alert(currentImage);   
         jQuery.fancybox.pos(currentImage);
       });
     }
  
     jQuery.noConflict();
  
     jQuery(document).ready(function() {
         jQuery('#mycarousel').jcarousel({
             scroll:1,
             'itemLoadCallback': getCurrImage 
         }); 
         jQuery('a[rel=example_group]').fancybox({
             'transitionIn': 'none',
             'transitionOut': 'none'
         });
     });
  &lt;/script&gt;
  </code></pre>
  
  <p><code>jQuery.fancybox.pos(currentImage);</code> doesn't work. <code>currentImage</code> seems to be correct, but the alert pops up 4 times if the button was clicked 4 times. That means:</p>
  
  <p>click 1: currentImage=0<br>
  click 2: currentImage=1, currentImage=1<br>
  click 3: currentImage=2, currentImage=2, currentImage=2<br>
  click 4: currentImage=3, currentImage=3, currentImage=3, currentImage=3  </p>
  
  <p><strong>Update:</strong></p>
  
  <p>New try:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    var currentImage = 0;
  
  function openfancy(){
     jQuery.fancybox.pos(currentImage);
  }
  
    function getCurrImage(carousel, state){
       currentImage = carousel.first-1;
  
       jQuery("a.enlarge").unbind("click", openfancy);
       jQuery("a.enlarge").bind("click", openfancy);
     }
  
     jQuery.noConflict();
  
     jQuery(document).ready(function() {
         jQuery('#mycarousel').jcarousel({
             scroll:1,
             'itemLoadCallback': getCurrImage 
         }); 
         jQuery('a[rel=example_group]').fancybox({
             'transitionIn': 'none',
             'transitionOut': 'none'
         });
     });
  &lt;/script&gt;
  </code></pre>
  
  <p><code>jQuery.fancybox.pos(currentImage);</code> still doesn't work. Is there any chance? Perhaps its because I have multiple fancyboxes on that page? I also tried it with <code>jQuery('.fancybox').fancybox.pos(currentImage);</code> but I get the error message that it is not a function.</p>