/* Copyright 2008 by Terry McNavage. All rights reserved. */

(function() {
			 
var sprites = {}, swaps = {};

function bind(n, t, f, p) {
	if (n.addEventListener) n.addEventListener(t, f, !!p);
	else if (n.attachEvent) n.attachEvent("on" + t, f);
}

function wakeSprites() {
	if (!document.getElementsByTagName) return;
	var i, n, a, re = /^t[1-4]$/i;
	a = document.getElementsByTagName("a");
	for (var i = 0; i < a.length; i += 1) {
		n = a[i];
		if (n.parentNode.parentNode.className == "sprites") {
			if (re.test(n.parentNode.className)) {
				sprites[n.parentNode.className] = [];
				if (window.getComputedStyle) sprites[n.parentNode.className] = [window.getComputedStyle(n, null).backgroundPosition];
				else if (n.currentStyle) sprites[n.parentNode.className] = n.currentStyle.backgroundPosition;
				sprites[n.parentNode.className][1] = sprites[n.parentNode.className][0].replace(/-17px$/i, "8px");
				bind(n, "mouseover", doTab);
				bind(n, "mouseout", doTab);
			} else {
				sprites[n.id] = [];
				if (window.getComputedStyle) sprites[n.id] = [window.getComputedStyle(n, null).backgroundPosition];
				else if (n.currentStyle) sprites[n.id] = n.currentStyle.backgroundPosition;
				sprites[n.id][1] = sprites[n.id][0].replace(/^-9px/i, "-139px");
				bind(n, "mouseover", doOakley);
				bind(n, "mouseout", doOakley);
			}
		}
	}
}

function wakeSwaps() {
	if (!document.getElementsByTagName) return;
	var i, n, a;
	a = document.getElementsByTagName("input");
	for (var i = 0; i < a.length; i += 1) {
		n = a[i];
		if (n.type.toLowerCase() != "image") continue;
		swaps[n.className] = [n.src, n.src.replace(/\.gif$/i, "3$&")];
		(new Image()).src = swaps[n.className][1];
		bind(n, "mouseover", doSwap);
		bind(n, "mouseout", doSwap);
	}
}

function doOakley(e) {
	if (!e) e = window.event;
	var t = e.target || e.srcElement;
	if (t.nodeName.toLowerCase() != "a") return;
	if (e.type == "mouseover") t.style.backgroundPosition = sprites[t.id][1];
	else t.style.backgroundPosition = sprites[t.id][0];
}

function doTab(e) {
	if (!e) e = window.event;
	var t = e.target || e.srcElement;
	if (t.nodeName.toLowerCase() != "a") return;
	if (e.type == "mouseover") t.style.backgroundPosition = sprites[t.parentNode.className][1];
	else t.style.backgroundPosition = sprites[t.parentNode.className][0];
}

function doSwap(e) {
	if (!e) e = window.event;
	var t = e.target || e.srcElement;
	if (e.type == "mouseover") t.src = swaps[t.className][1];
	else t.src = swaps[t.className][0];
}

bind(window, "load", wakeSprites);
bind(window, "load", wakeSwaps);

})();
