// Add extra paging options to top of works list in mybubble
// Version 0.1
// 2008-06-05
// Copyright (c) 2008, Dave Pearson <http://www.davep.org/>
// Released under the GPL
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.  To install it, you need
// Greasemonkey: http://www.greasespot.net/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "RedBubble Extra MyBubble Paging", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          RedBubble Extra MyBubble Paging
// @namespace     http://www.davep.org/
// @description   Adds paging options to the top of a works list.
// @include       http://www.redbubble.com/mybubble/art*
// @include       http://www.redbubble.com/mybubble/clothing*
// @include       http://www.redbubble.com/mybubble/writing*
// @include       http://www.redbubble.com/mybubble/calendars*
// @include       http://www.redbubble.com/mybubble/journal*
// ==/UserScript==

// Helper function to find an element by its tag and classname.
function getElementByTagNameAndClass( tag, classname )
{
   var hit  = null;
   var tags = document.getElementsByTagName( tag );

   for ( i = 0; i < tags.length; i++ )
   {
      if ( tags[ i ].className == classname )
      {
         hit = tags[ i ];
         break;
      }
   }

   return hit;
}

// Look for the pager.
var pager = getElementByTagNameAndClass( 'div', 'paging' );

// Look for the table of works.
var works = getElementByTagNameAndClass( 'table', 'works_list' );

// Did we get them?
if ( pager && works ) {
   // We got them. Clone the pager.
   newPager = pager.cloneNode( true );
   // Insert it before the works table.
   works.parentNode.insertBefore( newPager, works );
   // Ensure the table clears the pager.
   works.style.clear = "both";
}
