// Script to remove Java rollovers (such as those on restoration-team.co.uk)
// Version 2
// Copyright 2005, 2006 Adam Sampson <ats@offog.org>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// ==UserScript==
// @name	No Java Rollovers
// @namespace	http://offog.org/code/greasemonkey/
// @description	Replace image rollovers implemented as Java applets
// @include	*
// ==/UserScript==

// Find all the applets, then copy the array so that it doesn't change as we
// replace them.
var all = document.getElementsByTagName("applet");
var res = new Array(all.length);
for (var i = 0; i < all.length; i++) {
	res[i] = all[i];
}

var id = 0;
for (var i = 0; i < res.length; i++) {
	var a = res[i];

	// Find the image URLs from the applet parameters.
	var base = "", hover = "";
	var params = a.getElementsByTagName("param");
	for (var j = 0; j < params.length; j++) {
		var p = params[j];
		var name = p.getAttribute("name");
		var value = p.getAttribute("value");
		if (name == "image") {
			base = value;
		} else if (name == "hoverimage") {
			hover = value;
		}
	}
	if (base == "" || hover == "") {
		// Couldn't find them; not an applet we recognise, then.
		continue;
	}

	// Replace them with a real img and some old-fashioned Javascript
	// rollover code.
	var sid = "atsReplacedRollover" + id;
	id += 1;
	var n = document.createElement("img");
	n.setAttribute("id", sid);
	n.setAttribute("src", base);
	n.setAttribute("onMouseOver", "document.images." + sid + ".src = \"" + hover + "\"");
	n.setAttribute("onMouseOut", "document.images." + sid + ".src = \"" + base + "\"");
	a.parentNode.replaceChild(n, a);
}

