var imgs = [
	"status.png",
	"menu.png", "menu-thumb.png",
	"prefs-general.png", "prefs-general-thumb.png",
	"prefs-ignored.png", "prefs-ignored-thumb.png",
	"prefs-mudim.png", "prefs-mudim-thumb.png",
	"tester.png", "tester-thumb.png"
];
var noThumb = {"status-thumb.png": "status.png"};
var macPath = "screenshots/mac/";
var xpPath = "screenshots/winxp/";

function swapXpImages() {
	if (window.navigator.platform != "Win32") return;
	
	var box = document.getElementById("screenshot-box");
	if (!box || !document.getElementsByTagName) return;
	var links = box.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++) {
		var href = links[i].href;
		var off = href.indexOf(macPath);
		if (off < 0) continue;
		var name = href.substr(off + macPath.length);
		if (imgs.indexOf(name) < 0) {
			name = noThumb[name];
			if (!name) continue;
		}
		links[i].href = href.substr(0, off) + xpPath + name;
		
		var img = links[i].getElementsByTagName("img")[0];
		if (!img) continue;
		href = img.src;
		off = href.indexOf(macPath);
		if (off < 0) continue;
		name = href.substr(off + macPath.length);
		if (imgs.indexOf(name) < 0) {
			name = noThumb[name];
			if (!name) continue;
		}
		img.src = href.substr(0, off) + xpPath + name;
		img.removeAttribute("width");
		img.removeAttribute("height");
	}
}

var instructionBoxId = "install-steps";
var boxTimeout = null;

var boxText = {};

function activateInstructions() {
	var box = document.getElementById(instructionBoxId);
	var boxDuration = 1000 * 60 * 5;	// ms
	box.className = "";
	
	clearTimeout(boxTimeout);
	boxTimeout = setTimeout(function () {
		box.className = "inactive";
	}, boxDuration);
}

function displayInstructions() {
	var box = document.getElementById(instructionBoxId);
	if (box) {
		activateInstructions();
		return;
	}
	
	box = document.createElement("div");
	box.id = instructionBoxId;
	box.innerHTML = "<h3>" + boxText.title + "<\/h3>\n";
	box.innerHTML += "<p>" + boxText.body + "<\/p>";
	document.body.appendChild(box);
	
	activateInstructions();
}

function install(evt) {
	displayInstructions();
	
	var params = {
		AVIM: {
			URL: evt.target.href,
			IconURL: evt.target.getAttribute("iconsrc"),
			Hash: evt.target.getAttribute("hash"),
			toString: function () {
				return this.URL;
			}
		}
	};
	try {
		InstallTrigger.install(params);
	}
	catch (e) {
		return true;
	}
	return false;
}
