XML Pagination Problem

XML Pagination Problem

Hi guys, I have been slaving for hours over this snippet of code I have developed to read from an XML file and then paginate the results in an unordered list. However, the next and previous link buttons do not work correctly and my code only work ins Safari4+ on the Mac, but there is a JS error when opened in IE7+, maybe thats the reason for it not displaying properly in those browsers.

Anyway, I need to be able to fadeIn 10 magazine issues, then fade them out when the user clicks next or previous and fadeIn another 10 fresh copies.

Here is my code:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <meta name="robots" content="noindex, nofollow" />
  6. <title>Brave Creative - Online Archive</title>
  7. <link rel="stylesheet" href="css/global.css" media="screen" />
  8. <script type="text/javascript" charset="UTF-8" src="js/jquery.js"></script>
  9. <script type="text/javascript">

  10. $(document).ready(function() {

  11.  $.ajax({
  12.     type: "GET",
  13.     url: "issues.xml",
  14.     dataType: "xml",
  15.     success: function(xml) {
  16. var shelf = $('#shelf-items');
  17.                 var startIndex = 0; 
  18.                 var howMany = 10; 
  19.                 var $issues = $(xml).find('issue'); 
  20.                 var totalIssues = $issues.length;
  21. var numPages = Math.ceil(totalIssues / howMany);

  22.                 var displayIssues = function() {
  23.                       var $issuesPaginated = $issues.slice( startIndex , (totalIssues - startIndex) + howMany );
  24.                       shelf.html('');
  25.                       $issuesPaginated.each(function(){
  26.                           var id = $(this).attr('id');
  27.                           var date = $(this).find('date').text();
  28.                           var cover = $(this).find('cover').text();
  29.                           var issue = $(this).find('issuenumber').text();
  30.                           var url = $(this).find('url').text();
  31.                           $('<li id="'+id+'"></li>').html('<a href="'+url+'"><img src="images/covers/'+cover+'" alt="" /></a><br />'+date+' - #'+issue+'').fadeIn(900).appendTo(shelf);
  32.                       });
  33.                 }

  34.                 $('#prevIssueButton').click(function() {
  35.                     if( startIndex < howMany) {
  36.                         startIndex -= howMany;
  37.                         displayIssues().fadeIn(900);
  38.                     }else {
  39. startIndex = 0;
  40.                         displayIssues();
  41. $('span.error').html('No Issues to Display - You are now on Page 1').fadeIn(300).fadeOut(3000);
  42.                     }
  43.                 });
  44.                 $('#nextIssueButton').click(function() {
  45.   if( startIndex + howMany <= totalIssues) {
  46.                         startIndex += howMany;
  47.                         displayIssues().fadeIn(900);
  48.                     }else {
  49. $('span.error').html('No Issues to Display - You are now on Page 1').fadeIn(300).fadeOut(3000);
  50.                        startIndex = 0;
  51.                         displayIssues();
  52.                     }
  53.                 });
  54.                 displayIssues().fadeIn(900);
  55. $('span.issuecount').html(+totalIssues+'&nbsp;Issues - '+numPages+'&nbsp;Pages');
  56.             }
  57.    }); // end ajax call

  58. }); // end document-ready

  59. </script>
  60. </head>
  61. <body>

  62. <div id="bc-publish"><span></span></div>

  63. <br />

  64. <div id="wrapper">

  65. <header>
  66. <h1>Online Archive: <span>FSM</span></h1>
  67. </header>
  68.     
  69.     <section id="buttons">
  70.     
  71.      <a href="#" id="prevIssueButton" title="Toggle Previous Entries">Previous</a>
  72.         <a href="#" id="nextIssueButton" title="Toggle Next Entries">Next</a>
  73.         
  74.         <span class="error"><a></a></span>
  75.         
  76.         <div class="clear"></div>
  77.     
  78.     </section> <!-- /buttons -->
  79.     
  80.     <section id="shelf">
  81.     
  82.      <ul id="shelf-items"></ul>
  83.         
  84.         <div class="clear"></div>
  85.     
  86.     </section> <!-- /shelf -->
  87.     <br />
  88.     <span class="issuecount"></span>
  89.     
  90.     <br /><br />
  91.     
  92.     <span class="logo"><a href="http://www.bravecreative.co.uk" title="Brave Creative"><img src="images/brave-creative-logo.jpg" alt="Brave Creative" /></a></span>
  93.     <span class="address">
  94.     
  95.      <span>t.</span> 01733 392978 <span>m.</span> 07719442825<br />
  96. <span>e.</span> tony@bravecreative.co.uk<br />
  97.         4 Milnyard Square, Orton Southgate, Peterborough PE2 6CX
  98.     
  99.     </span>
  100.     
  101.     <div class="clear"></div>

  102. </div> <!-- /wrapper -->

  103. </body>
  104. </html>
This has really baffled myself and I thought Id come see the experts on the case to see if they could shed any light on the matter.

Any help would be DEEPLY appreciated.

Thanks

Nathan