
    $(document).ready(function(){
        var tempTitle = '';

        // Video Popup
        $("a.video-play-btn, a.video-preview").fancybox({
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'titlePosition'     : 'inside',
            'overlayColor'      : '#000', 
            'scrolling'         : 'no',
            'onStart'           : function() {
                tempTitle = $("title").html();                    
            },
            'onComplete'        : function() {

                // Force reload for youtube videos
                if( $("#fancybox-inner").html().search("youtube.com") != -1 ) {
                    $("#fancybox-inner").html( $("#fancybox-inner").html() );
                }
                
                // Load flowplayer if there are any on this page
                if ( typeof($f()) != "undefined" && $("#fancybox-inner a.player").flowplayer(0) !== undefined ) {
                    $("#fancybox-inner a.player").flowplayer(0).load();
                }

                document.title = tempTitle;                      
            }, 
            'onCleanup'         : function() {
                
                // Remove/unload flowplayer if there are any on this page
                if ( typeof($f()) != "undefined" && $("#fancybox-inner a.player").flowplayer(0) !== undefined ) {
                    $("#fancybox-inner a.player").flowplayer(0).stop();
                    $("#fancybox-inner a.player").flowplayer(0).close();
                    $("#fancybox-inner a.player").flowplayer(0).unload();
                }

                document.title = tempTitle;                
            }
        });

        // Image Gallery
        $("a[rel=gallery]").fancybox({
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'titlePosition'     : 'inside',
            'overlayColor'      : '#000',
            'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-inside">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
            }
        });
        
        // Video Player
        $("a.player").flowplayer(Workspace.flowplayer);
    });

