data: [],
     state: 'empty',
 
-    init: function(serverURL) {
+    init: function(document, serverURL) {
         this._super();
         this.set('state', 'empty');
         this.serverURL = serverURL;
 
     load: function(force) {
         if (force || this.get('state') == 'empty') {
+            console.log("setting state");
             this.set('state', 'loading');
+            console.log("going ajax");
             $.ajax({
                 url: this.serverURL,
                 dataType: 'json',
-                success: this.loadingSucceeded.bind(this)
+                success: this.loadingSucceeded.bind(this),
+                error: this.loadingFailed.bind(this)
             });
         }
     },
 
-    loadingSucceeded: function(data) {
+    loadingSucceeded: function(data) 
+    {
+        console.log("success");        
+        
         if (this.get('state') != 'loading') {
             alert('erroneous state:', this.get('state'));
         }
         this.set('state', 'synced');
     },
 
+    loadingFailed: function(data) {
+        console.log("failed");
+
+        if (this.get('state') != 'loading') {
+            alert('erroneous state:', this.get('state'));
+        }       
+
+        this.set('state', 'error');
+    },
+
     set: function(property, value) {
         if (property == 'state') {
             console.log(this.description(), ':', property, '=', value);
 
     this._super(element, model, template);
     this.parent = parent;
 
-    console.log("galley model", this.model);
+    console.log("gallery model", this.model);
        
     this.model
       .addObserver(this, 'data', this.modelDataChanged.bind(this))
   
   modelStateChanged: function(property, value) {   
     if (value == 'loading') {
-      this.parent.freeze('Ładowanie...');
+      // this.freeze('Ładowanie...');
     } else {
-      this.parent.unfreeze();
+      this.unfreeze();
     }
   },
 
     $page.hide();
     $('img', $page).unbind();
     
-    $page.empty();
-    
+    $page.empty();    
     this.setPageViewOffset($page, {x:0, y:0});
   },