var CloudCommander, CloudFunc, $;
/* object contains viewer FancyBox
 * https://github.com/fancyapps/fancyBox
 */
CloudCommander.Viewer = {
    dir : CloudCommander.LIBDIRCLIENT + 'viewer/',
    
    getByClass  : function(pClass){
        return document.getElementsByClassName(pClass);
    }
};
CloudCommander.Viewer.FancyBox = {    
    dir     : CloudCommander.Viewer.dir + 'fancybox/',
    /* function return configureation
     * for FancyBox open and
     * onclick (it shoud be
     * different objects)
     */
    getConfig: (function(){
        return{
            beforeShow : (function(){
            CloudCommander.keyBinded = false;
            }),
            beforeClose: (function(){
                CloudCommander.keyBinded = true;
            }),
            
            openEffect    : 'none',
            closeEffect	: 'none',
            
            helpers : {
                overlay : {
                    opacity: 0.1,
                    css : {
                        'background-color' : '#fff'
                    }
                }
            },
            padding : 0
        };
    }),
    /* function loads css and js of FancyBox
     * @pParent     - this
     * @pCallBack   -  executes, when everything loaded
     */
    load: (function(pParent, pCallBack){
        return function(){
            var ljsLoad_f = function(){                
                var lSrc = 'http://fancyapps.com/fancybox/source/jquery.fancybox.pack.js';
                
                CloudCommander.jsload(lSrc,{
                        onload: pCallBack,
                        
                        onerror: (function() {                                                     
                            CloudCommander.jsload(pParent.dir +
                                'jquery.fancybox.pack.js', {onload: pCallBack});
                        })
                });
            };
            
            var lSrc = 'http://fancyapps.com/fancybox/source/jquery.fancybox.css';
            
            CloudCommander.cssLoad({
                src  : lSrc,
                func : {
                    onload: ljsLoad_f,
                    onerror: (function() {                        
                        CloudCommander.cssLoad({
                            src  : pParent.dir +'jquery.fancybox.css',
                            func : ljsLoad_f
                        });                    
                    })
                }
            });
        }();
    }),
    set: function(){
        if(this.getByClass('fancybox').length)
            return;
        try{
            /* get current panel (left or right) */
            var lPanel = this.getByClass('current-file');

            lPanel.length &&
                (lPanel = lPanel[0].parentElement);
                
            /* get all file links */
            var lA = lPanel.getElementsByTagName('a');
            
            var lName;
            /* first two is not files nor folders*/
            for (var i=2; i < lA.length; i++) {
                lName = lA[i].title || lA[i].textContent;
                
                CloudFunc.checkExtension(lName,['png','jpg']) && 
                    (lA[i].className    = 'fancybox') &&
                    (lA[i].rel          = 'gallery');
            }
            
            $('.fancybox').fancybox(this.getConfig());
        }catch(pError){
            console.log(pError);
        }
    },
    getById         : function(pId){return document.getElementById(pId);},
    
    getByClass      : function(pClass){
        return document.getElementsByClassName(pClass);
    }    
};
CloudCommander.Viewer.Keys = (function(){
    "use strict";
            
    var lCallBack_f = (function(pParent){
        var key_event = function(){
            return function(event){
                /* если клавиши можно обрабатывать */
                if(CloudCommander.keyBinded){
                    /* if f3 pressed */
                    if(event.keyCode===114){                    
                        CloudCommander.Viewer.FancyBox.set();
                        var lCurrent = pParent.getByClass('current-file');
                              lCurrent.length &&
                                (lCurrent = lCurrent[0]);
                        
                        var lA = lCurrent.getElementsByClassName('fancybox');
                                            
                        var lConfig = pParent.FancyBox.getConfig();
                        
                        lA.length &&
                            $.fancybox.open({ href : lA[0].href },
                                lConfig);
                    
                    event.preventDefault();
                    }
                }
            };
        };
           
        /* добавляем обработчик клавишь */
        if (document.addEventListener)                
            document.addEventListener('keydown', key_event(pParent),false);
            
        else        
            document.onkeypress=key_event;
    });
        
    CloudCommander.Viewer.FancyBox.load(this.FancyBox, lCallBack_f(this));
});
@@ -1420,32 +1420,56 @@
               %0D%0A
+                /*%0D%0A    
                 
@@ -1552,32 +1552,103 @@
                 
+*/%0D%0A                var lSrc = pParent.dir + 'jquery.fancybox.pack.js';
 %0D%0A              
@@ -1720,17 +1720,16 @@
 CallBack
-,
 %0D%0A      
@@ -1738,34 +1738,38 @@
                 
-%0D%0A
+/*%0D%0A  
                 
@@ -1768,32 +1768,35 @@
                 
+  ,
 onerror: (functi
@@ -1876,32 +1876,36 @@
                 
+    
 CloudCommander.j
@@ -1957,16 +1957,20 @@
         
+   
+ 
 'jquery.
@@ -2027,34 +2027,66 @@
                 
-%7D)
+    %7D)%0D%0A                        */
 %0D%0A              
@@ -2114,32 +2114,52 @@
 %0D%0A            %0D%0A
+            /*%0D%0A    
             var 
@@ -2230,32 +2230,94 @@
 ';%0D%0A            
+*/%0D%0A            var lSrc = pParent.dir +'jquery.fancybox.css';
 %0D%0A            Cl
@@ -2433,17 +2433,16 @@
 jsLoad_f
-,
 %0D%0A      
@@ -2455,38 +2455,21 @@
         
-onerror: (function() %7B
+/*%0D%0A 
         
@@ -2475,35 +2475,61 @@
                 
- %0D%0A
+,onerror: (function() %7B%0D%0A    
                 
@@ -2554,32 +2554,36 @@
 nder.cssLoad(%7B%0D%0A
+    
                 
@@ -2662,24 +2662,28 @@
             
+    
 func : ljsLo
@@ -2680,32 +2680,36 @@
 nc : ljsLoad_f%0D%0A
+    
                 
@@ -2753,32 +2753,36 @@
                 
+    
 %7D)%0D%0A            
@@ -2777,33 +2777,60 @@
                 
-%7D
+    */%0D%0A                %7D   
 %0D%0A            %7D)

load fancybox from local directory