How to add caption to a slider

How to add caption to a slider

Hey Everyone! i have created a slider in which i am getting the images from database. It is a very basic slider only images are showing, i want to add caption and navigation arrows to it. 
This is my code, i have hard coded one image while the others comes from database, please tell me how to put caption and navigation arrows to it..
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>JQuery Photo Slider with Semi Transparent Caption</title>

  5. <script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
  6. <script type="text/javascript">

  7. $(document).ready(function() {
  8. //Execute the slideShow
  9. slideShow();

  10. });

  11. function slideShow() {

  12. //Set the opacity of all images to 0
  13. $('#gallery a').css({opacity: 0.0});
  14. //Get the first image and display it (set it to full opacity)
  15. $('#gallery a:first').css({opacity: 1.0});
  16. //Set the caption background to semi-transparent
  17. $('#gallery .caption').css({opacity: 0.7});

  18. //Resize the width of the caption according to the image width
  19. $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
  20. //Get the caption of the first image from REL attribute and display it
  21. $('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
  22. .animate({opacity: 0.7}, 400);
  23. //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
  24. setInterval('gallery()',6000);
  25. }

  26. function gallery() {
  27. //if no IMGs have the show class, grab the first image
  28. var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

  29. //Get next image, if it reached the end of the slideshow, rotate it back to the first image
  30. var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));
  31. //Get next image caption
  32. var caption = next.find('img').attr('rel');
  33. //Set the fade in effect for the next image, show class has higher z-index
  34. next.css({opacity: 0.0})
  35. .addClass('show')
  36. .animate({opacity: 1.0}, 1000);

  37. //Hide the current image
  38. current.animate({opacity: 0.0}, 1000)
  39. .removeClass('show');
  40. //Set the opacity to 0 and height to 1px
  41. $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
  42. //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
  43. $('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
  44. //Display the content
  45. $('#gallery .content').html(caption);
  46. }

  47. </script>

  48. <script> // Then own code
  49. $(function() { // Shorthand for $(document).ready(function() {
  50.     $.getJSON('getphp.php', function(json) {
  51.         var images = '';
  52.         $.each(json.userdata, function(i, image) {
  53.            images = images + '<a href="#"><img src="images/' + image.a + '" width="380" height="250" ></a>';
  54.         });
  55.         $('#gallery').html(images);
  56.     });
  57. });
  58. </script>

  59. <style type="text/css">
  60. body{
  61. font-family:arial
  62. }

  63. .clear {
  64. clear:both
  65. }

  66. #gallery {
  67. position:relative;
  68. height:360px
  69. }
  70. #gallery a {
  71. float:left;
  72. position:absolute;
  73. }
  74. #gallery a img {
  75. border:none;
  76. }
  77. #gallery a.show {
  78. z-index:500
  79. }

  80. #gallery .caption {
  81. z-index:600; 
  82. background-color:#000; 
  83. color:#ffffff; 
  84. height:100px; 
  85. width:100%; 
  86. position:absolute;
  87. bottom:0;
  88. }

  89. #gallery .caption .content {
  90. margin:5px
  91. }
  92. #gallery .caption .content h3 {
  93. margin:0;
  94. padding:0;
  95. color:#1DCCEF;
  96. }

  97. </style>
  98. </head>
  99. <body>
  100. <h1>&nbsp;</h1>
  101. <div id="gallery">

  102. <a href="#" class="show">
  103.   <img src="images/flowing-rock.jpg" alt="Flowing Rock" width="580" height="360" title=""  rel="<h3>Flowing Rock</h3>Lorem ipsum dolor sit     amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "/>
  104. </a>
  105.      
  106.   
  107. <div class="caption"><div class="content"></div></div>
  108.     
  109.     
  110. </div>
  111. <div class="clear"></div>

  112. <br/><br/>
  113. </body>
  114. </html>