<div id="mid_inner">
<style>
div.pagination {
	padding: 3px;
	margin: 3px;
	font-size:11px;
}

div.pagination a {
	padding: 2px 5px 2px 5px;
	margin: 2px;
	/*border: 1px solid #AAAADD;*/
	
	text-decoration: none; /* no underline */
	/*color: #000099;*/
}
div.pagination a:hover, div.pagination a:active {
	/*border: 1px solid #000099;*/

	color: #000;
}
div.pagination span.current {
	padding: 2px 5px 2px 5px;
	margin: 2px;
		/*border: 1px solid #000099;*/
		
		font-weight: bold;
		background-color: #555;
		color: #FFF;
	}
	div.pagination span.disabled {
		padding: 2px 5px 2px 5px;
		margin: 2px;
		/*border: 1px solid #EEE;*/
	
		color: #666;
	}
</style>

<?php 
// How many adjacent pages should be shown on each side?
    $adjacents = 3;
    $pageno=$pageno;
    /* 
       First get total number of rows in data table. 
       If you have a WHERE clause in your query, make sure you mirror it here.
    */   
    $total_pages =$num_rows;
    
    /* Setup vars for query. */
    $limit = $pagesize;                                 //how many items to show per page
    if($pageno) 
        $start = ($pageno - 1) * $limit;          //first item to display on this page
    else
        $start = 0;                             //if no page var is given, set start to 0
    
    /* Get data. */
   // $query = "SELECT id, title, description FROM filedetails LIMIT $start, $limit";
   // $portfolio = mysql_query($query);
    
    /* Setup page vars for display. */
    if ($pageno == 0) $pageno = 1;                  //if no page var is given, default to 1.
    $prev = $pageno - 1;                          //previous page is page - 1
    $next = $pageno + 1;                          //next page is page + 1
    $lastpage = ceil($total_pages/$limit);      //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1;                      //last page minus 1
    
    /* 
        Now we apply our rules and draw the pagination object. 
        We're actually saving the code to a variable in case we want to draw it more than once.
    */
    $pagination = "";
    if($lastpage > 1)
    {   
        $pagination .= "<div class=\"pagination\">";
        //previous button
        if ($pageno > 1) 
            $pagination.= "<a href=\"$pagename&pageno=$prev&pagesize=$pagesize\">&lt;&lt; previous</a>";
        else
            $pagination.= "<span class=\"disabled\">&lt;&lt; previous</span>";    
        
        //pages 
        if ($lastpage < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $pageno)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$pagename&pageno=$counter&pagesize=$pagesize\">$counter</a>";                   
            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))    //enough pages to hide some
        {
            //close to beginning; only hide later pages
            if($pageno < 1 + ($adjacents * 2))        
            {
                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                {
                    if ($counter == $pageno)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$pagename&pageno=$counter&pagesize=$pagesize\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$pagename&pageno=$lpm1&pagesize=$pagesize\">$lpm1</a>";
                $pagination.= "<a href=\"$pagename&pageno=$lastpage&pagesize=$pagesize\">$lastpage</a>";     
            }
            //in middle; hide some front and some back
            elseif($lastpage - ($adjacents * 2) > $pageno && $pageno > ($adjacents * 2))
            {
                $pagination.= "<a href=\"$pagename&pageno=1&pagesize=$pagesize\">1</a>";
                $pagination.= "<a href=\"$pagename&pageno=2&pagesize=$pagesize\">2</a>";
                $pagination.= "...";
                for ($counter = $pageno - $adjacents; $counter <= $pageno + $adjacents; $counter++)
                {
                    if ($counter == $pageno)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$pagename&pageno=$counter&pagesize=$pagesize\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$pagename&pageno=$lpm1&pagesize=$pagesize\">$lpm1</a>";
                $pagination.= "<a href=\"$pagename&pageno=$lastpage&pagesize=$pagesize\">$lastpage</a>";     
            }
            //close to end; only hide early pages
            else
            {
                $pagination.= "<a href=\"$pagename&pageno=1&pagesize=$pagesize\">1</a>";
                $pagination.= "<a href=\"$pagename&pageno=2&pagesize=$pagesize\">2</a>";
                $pagination.= "...";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                {
                    if ($counter == $pageno)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$pagename&pageno=$counter&pagesize=$pagesize\">$counter</a>";                   
                }
            }
        }
        
        //next button
        if ($pageno < $counter - 1) 
            $pagination.= "<a href=\"$pagename&pageno=$next&pagesize=$pagesize\">next &gt;&gt;</a>";
        else
            $pagination.= "<span class=\"disabled\">next &gt;&gt;</span>";
        $pagination.= "</div>\n";       
    }

?>
<span style="float:right; position:static; margin:5px 10px 0 0 ">
	<form id="formnumber" name="formnumber" method="post" action="<?=$pagename?>&pageno=<?=$pageno?>&pagesize=<?=$pagesize?>" class="dropdown">
	<select name="pagesize" id="pagesize" onChange="javascript:formnumber.submit()" class="form-control">
	   <option value="0">Select #</option>
	   <option value="5">5 Entries</option>
	  <option value="10">10 Entries</option>
	  <option value="20">20 Entries</option>
	  <option value="50">50 Entries</option>
	  <option value="100">100 Entries</option>
	  </select>
	</form>
</span>
<?=$pagination?>
