var counter=1;

$(document).ready(function() {
	$('table.twoColumn td:nth-child(2) p a').each(function() {
		if ($(this).html().toLowerCase().indexOf('span') == -1 && $(this).html().toLowerCase().indexOf('img') == -1 && $(this).html().toLowerCase().indexOf('<br>') > -1) {
		    // This adds a <span class="greylink"> around the second line
		    $(this).html(
		    	$(this).html().substring(
		    		0,$(this).html().search(/<br>/i)
		    	) 
		    	+ '<br /><span class="greylink">' 
		    	+ $(this).html().substring(
		    		$(this).html().search(/<br>/i)+4
		    	) + '</span>'
		    );			
		}
	});		
    
    $('div#translate label span').hide();
    if ($('div#translate label span').size() > 0) {
        $('div#translate label span:nth-child(1)').show();
        setInterval('updateLanguage()',2000);
    }
});

function updateLanguage() {
    //alert(counter + "/" + $('div#translate label span').size())
    if(counter == $('div#translate label span').size()) {
        counter = 0;
        $('div#translate label span:nth-child(' + $('div#translate label span').size() + ')').hide(0)
    }
    
    $('div#translate label span:nth-child(' + counter + ')').hide(0)
    $('div#translate label span:nth-child(' + (counter+1) + ')').show(0);   
    counter++;
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	}
}


sfHover2 = function() {
	var sfEls = document.getElementById("mainNav").getElementsByTagName("A");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			document.getElementById('rollovertext').innerHTML = this.title;
		}
		sfEls[i].onmouseout=function() {
			document.getElementById('rollovertext').innerHTML = '&nbsp;'
		}
	}
}

mcAccessible = function() {
	var mcEls = document.getElementById("nav").getElementsByTagName("A");
	for (var i=0; i<mcEls.length; i++) {
		mcEls[i].onfocus=function() {
			this.className+=(this.className.length>0? " ": "") + "sffocus"; //a:focus
			this.parentNode.className+=(this.parentNode.className.length>0? " ": "") + "sfhover"; //li < a:focus
			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {
				this.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < a:focus
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < ul < li < a:focus
				}
			}
		}
		mcEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
			this.parentNode.className=this.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {
				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				}
			}
		}
	}
}

// only ie needs the sfHover script. all need the accessibility script...
// thanks http://www.brothercake.com/site/resources/scripts/onload/
if(window.addEventListener) {
	window.addEventListener('load', sfHover2, false); // gecko, safari, konqueror and standard
	//window.addEventListener('load', mcAccessible, false); // gecko, safari, konqueror and standard
	window.addEventListener('load', addOnloads, false); // gecko, safari, konqueror and standard
} else if(document.addEventListener) {
	document.addEventListener('load', sfHover2, false); // opera 7
	//document.addEventListener('load', mcAccessible, false); // opera 7
	document.addEventListener('load', addOnloads, false); // opera 7
} else if(window.attachEvent) { // win/ie
	//window.attachEvent('onload', sfHover);
	window.attachEvent('onload', sfHover2);
	//window.attachEvent('onload', mcAccessible);
	window.attachEvent('onload', addOnloads);
} else { // mac/ie5
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			//sfHover();
			sfHover2();
			//mcAccessible();
			addOnloads();
		}
	} else {
		window.onload = function() {
			//sfHover();
			sfHover2();
			//mcAccessible();
			addOnloads();
		}
	}
}