// ==UserScript==
// @name           AllegroTools (Cafe) dla IE i FF
// @namespace      http://www.allegrotoolsie.hopto.org/
// @description    Dodatkowe narzedzia pomocne przy przegladaniu Cafe Allegro // v0.20070114.1
// @include        http*://*allegro.pl/phorum/read.php?*
// ==/UserScript==

/////////////////////////////////////////////////////////////////

function addLink(element, link)
{
  var linkElement = link.cloneNode(true);
  var separatorElement = element.previousSibling.cloneNode(true);
  element.parentNode.insertBefore(linkElement, element);
  element.parentNode.insertBefore(separatorElement, element);
}

function allegrotoolsCafe()
{
  var linksTable = document.links;
  var searchLink = false;
  var viewLink = false;
  
  if (linksTable)
  {
    for(var i = 0; i < linksTable.length; i++)
    {
      if (linksTable[i].href.match("allegro.pl/phorum/search.php") && (linksTable[i].className == "spec-flex"))
      {
        searchLink = linksTable[i];
      }
      else if ((linksTable[i].href.match("v=f") && (linksTable[i].className == "spec-flex")) ||
                (linksTable[i].href.match("v=t") && (linksTable[i].className == "spec-flex")))
      {
        viewLink = linksTable[i];
      }
      if(searchLink && viewLink)
      {
        addLink(searchLink, viewLink);
        break;
      }
    }
  }
}

/////////////////////////////////////////////////////////////////
// Start Allegro Tools Cafe script
/////////////////////////////////////////////////////////////////

allegrotoolsCafe()
