diff --git a/.htaccess b/.htaccess
index 181248267559e377dbac74e01b395cbc215558f6..8763a8bcde5c23897d4393d47430cc72241ea259 100644
--- a/.htaccess
+++ b/.htaccess
@@ -1,7 +1,8 @@
-ErrorDocument 404 //owncloud/core/templates/404.php
+ErrorDocument 404 /owncloud/core/templates/404.php
 <IfModule mod_php5.c>
-	php_value upload_max_filesize 512M
-	php_value post_max_size 512M
-	SetEnv htaccessWorking true
+php_value upload_max_filesize 512M
+php_value post_max_size 512M
+php_value memory_limit 128M
+SetEnv htaccessWorking true
 </IfModule>
 Options -Indexes
diff --git a/apps/gallery/ajax/cover.php b/apps/gallery/ajax/cover.php
new file mode 100644
index 0000000000000000000000000000000000000000..375905ec52056d215353bec939c78129bf89cb85
--- /dev/null
+++ b/apps/gallery/ajax/cover.php
@@ -0,0 +1,62 @@
+<?php
+require_once('../../../lib/base.php');
+
+function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
+    //getting the image dimensions  
+    list($width_orig, $height_orig) = getimagesize($imgSrc);   
+    switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
+      case "jpeg":
+      case "jpg":
+        $myImage = imagecreatefromjpeg($imgSrc);
+        break;
+      default:
+        exit();
+    }
+    $ratio_orig = $width_orig/$height_orig;
+    
+    if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
+       $new_height = $thumbnail_width/$ratio_orig;
+       $new_width = $thumbnail_width;
+    } else {
+       $new_width = $thumbnail_height*$ratio_orig;
+       $new_height = $thumbnail_height;
+    }
+    
+    $x_mid = $new_width/2;  //horizontal middle
+    $y_mid = $new_height/2; //vertical middle
+    
+    $process = imagecreatetruecolor(round($new_width), round($new_height)); 
+
+    imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
+    $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height); 
+    imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
+
+    imagedestroy($process);
+    imagedestroy($myImage);
+    return $thumb;
+}
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+	echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'You need to log in.')));
+	exit();
+}
+$box_size = 200;
+$album_name = $_GET['album'];
+$x = $_GET['x'];
+
+$stmt = OC_DB::prepare('SELECT file_path FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.uid_owner = ? AND album_name = ? AND *PREFIX*gallery_photos.album_id == *PREFIX*gallery_albums.album_id');
+$result = $stmt->execute(array(OC_User::getUser(), $album_name));
+$x = min((int)($x/($box_size/$result->numRows())), $result->numRows()-1); // get image to display
+$result->seek($x); // never throws
+$path = $result->fetchRow();
+$path = $path['file_path'];
+$tmp = OC::$CONFIG_DATADIRECTORY . $path;
+$imagesize = getimagesize($tmp);
+
+header('Content-Type: image/png');
+$image = CroppedThumbnail($tmp, $box_size, $box_size);
+
+imagepng($image);
+imagedestroy($image);
+?>
diff --git a/apps/gallery/ajax/createAlbum.php b/apps/gallery/ajax/createAlbum.php
new file mode 100644
index 0000000000000000000000000000000000000000..3a490bdc3bd35d83db91fd8c260202e978271f4f
--- /dev/null
+++ b/apps/gallery/ajax/createAlbum.php
@@ -0,0 +1,14 @@
+<?php
+require_once('../../../lib/base.php');
+
+if( !OC_User::isLoggedIn()){
+	echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'You need to log in.')));
+	exit();
+}
+
+$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES ("'.OC_User::getUser().'", "'.$_GET['album_name'].'")');
+$stmt->execute(array());
+
+echo json_encode(array( 'status' => 'success', 'name' => $_GET['album_name']));
+
+?>
diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php
new file mode 100644
index 0000000000000000000000000000000000000000..6b551ac49d519d879dc911ffdc48747e56297edd
--- /dev/null
+++ b/apps/gallery/ajax/getAlbums.php
@@ -0,0 +1,22 @@
+<?php
+require_once('../../../lib/base.php');
+
+if (!OC_User::IsLoggedIn()) {
+  echo json_encode(array('status' => 'error', 'message' => 'You need to log in'));
+  exit();
+}
+
+$a = array();
+$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?');
+$result = $stmt->execute(array(OC_User::getUser()));
+
+while ($r = $result->fetchRow()) {
+  $album_name = $r['album_name'];
+  $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?');
+  $tmp_res = $stmt->execute(array($r['album_id']));
+  $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10));
+}
+
+echo json_encode(array('status'=>'success', 'albums'=>$a));
+
+?>
diff --git a/apps/gallery/ajax/getCovers.php b/apps/gallery/ajax/getCovers.php
new file mode 100644
index 0000000000000000000000000000000000000000..d56bf6fa4b7e5ce3bec3b9ae0f774989cf80086b
--- /dev/null
+++ b/apps/gallery/ajax/getCovers.php
@@ -0,0 +1,66 @@
+<?php
+require_once('../../../lib/base.php');
+
+function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $shift) { 
+    //getting the image dimensions
+    list($width_orig, $height_orig) = getimagesize($imgSrc); 
+    switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
+      case "jpeg":
+      case "jpg":
+      case "tiff":
+        $myImage = imagecreatefromjpeg($imgSrc);
+        break;
+      case "png":
+        $myImage = imagecreatefrompng($imgSrc);
+        break;
+      default:
+        exit();
+    }
+    $ratio_orig = $width_orig/$height_orig;
+    
+    if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
+       $new_height = $thumbnail_width/$ratio_orig;
+       $new_width = $thumbnail_width;
+    } else {
+       $new_width = $thumbnail_height*$ratio_orig;
+       $new_height = $thumbnail_height;
+    }
+    
+    $x_mid = $new_width/2;  //horizontal middle
+    $y_mid = $new_height/2; //vertical middle
+    
+    $process = imagecreatetruecolor(round($new_width), round($new_height)); 
+
+    imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
+    imagecopyresampled($tgtImg, $process, $shift, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
+
+    imagedestroy($process);
+    imagedestroy($myImage);
+}
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+	echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'You need to log in.')));
+	exit();
+}
+$box_size = 200;
+$album_name= $_GET['album_name'];
+
+$stmt = OC_DB::prepare('SELECT file_path FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.uid_owner = ? AND album_name = ? AND *PREFIX*gallery_photos.album_id == *PREFIX*gallery_albums.album_id');
+$result = $stmt->execute(array(OC_User::getUser(), $album_name));
+
+$numOfItems = min($result->numRows(),10);
+
+$targetImg = imagecreatetruecolor($numOfItems*$box_size, $box_size);
+$counter = 0;
+while (($i = $result->fetchRow()) && $counter < $numOfItems) {
+  $imagePath = OC::$CONFIG_DATADIRECTORY . $i['file_path'];
+  CroppedThumbnail($imagePath, $box_size, $box_size, $targetImg, $counter*$box_size);
+  $counter++;
+}
+
+header('Content-Type: image/png');
+
+imagepng($targetImg);
+imagedestroy($targetImg);
+?>
diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php
new file mode 100644
index 0000000000000000000000000000000000000000..a04ad62b1bff2e7be927b50ff9aea6337416f3f7
--- /dev/null
+++ b/apps/gallery/ajax/scanForAlbums.php
@@ -0,0 +1,14 @@
+<?php
+
+require_once('../../../lib/base.php');
+require_once('../lib_scanner.php');
+
+if (!OC_User::IsLoggedIn()) {
+  echo json_encode(array('status' => 'error', 'message' => 'You need to log in'));
+  exit();
+}
+
+echo json_encode(array( 'status' => 'success', 'albums' => OC_GALLERY_SCANNER::scan('')));
+//echo json_encode(array('status' => 'success', 'albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa')))));
+
+?>
diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php
new file mode 100644
index 0000000000000000000000000000000000000000..db428eeff34983f6b6f3ad45bcfd668429712ef1
--- /dev/null
+++ b/apps/gallery/ajax/thumbnail.php
@@ -0,0 +1,58 @@
+<?php
+require_once('../../../lib/base.php');
+
+function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
+    //getting the image dimensions  
+    list($width_orig, $height_orig) = getimagesize($imgSrc);   
+    switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
+      case "jpeg":
+      case "jpg":
+      case "tiff":
+        $myImage = imagecreatefromjpeg($imgSrc);
+        break;
+      case "png":
+        $myImage = imagecreatefrompng($imgSrc);
+        break;
+      default:
+        exit();
+    }
+    $ratio_orig = $width_orig/$height_orig;
+    
+    if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
+       $new_height = $thumbnail_width/$ratio_orig;
+       $new_width = $thumbnail_width;
+    } else {
+       $new_width = $thumbnail_height*$ratio_orig;
+       $new_height = $thumbnail_height;
+    }
+    
+    $x_mid = $new_width/2;  //horizontal middle
+    $y_mid = $new_height/2; //vertical middle
+    
+    $process = imagecreatetruecolor(round($new_width), round($new_height)); 
+
+    imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
+    $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height); 
+    imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
+
+    imagedestroy($process);
+    imagedestroy($myImage);
+    return $thumb;
+}
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+	echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'You need to log in.')));
+	exit();
+}
+$box_size = 200;
+$img = $_GET['img'];
+
+$tmp = OC::$CONFIG_DATADIRECTORY . $img;
+
+header('Content-Type: image/png');
+$image = CroppedThumbnail($tmp, $box_size, $box_size);
+
+imagepng($image);
+imagedestroy($image);
+?>
diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php
new file mode 100644
index 0000000000000000000000000000000000000000..5760bb149d819fafa0831130f050232bdc975ba2
--- /dev/null
+++ b/apps/gallery/appinfo/app.php
@@ -0,0 +1,27 @@
+<?php
+OC_App::register(array(
+  'order' => 20,
+  'id' => 'gallery',
+  'name' => 'Gallery'));
+
+OC_App::addNavigationEntry( array(
+ 'id' => 'gallery_index',
+ 'order' => 20,
+ 'href' => OC_Helper::linkTo('gallery', 'index.php'),
+ 'icon' => OC_Helper::linkTo('', 'core/img/filetypes/image.png'),
+ 'name' => 'Gallery'));
+
+ class OC_GallerySearchProvider extends OC_Search_Provider{
+	function search($query){
+		$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name LIKE ?');
+		$result = $stmt->execute(array(OC_User::getUser(),'%'.$query.'%'));
+		$results=array();
+		while($row=$result->fetchRow()){
+			$results[]=new OC_Search_Result($row['album_name'],'',OC_Helper::linkTo( 'apps/gallery', 'index.php?view='.$row['album_name']),'Galleries');
+		}
+		return $results;
+	}
+}
+
+new OC_GallerySearchProvider();
+?>
diff --git a/apps/gallery/appinfo/database.xml b/apps/gallery/appinfo/database.xml
new file mode 100644
index 0000000000000000000000000000000000000000..fd55b3a6fb4cd320e8b3d8b34d11415185671d85
--- /dev/null
+++ b/apps/gallery/appinfo/database.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<database>
+	 <name>*dbname*</name>
+	 <create>true</create>
+	 <overwrite>false</overwrite>
+	 <charset>latin1</charset>
+	 <table>
+		<name>*dbprefix*gallery_albums</name>
+		<declaration>
+			<field>
+				<name>album_id</name>
+				<type>integer</type>
+				<default>0</default>
+			    <notnull>true</notnull>
+    			<autoincrement>1</autoincrement>
+			    <length>4</length>
+			</field>
+			<field>
+				<name>uid_owner</name>
+				<type>text</type>
+				<notnull>true</notnull>
+				<length>64</length>
+			</field>
+			<field>
+				<name>album_name</name>
+				<type>text</type>
+				<notnull>true</notnull>
+				<length>100</length>
+			</field>
+		</declaration>
+	</table>
+	<table>
+		<name>*dbprefix*gallery_photos</name>
+		<declaration>
+			<field>
+				<name>photo_id</name>
+				<type>integer</type>
+				<default>0</default>
+			    <notnull>true</notnull>
+			    <autoincrement>1</autoincrement>
+			    <length>4</length>
+			</field>
+			<field>
+				<name>album_id</name>
+				<type>integer</type>
+				<default>0</default>
+			    <notnull>true</notnull>
+			    <length>4</length>
+			</field>
+			<field>
+				<name>file_path</name>
+				<type>text</type>
+				<notnull>true</notnull>
+				<length>100</length>
+			</field>
+		</declaration>
+	</table>
+</database>
diff --git a/apps/gallery/appinfo/info.xml b/apps/gallery/appinfo/info.xml
new file mode 100644
index 0000000000000000000000000000000000000000..154b5fcf7ae719f2804871029fa4efe2eb5139ec
--- /dev/null
+++ b/apps/gallery/appinfo/info.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?> 
+<info>
+	<id>gallery</id>
+	<name>Gallery</name>
+	<version>0.1</version>
+	<licence>AGPL</licence>
+	<author>Bartosz Przybylski</author>
+	<require>2</require>
+	<description></description>
+	<default_enable/>
+</info>
diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css
new file mode 100644
index 0000000000000000000000000000000000000000..03b179138e655ffc14a10811fc86d533915a52b3
--- /dev/null
+++ b/apps/gallery/css/styles.css
@@ -0,0 +1,23 @@
+div#gallery_list {
+  margin: 90pt 20pt;
+}
+
+div#gallery_album_box {
+  width: 200px;
+  text-align: center;
+  border: 0;
+  float: left;
+  margin: 5pt;
+}
+
+div#gallery_album_box h1 {
+  font-size: 12pt;
+  font-family: Arial;
+}
+
+div#gallery_album_cover {
+  width: 199px;
+  height: 199px;
+  border: solid 1px black;
+}
+
diff --git a/apps/gallery/index.php b/apps/gallery/index.php
new file mode 100644
index 0000000000000000000000000000000000000000..c8d5892e5552f0c20995b806a6f656a9af99acbc
--- /dev/null
+++ b/apps/gallery/index.php
@@ -0,0 +1,33 @@
+<?php
+require_once('../../lib/base.php');
+
+OC_Util::checkLoggedIn();
+OC_App::setActiveNavigationEntry( 'gallery_index' );
+
+
+if (!isset($_GET['view'])) {
+  $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?');
+  $result = $stmt->execute(array(OC_User::getUser()));
+
+  $r = array();
+  while ($row = $result->fetchRow())
+    $r[] = $row;
+
+  $tmpl = new OC_Template( 'gallery', 'index', 'user' );
+  $tmpl->assign('r', $r);
+  $tmpl->printPage();
+} else {
+  $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos, *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name = ? AND *PREFIX*gallery_albums.album_id = *PREFIX*gallery_photos.album_id');
+  
+  $result = $stmt->execute(array(OC_User::getUser(), $_GET['view']));
+
+  $photos = array();
+  while ($p = $result->fetchRow())
+    $photos[] = $p['file_path'];
+  
+  $tmpl = new OC_Template( 'gallery', 'view_album', 'user' );
+  $tmpl->assign('photos', $photos);
+  $tmpl->assign('albumName', $_GET['view']);
+  $tmpl->printPage();
+}
+?>
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js
new file mode 100644
index 0000000000000000000000000000000000000000..776feae32cc50301e1e5a1d065490f8e131bea1e
--- /dev/null
+++ b/apps/gallery/js/album_cover.js
@@ -0,0 +1,41 @@
+var actual_cover;
+$(document).ready(function() {
+  $.getJSON('ajax/getAlbums.php', function(r) {
+    if (r.status == 'success') {
+      for (var i in r.albums) {
+        var a = r.albums[i];
+        Albums.add(a.name, a.numOfItems);
+      }
+      var targetDiv = document.getElementById('gallery_list');
+      if (targetDiv) {
+        Albums.display(targetDiv);
+      } else {
+        alert('Error occured: no such layer `gallery_list`');
+      }
+    } else {
+      alert('Error occured: ' + r.message);
+    }
+  });
+});
+
+function createNewAlbum() {
+  var name = prompt("album name", "");
+  if (name != null && name != "") {
+    $.getJSON("ajax/createAlbum.php", {album_name: name}, function(r) {
+      if (r.status == "success") {
+        var v = '<div class="gallery_album_box"><a href="?view='+r.name+'"><img class="gallery_album_cover"/></a><h1>'+r.name+'</h1></div>';
+        $('div#gallery_list').append(v);
+      }
+    });
+  }
+}
+
+function scanForAlbums() {
+  $.getJSON('ajax/scanForAlbums.php', function(r) {
+    if (r.status == 'success') {
+      window.location.reload(true);
+    } else {
+      alert('Error occured: ' + r.message);
+    }
+  });
+}
diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js
new file mode 100644
index 0000000000000000000000000000000000000000..7ab243ededfdf89c6097982d5db870578f6610da
--- /dev/null
+++ b/apps/gallery/js/albums.js
@@ -0,0 +1,80 @@
+Albums={
+  // album item in this array should look as follow
+  // {name: string,
+  //  numOfCovers: int}
+  //
+  // previews array should be an array of base64 decoded images
+  // to display to user as preview picture when scrolling throught
+  // the album cover
+  albums:new Array(),
+  // add simply adds new album to internal structure
+  // however albums names must be unique so other
+  // album with the same name wont be insered,
+  // and false will be returned
+  // true on success
+  add: function(album_name, num) {
+    for (var a in Albums.albums) {
+      if (a.name == album_name) {
+        return false;
+      }
+    }
+    Albums.albums.push({name: album_name, numOfCovers: num});
+    return true;
+  },
+  // remove element with given name
+  // returns remove element or undefined if no such element was present
+  remove: function(name) {
+    var i = -1, tmp = 0;
+    for (var a in Albums.albums) {
+      if (a.name == name) {
+        i = tmp;
+        break;
+      }
+      tmp++;
+    }
+    if (i != -1) {
+      return Albums.albums.splice(i,1);
+    }
+    return undefined;
+  },
+  // return element which match given name
+  // of undefined if such element do not exist
+  find: function(name) {
+    var i = -1, tmp = 0;
+    for (var k in Albums.albums) {
+      var a = Albums.albums[k];
+      if (a.name == name) {
+        i = tmp;
+        break;
+      }
+      tmp++;
+    }
+    if (i != -1) {
+      return Albums.albums[i];
+    }
+    return undefined;
+  },
+  // displays gallery in linear representation
+  // on given element, and apply default styles for gallery
+  display: function(element) {
+    var displayTemplate = '<div id="gallery_album_box" title="*NAME*"><a href="?view=*NAME*"><div id="gallery_album_cover"></div></a><h1>*NAME*</h1></div></div>';
+    for (var i in Albums.albums) {
+      var a = Albums.albums[i];
+      var local = $(displayTemplate.replace(/\*NAME\*/g, a.name));
+      local.css('background-repeat', 'no-repeat');
+      local.css('background-position', '0 0');
+      local.css('background-image','url("ajax/getCovers.php?album_name='+a.name+'")');
+      local.mousemove(function(e) {
+        var albumMetadata = Albums.find(this.title);
+        if (albumMetadata == undefined) {
+          return;
+        }
+        var x = Math.min(Math.floor((e.clientX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers)), albumMetadata.numOfCovers-1);
+        x *= this.offsetWidth;
+        $(this).css('background-position', -x+'px 0');
+      });
+      $(element).append(local);
+    }
+  }
+
+}
diff --git a/apps/gallery/lib_scanner.php b/apps/gallery/lib_scanner.php
new file mode 100644
index 0000000000000000000000000000000000000000..fe14b68add1345ae50384b888395024629ce531d
--- /dev/null
+++ b/apps/gallery/lib_scanner.php
@@ -0,0 +1,57 @@
+<?php
+
+require_once('base.php'); // base lib
+
+class OC_GALLERY_SCANNER {
+
+  public static function scan($root) {
+    $albums = array();
+    self::scanDir($root, $albums);
+    return $albums;
+  }
+
+  public static function scanDir($path, &$albums) {
+    $current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array());
+    $current_album['name'] = str_replace('/', '.', str_replace(OC::$CONFIG_DATADIRECTORY, '', $current_album['name']));
+    $current_album['name'] = ($current_album['name']==='')?'main':$current_album['name'];
+
+    if ($dh = OC_Filesystem::opendir($path)) {
+      while (($filename = readdir($dh)) !== false) {
+        $filepath = $path.'/'.$filename;
+        if (substr($filename, 0, 1) == '.') continue;
+        if (OC_Filesystem::is_dir($filepath)) {
+          self::scanDir($filepath, $albums);
+        } elseif (self::isPhoto($path.'/'.$filename)) {
+          $current_album['images'][] = $filepath;
+        }
+      } 
+    }
+    $current_album['imagesCount'] = count($current_album['images']);
+    $albums[] = $current_album;
+    $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE "uid_owner" = ? AND "album_name" = ?');
+    $result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
+    if ($result->numRows() == 0 && count($current_album['images'])) {
+      $stmt = OC_DB::prepare('INSERT OR REPLACE INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES (?, ?)');
+      $stmt->execute(array(OC_User::getUser(), $current_album['name']));
+    }
+    $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE "uid_owner" = ? AND "album_name" = ?');
+    $result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
+    $albumId = $result->fetchRow();
+    $albumId = $albumId['album_id'];
+    foreach ($current_album['images'] as $img) {
+      $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE "album_id" = ? AND "file_path" = ?');
+      $result = $stmt->execute(array($albumId, $img));
+      if ($result->numRows() == 0) {
+        $stmt = OC_DB::prepare('INSERT OR REPLACE INTO *PREFIX*gallery_photos ("album_id", "file_path") VALUES (?, ?)');
+        $stmt->execute(array($albumId, $img));
+      }
+    }
+  }
+
+  public static function isPhoto($filename) {
+    if (substr(OC_Filesystem::getMimeType($filename), 0, 6) == "image/")
+      return 1;
+    return 0;
+  }
+}
+?>
diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php
new file mode 100644
index 0000000000000000000000000000000000000000..0e89e448768bfab117352aa774b6b41bf95db968
--- /dev/null
+++ b/apps/gallery/templates/index.php
@@ -0,0 +1,12 @@
+<?php
+OC_Util::addStyle('gallery', 'styles');
+OC_Util::addScript('gallery', 'albums');
+OC_Util::addScript('gallery', 'album_cover');
+?>
+
+<div id="controls">
+  <!--  <input type="button" value="New album" onclick="javascript:createNewAlbum();" />-->
+  <input type="button" value="Rescan" onclick="javascript:scanForAlbums();" /><br/>
+</div>
+<div id="gallery_list">
+</div>
diff --git a/apps/gallery/templates/view_album.php b/apps/gallery/templates/view_album.php
new file mode 100644
index 0000000000000000000000000000000000000000..ea2969e01104c98a0e6e227381edaf9bb6edad6d
--- /dev/null
+++ b/apps/gallery/templates/view_album.php
@@ -0,0 +1,20 @@
+<?php
+OC_Util::addStyle('gallery', 'styles');
+OC_Util::addScript('gallery', 'album_cover');
+OC_Util::addScript( 'files_imageviewer', 'lightbox' );
+OC_Util::addStyle( 'files_imageviewer', 'lightbox' );
+?>
+
+<div id="controls">
+  <a href="?"><input type="button" value="Back" /></a><br/>
+</div>
+<div id="gallery_list">
+<?php
+foreach ($_['photos'] as $a) {
+?>
+<a onclick="javascript:viewImage('/','<?php echo $a; ?>');"><img src="ajax/thumbnail.php?img=<?php echo $a ?>"></a>
+<?php
+  }
+?>
+
+</div>
diff --git a/lib/util.php b/lib/util.php
index f21ec8208b4703734e49a23083f1952bbaf919ae..5d03c56f18e6ed9bbc564f5dcd1749e6ecf098da 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -90,7 +90,7 @@ class OC_Util {
 	 * @return array
 	 */
 	public static function getVersion(){
-		return array(1,91,0);
+		return array(1,92,0);
 	}
 
 	/**
@@ -98,7 +98,7 @@ class OC_Util {
 	 * @return string
 	 */
 	public static function getVersionString(){
-		return '2 beta 2';
+		return '2 beta 3';
 	}
 
 	/**