/**
 * Previous-next script to handle 'switching' one block of content into the
 * next. This requires absolute positioning.
**/
$(document).ready(
   function() {
      var view_button         = 'all';
      var num_children        = $('#previous-next-items').children('.previous-next-item').length;
      var current_child_num   = 1;
      var new_child_num       = 2;

      // Must have at least 2 items in order to use previous-next functionality.
      if (num_children > 1) {

         // Hide previous button (starts on the first item).
         $('#previous-next-previous-button:parent').attr('style', 'display:none;');

         // Hide all items except for the first one.
         for (i = 2; i <= num_children; i++) {
            $('#previous-next-item-' + i).attr('style', 'display:none;');
         }

         // Next item.
         $('#previous-next-next-button').click(
            function() {
               $(this).attr('href', '#');

               new_child_num = current_child_num + 1;

               // Hide next button if on last item.
               if (new_child_num == num_children) {
                  $('#previous-next-next-button:parent').attr('style', 'display:none;');
               }

               // Show previous button if not on first item.
               if (new_child_num > 1) {
                  $('#previous-next-previous-button:parent').attr('style', 'display:inline;');
               }

               $('#previous-next-item-' + current_child_num).attr('style', 'display:none;');
               $('#previous-next-item-' + new_child_num).attr('style', 'display:block;');

               current_child_num = new_child_num;
            }
         );

         // Previous item.
         $('#previous-next-previous-button').click(
            function() {
               $(this).attr('href', '#');

               new_child_num = current_child_num - 1;

               // Hide prevous button if on first item.
               if (new_child_num == 1) {
                  $('#previous-next-previous-button:parent').attr('style', 'display:none;');
               }

               // Show next button if not on last item.
               if (new_child_num < num_children) {
                  $('#previous-next-next-button:parent').attr('style', 'display:inline;');
               }

               $('#previous-next-item-' + current_child_num).attr('style', 'display:none;');
               $('#previous-next-item-' + new_child_num).attr('style', 'display:block;');

               current_child_num = new_child_num;
            }
         );

         // View all/view one.
         $('#previous-next-view-all-button').click(
            function() {
               $(this).attr('href', '#');

               if (view_button == 'all') {
                  $('#previous-next-view-all-button').html('View One');
                  $('.previous-next-item').attr('style', 'display:block;');
                  $('#previous-next-previous-button:parent').attr('style', 'display:none;');
                  $('#previous-next-next-button:parent').attr('style', 'display:none;');
                  view_button = 'one';
               } else {
                  $('#previous-next-view-all-button').html('View All');
                  $('.previous-next-item').attr('style', 'display:none;');
                  $('#previous-next-item-1').attr('style', 'display:block;');
                  $('#previous-next-previous-button:parent').attr('style', 'display:inline;');
                  $('#previous-next-next-button:parent').attr('style', 'display:inline;');
                  view_button = 'all';
               }
            }
         );
      }
   }
);

/**
 * Previous-next script to handle 'cross-fading' one block of content into the
 * next. This requires absolute positioning.
**/
/*
$(document).ready(
   function() {
      var view_button = 'all';

      if ($.browser.msie) {
         $('#previous-next-items').cycle({
            fx:      'fade',
            speed:   350,
            timeout: 0,
            prev:    '#previous-next-previous-button',
            next:    '#previous-next-next-button'
         });
      }
      else {
         $('#previous-next-items').cycle({
            fx:      'fade',
            speed:   350,
            timeout: 0,
            prev:    '#previous-next-previous-button',
            next:    '#previous-next-next-button'
         });
      }

      $('#previous-next-view-all-button').click(
         function() {
            if (view_button == 'all') {
               view_button = 'one';
               $('#previous-next-view-all-button').html('View One');
               $('.previous-next-item').attr('style', 'display:block; opacity:1.0;');
               $('#previous-next-previous-button:parent').attr('style', 'display:none; opacity:0;');
               $('#previous-next-next-button:parent').attr('style', 'display:none; opacity:0;');
            } else {
               view_button = 'all';
               $('#previous-next-view-all-button').html('View All');
               $('.previous-next-item').attr('style', 'position:absolute; display:none; opacity:0;');
               $('#previous-next-item-1').attr('style', 'position:absolute; display:block; opacity:1.0;');
               $('#previous-next-previous-button:parent').attr('style', 'display:inline; opacity:1.0;');
               $('#previous-next-next-button:parent').attr('style', 'display:inline; opacity:1.0;');
            }
         }
      );

      $('#previous-next-view-all-button').attr('href', 'javascript:void(0); return false;');
      $('#previous-next-previous-button').attr('href', 'javascript:void(0); return false;');
      $('#previous-next-next-button').attr('href', 'javascript:void(0); return false;');
   }
);
*/
