// ==UserScript==
// @name          WorldCat Amazon Linky
// @namespace     http://www.library.southernct.edu/firefox/
// @description	  Inserts a link under the book title to Worldcat "Find at a Library".
// @description   Based on Amazon Linky (http://www.statway.com/firefox) and the OCLC xISBN project (http://www.oclc.org/research/researchworks/xisbn/default.htm)
// @include       http://*.amazon.*
// ==/UserScript==



(

function() {
  mainmatch = window._content.location.href.match(/\/(\d{9}[\d|X])\//);
  if (mainmatch){
  	var isbn = mainmatch[1];
  	var header = document.evaluate("//b[@class='sans']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  	if (header) {
                   

      	
  var worldcat_link = document.createElement('a');
   	  worldcat_link.setAttribute('href', 'http://labs.oclc.org/xisbn/liblook?baseURL=http://www.google.com&opacID=openworldcat&isbn=' + isbn);
   	  worldcat_link.setAttribute('title', 'Find in a Library near you');
          worldcat_link.innerHTML 
	   	= '<img src="http://www.worldcatlibraries.org/wcpa/images/fial_title.gif"'
      	+ ' style="border: 0; margin: 0px 0 0 2px; padding: 0; vertical-align: middle"'
      	+ ' alt="WorldCat icon" width=304 height=33 />'   	  ;  
    	
      

    
header.parentNode.insertBefore(worldcat_link, header.nextSibling);  
    


    }

  }
 
}

)();
