Index: dbstruct.sql
===================================================================
--- dbstruct.sql	(revision 1166)
+++ dbstruct.sql	(working copy)
@@ -119,6 +119,7 @@
 insert into config (key_,value_,default_,type_,desc_,export_) values ("rss.config.ajaxparallelsize",'3','3','num','Sets the number of feeds to update in parallel. Remember to set rss.config.serverpush to false.',NULL);
 insert into config (key_,value_,default_,type_,desc_,export_) values ("rss.config.ajaxbatchsize",'3','3','num','Sets the number of feeds in a batch when using the ajax updater. Remember to set rss.config.serverpush to false.',NULL);
 insert into config (key_,value_,default_,type_,desc_,export_) values ("rss.config.defaultdashboard", '1', '1','boolean','If the first page seen when entering the admin section should be the dashboard',NULL);
+insert into config (key_,value_,default_,type_,desc_,export_) values ("rss.output.nav.unread", 'false', 'false','boolean','If the navigation hints on the feeds page should go to the next feed with unread items.  If false, it simply goes to the next feed.',NULL);
 
 DROP TABLE IF EXISTS `tag`;
 CREATE TABLE `tag` (
Index: schema.php
===================================================================
--- schema.php	(revision 1166)
+++ schema.php	(working copy)
@@ -383,7 +383,8 @@
 		"rss.output.title"			=> array('Gregarius','Gregarius','string','Sets the title of this feedreader.',NULL),
 		"rss.config.ajaxparallelsize"			=> array('3','3','num','Sets the number of feeds to update in parallel. Remember to set rss.config.serverpush to false.',NULL),
 		"rss.config.ajaxbatchsize"			=> array('3','3','num','Sets the number of feeds in a batch when using the ajax updater. Remember to set rss.config.serverpush to false.',NULL),
-		"rss.config.defaultdashboard"	  		=> array('true','true','boolean','If the first page seen when entering the admin section should be the dashboard',NULL)
+		"rss.config.defaultdashboard"	  		=> array('true','true','boolean','If the first page seen when entering the admin section should be the dashboard',NULL),
+		"rss.output.nav.unread"		=>		array('false','false','boolean','If the navigation hints on the feeds page should go to the next feed with unread items.  If false, it simply goes to the next feed.',NULL)
 	);
 	
 	
Index: feed.php
===================================================================
--- feed.php	(revision 1166)
+++ feed.php	(working copy)
@@ -840,7 +840,11 @@
             } elseif (strlen($lbl) > 40) {
                 $lbl = substr($lbl,0,37) . "...";
             }
-            $readMoreNav .= "<a href=\"".$prev['url']."\" class=\"fl\">".LBL_NAV_PREV_PREFIX ."$lbl</a>\n";
+            $readMoreNav .= "<a href=\"".$prev['url']."\" class=\"fl\">".LBL_NAV_PREV_PREFIX . $lbl;
+            if( array_key_exists( 'unread', $prev ) && $prev['unread'] ) {
+                $readMoreNav .= "&nbsp;(" . $prev['unread'] . " " . LBL_UNREAD . ")";
+            }
+            $readMoreNav .= "</a>\n";
         }
 
         if($succ != null) {
@@ -850,7 +854,11 @@
             } elseif (strlen($lbl) > 40) {
                 $lbl = substr($lbl,0,37) . "...";
             }
-            $readMoreNav .= "<a href=\"".$succ['url']."\" class=\"fr\">$lbl".LBL_NAV_SUCC_POSTFIX."</a>\n";
+            $readMoreNav .= "<a href=\"".$succ['url']."\" class=\"fr\">$lbl";
+            if( array_key_exists( 'unread', $succ ) && $succ['unread'] ) {
+                $readMoreNav .= "&nbsp;(" . $succ['unread'] . " " . LBL_UNREAD . ")";
+            }
+            $readMoreNav .= LBL_NAV_SUCC_POSTFIX."</a>\n";
         }
 
         if ($readMoreNav != "") {
@@ -1144,55 +1152,100 @@
         case 'feed':
 
             $sql = "select "
-                   ." c.id, c.title "
-                   ." from "
-                   .getTable("channels") ." c, "
-                   . getTable("folders") ." d "
-                   ." where d.id = c.parent ";
+                   ." c.id, c.title";
+            if (getConfig('rss.output.nav.unread') ) {
+                $sql .= ", count(i.id) as unreadCount ";
+            } else {
+                $sql .= ", 0";
+            }
+            $sql .= " from " 
+                   .getTable("folders") ." d, "
+                   .getTable("channels") ." c ";
+            if (getConfig('rss.output.nav.unread') ) {
+                $sql .= " left outer join " . getTable('item') . " i on i.cid=c.id ";
+            }
+            $sqlwhere = " where d.id = c.parent";
 
-
             if (hidePrivate()) {
-                $sql .=" and not(c.mode & " . RSS_MODE_PRIVATE_STATE .") ";
+                $sqlwhere .=" and not(c.mode & " . RSS_MODE_PRIVATE_STATE .") ";
+                if (getConfig('rss.output.nav.unread') ) {
+                    $sql .= " and not (i.unread & " . RSS_MODE_PRIVATE_STATE . ") ";
+                }
             }
-            $sql .= " and not(c.mode & " .  RSS_MODE_DELETED_STATE .") ";
+            $sqlwhere .= " and not(c.mode & " .  RSS_MODE_DELETED_STATE .") ";
+            if (getConfig('rss.output.nav.unread') ) {
+                $sql .= " and (i.unread & ".RSS_MODE_UNREAD_STATE . ") and not (i.unread & " .RSS_MODE_DELETED_STATE . ") ";
+            }
+            if (getConfig('rss.output.nav.unread') ) {
+                $sqlwhere .= " group by i.cid";
+            }
 
             if (getConfig('rss.config.absoluteordering')) {
-                $sql .=" order by d.position asc, c.position asc";
+                $sqlwhere .=" order by d.position asc, c.position asc";
             } else {
-                $sql .=" order by d.name asc, c.title asc";
+                $sqlwhere .=" order by d.name asc, c.title asc";
             }
 
-
-            $res  = rss_query($sql);
+            $res  = rss_query($sql.$sqlwhere);
             $pcid = $ptitile = null;
-            $cidname=array();
+            $ciddata=array();
             $cids=array();
-            while (list ($cid_,$title_)=rss_fetch_row($res)) {
+            while (list ($cid_,$title_,$unread_)=rss_fetch_row($res)) {
                 $cids[]=$cid_;
-                $cidname[]=array($cid_,$title_);
+                $ciddata[]=array($cid_,$title_,$unread_);
             }
             $key = array_search($cid,$cids);
             if ($key !== NULL && $key !== FALSE) {
-                //echo "$key " .count($cidname);
-                if ($key+1 < count($cidname)) {
-                    list($cid_,$title_) = $cidname[$key+1];
+                //echo "$key " .count($ciddata);
+                $succkey = $key + 1;
+                $prevkey = $key - 1;
+                while ($succkey < count($ciddata)) {
+                    list($cid_,$title_,$unread_) = $ciddata[$succkey];
+                    if (getConfig('rss.output.nav.unread') ) {
+                        if( !$unread_ ) {
+                            if( $succkey + 1 < count($ciddata) ) {
+                                $succkey++;
+                                continue;
+                            }
+                            else {
+                                $succkey = $key + 1; //no more feeds, we'll just use the regular "next" one
+                            }
+                        }
+                    }
+
                     $succ = array(
                                 'url' => getPath().
                                        ( getConfig('rss.output.usemodrewrite') ?
                                          preg_replace("/[^A-Za-z0-9\.]/","_",$title_) ."/"
                                          :"feed.php?channel=$cid_") ,
-                                'lbl' => htmlentities( $title_,ENT_COMPAT,"UTF-8" )
+                                'lbl' => htmlentities( $title_,ENT_COMPAT,"UTF-8" ) ,
+                                'unread' => $unread_
                             );
+                    break;
                 }
-                if ($key > 0) {
-                    list($cid_,$title_) = $cidname[$key-1];
+                while ($prevkey >= 0) {
+                    list($cid_,$title_,$unread_) = $ciddata[$prevkey];
+                    if (getConfig('rss.output.nav.unread') ) {
+                        if( !$unread_ ) {
+                            if( $prevkey > 0 ) {
+                                $prevkey--;
+                                continue;
+                            }
+                            else {
+                                $prevkey = $key - 1; //no more feeds, we'll just use the regular "previous" one
+                            }
+                        }
+                    }
+
                     $prev = array(
                                 'url' => getPath().
                                        ( getConfig('rss.output.usemodrewrite') ?
                                          preg_replace("/[^A-Za-z0-9\.]/","_",$title_) ."/"
                                          :"feed.php?channel=$cid_") ,
-                                'lbl' => htmlentities( $title_,ENT_COMPAT,"UTF-8" )
+                                'lbl' => htmlentities( $title_,ENT_COMPAT,"UTF-8" ) ,
+                                'unread' => $unread_
                             );
+                    break;
                 }
 
             }
