diff --git a/inc/media.php b/inc/media.php
index cbb17ac212744edb8440edbbb1d721e51662939d..e18144ebacae42698a4c716457ee1d55cd7e586d 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -725,21 +725,32 @@ function media_tab_files_options($ns, $sort){
 }
 
 /**
- * Prints tab that displays a list of all files
+ * Returns type of sorting for the list of files in media manager
  *
  * @author Kate Arzamastseva <pshns@ukr.net>
+ * @return string - sort type
  */
-function media_tab_files($ns,$auth=null,$jump='') {
-    global $lang;
-    if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
-
+function _media_get_sort_type() {
     $sort = $_REQUEST['sort'];
-    if (!$sort && @strpos($_COOKIE['DOKU_PREFS'], 'sort')) {
+    if (!$sort && (strpos($_COOKIE['DOKU_PREFS'], 'sort') >= 0)) {
         $parts = explode('#', $_COOKIE['DOKU_PREFS']);
             for ($i = 0; $i < count($parts); $i+=2){
                 if ($parts[$i] == 'sort') $sort = $parts[$i+1];
             }
     }
+    return $sort;
+}
+
+/**
+ * Prints tab that displays a list of all files
+ *
+ * @author Kate Arzamastseva <pshns@ukr.net>
+ */
+function media_tab_files($ns,$auth=null,$jump='') {
+    global $lang;
+    if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
+
+    $sort = _media_get_sort_type();
     media_tab_files_options($ns, $sort);
 
     echo '<div class="scroll-container" >';
@@ -782,13 +793,12 @@ function media_tab_search($ns,$auth=null) {
     $query = $_REQUEST['q'];
     if (!$query) $query = '';
 
-    echo '<div class="background-container">';
-    echo sprintf($lang['media_search'], $ns ? $ns : '['.$lang['mediaroot'].']');
-    echo'</div>';
+    $sort = _media_get_sort_type();
+    media_tab_files_options($ns, $sort);
 
     echo '<div class="scroll-container">';
     media_searchform($ns, $query, true);
-    if ($do == 'searchlist') media_searchlist($query,$ns,$auth,true);
+    if ($do == 'searchlist') media_searchlist($query,$ns,$auth,true,$sort);
     echo '</div>';
 }
 
@@ -1300,7 +1310,7 @@ function media_restore($image, $rev, $auth){
  * @author Kate Arzamastseva <pshns@ukr.net>
  * @triggers MEDIA_SEARCH
  */
-function media_searchlist($query,$ns,$auth=null,$fullscreen=false){
+function media_searchlist($query,$ns,$auth=null,$fullscreen=false,$sort=''){
     global $conf;
     global $lang;
 
@@ -1322,6 +1332,14 @@ function media_searchlist($query,$ns,$auth=null,$fullscreen=false){
                     array('showmsg'=>false,'pattern'=>$pattern),
                     $dir);
         }
+        if ($sort == 'date') {
+            $data = array();
+            foreach ($evdata['data'] as $k => $v) {
+                $data[$k]  = $v['mtime'];
+            }
+            array_multisort($data, SORT_DESC, SORT_NUMERIC, $evdata['data']);
+        }
+
         $evt->advise_after();
         unset($evt);
     }
@@ -1685,7 +1703,7 @@ function media_searchform($ns,$query='',$fullscreen=false){
     if (!$fullscreen) $form->addHidden('do', 'searchlist');
     else $form->addHidden('mediado', 'searchlist');
     $form->addElement(form_makeOpenTag('p'));
-    $form->addElement(form_makeTextField('q', $query,$lang['searchmedia'],'','',array('title'=>sprintf($lang['searchmedia_in'],hsc($ns).':*'))));
+    $form->addElement(form_makeTextField('q', $query,$lang['searchmedia'],'mediamanager__sort_textfield','',array('title'=>sprintf($lang['searchmedia_in'],hsc($ns).':*'))));
     $form->addElement(form_makeButton('submit', '', $lang['btn_search']));
     $form->addElement(form_makeCloseTag('p'));
     html_form('searchmedia', $form);
diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js
index 3f3375fa74930c2a36a3350333cc323e2270904a..4dd77beeaa5ee34bf3a616b4e69b27f9d60698aa 100644
--- a/lib/scripts/cookie.js
+++ b/lib/scripts/cookie.js
@@ -24,8 +24,8 @@ DokuCookie = {
         this.data[key] = val;
 
         //save the whole data array
-        jQuery.each(this.data, function (val, key) {
-            if (this.data.hasOwnProperty(key)) {
+        jQuery.each(this.data, function (key, val) {
+            if (DokuCookie.data.hasOwnProperty(key)) {
                 text += '#'+encodeURIComponent(key)+'#'+encodeURIComponent(val);
         }
         });
diff --git a/lib/scripts/media.js b/lib/scripts/media.js
index 7103727c571d368327de082ba894510085b0e59b..e48c9c1b012786d22e808e9366b524c9769f1d12 100644
--- a/lib/scripts/media.js
+++ b/lib/scripts/media.js
@@ -299,6 +299,8 @@ var dw_mediamanager = {
 
             if ($link.parents('form')[0].id == 'mediamanager__form_sort') {
                 DokuCookie.setValue('sort', $link[0].value);
+                params += '&q=' + jQuery('#mediamanager__sort_textfield').val();
+                params += '&mediado=searchlist';
             }
         }