// ==UserScript==
// @name Show what's related
// @author TarquinWJ 
// @namespace http://www.howtocreate.co.uk/ 
// @version 1.0
// @description  Shows a 'what's related' panel for the current page.
// @ujs:category general: enhancements
// @ujs:published 2005-09-30 01:30
// @ujs:modified 2005-11-11 09:25
// @ujs:documentation http://userjs.org/scripts/general/enhancements/whats-related 
// @ujs:download http://userjs.org/scripts/download/general/enhancements/whats-related.js
// ==/UserScript==


/* 
 * Please see
 * http://www.howtocreate.co.uk/operaStuff/userJavaScript.html#terms
 * for License and Terms of Use
 */

document.addEventListener('load',function () {

	//configure options here

	//show related links by default (true = yes [not recommended], false = no)
	var showByDefault = false;

	//the page that provides the 'what's related' service (the current page address will be appended)
	var serviceURL = 'http:\/\/www.google.com\/search?q=related:';

	if( ( window != window.top ) || ( location.protocol != 'http:' ) || ( document.getElementsByTagName('*').length == 5 ) ) { return; }
	var bar = document.createElement('oobadayawhatsrel');
	bar.appendChild(document.createTextNode('>>'));
	bar.setAttribute('style','box-sizing:border-box;border:solid #000;border-width:0px 1px 1px 0px;position:fixed;top:0px;left:0px;width:20px;height:1.5em;cursor:pointer;background-color:yellow;color:#000;');
	bar.onclick = function () {
		if(this.hasFrame) {
			document.body.removeChild(this.hasFrame);
			this.hasFrame = null;
			this.firstChild.nodeValue = '>>';
			this.style.left = '0px';
			this.style.height = '1.5em';
			document.documentElement.style.marginLeft = this.oldW;
		} else {
			this.hasFrame = document.createElement('iframe');
			this.hasFrame.setAttribute('style','position:fixed;top:0px;left:20px;width:200px;height:100%;');
			this.hasFrame.src = serviceURL+escape(location.href);
			document.body.appendChild(this.hasFrame);
			this.style.height = '100%';
			this.firstChild.nodeValue = '<<';
			this.style.height = '100%';
			this.oldW = document.documentElement.style.marginLeft ? document.documentElement.style.marginLeft : '';
			document.documentElement.style.marginLeft = '220px';
		}
	};
	document.body.appendChild(bar);
	if( showByDefault ) { bar.onclick(); }
},false);
