Preview uploaded files (documents & photos
<p>I have a files library that contains documents (pdf, doc, xls) and photos. I need a method to help me preview files before I download them using google docs (for pdf &amp; doc.) and simple integration code for photos.<br>
I was using fancybox using this code:<br></p>

<pre><code>if ($document-&gt;get_preview() == "document"){
        ?&gt;
                       &lt;script type="text/javascript" language="javascript"&gt;
&lt;!--
&lt;?php
echo("
jQuery(document).ready(function() {
    jQuery(\"a[class*=document-$doc_id]\").fancybox({
    'width'             : '75%',
    'height'            : '75%',
    'href'          : '$link',
    'autoScale'         : false,
    'transitionIn'      : 'none',
    'transitionOut'     : 'none',
    'type'              : 'iframe'
    });
});
");
?&gt;
// --&gt;
              &lt;/script&gt;
              &lt;?php } else {?&gt;
              &lt;script type="text/javascript" language="javascript"&gt;
&lt;!--
&lt;?php
echo("
jQuery(document).ready(function() {
    jQuery(\"a[class*=url_img-$doc_id]\").fancybox({
    'overlayOpacity'    :   0.7,
    'overlayColor'      :   '#000000',
    'href'              :  '$link',
    'transitionIn'      : 'elastic',
    'transitionOut'     : 'elastic',
    'easingIn'          : 'easeOutBack',
    'easingOut'         : 'easeInBack',
    'speedIn'           : '700',
    'centerOnScroll'    : true
    });
});
");
?&gt;
// --&gt;
              &lt;/script&gt;
              &lt;?php }?&gt;
</code></pre>

<p><code>get_preview()</code> is a function that verifies if the file is a document or photo using extensions.</p>

<p>In the previous code the job is repeated for every file so it cause slow page loading. Is there any alternative to this solution?</p>
