var email_regex1 = /my_name_is_/g;
var email_regex2 = /_and_the_domain_is_/g;
var email_regex3 = /my name is/g;
var email_delay = 200;  // short delay to fool any DOM-enabled scrapers from the future!

function email_callFixHrefs() {
	setTimeout("email_fixHrefs()",email_delay);  
}
function email_fixHrefs() {
	var newHref;
	
	// cycle through all anchors
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
	    // require phrase in href property
		if (!email_regex1.test(links[i].href)) continue;
		
		newHref = new String(links[i].href);
		newHref = newHref.replace(email_regex1,"");
		newHref = newHref.replace(email_regex2,"@");
		links[i].setAttribute("href",newHref);
			
		if (email_regex3.test(links[i].getAttribute("title"))) {
			links[i].setAttribute("title","");
		}
		
	}
}

function fnLoadPNG(id) /* adapted from sleight.js */
{
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && window.createPopup);
	if (!itsAllGood) return;

	var img = document.getElementById(id);
	img.style.visibility = "hidden";
	var src = img.src;
	var div = document.createElement("DIV");
	div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')";
	div.style.width = img.width + "px";
	div.style.height = img.height + "px";
	img.replaceNode(div);
	//img.style.visibility = "visible";
}

function Color(r,g,b) 
{
	this.r = r; this.g = g; this.b = b;
	this.getColor = function () {
		return "rgb("+this.r+","+this.g+","+this.b+")";
	}
}

var 
	logo,
	current_color = new Color(255,255,255),
	colors_array = new Array,
	link_colors = new Array,
	cycle_wait_ms = 25,
	cycle_running = false;

link_colors[-1] = new Color(255,255,255);
link_colors[0] = new Color(0,117,147);
link_colors[1] = new Color(0,164,0);
link_colors[2] = new Color(220,16,16);
link_colors[3] = new Color(174,131,0);
link_colors[4] = new Color(153,153,204);

function setup_colorAction()
{
	var 
		nav = document.getElementById('nav'),
		a,
		i = 0;
	while(a=nav.getElementsByTagName('a').item(i++))
	{
		a.onmouseover = mouseGoesOver;
		a.onmouseout = mouseGoesOut;
		a.index = (i-1);
		a.getElementsByTagName('img')[0].title = ""; /* IE don't show alts */
	}
}

function mouseGoesOver()
{
	fade_to_color(link_colors[this.index],5);
}
function mouseGoesOut()
{
	fade_to_color(link_colors[-1],20);
}

function color_cycle() {
	if (colors_array.length == 0) {
		cycle_running = false;
		return;
	}
	current_color = colors_array[colors_array.length-1];
	logo.style.backgroundColor = current_color.getColor();
	colors_array.length = (colors_array.length - 1);
	setTimeout("color_cycle()",cycle_wait_ms);
}

function fade_to_color(newColor,steps) {
	var 
		i, r, g, b;
	colors_array.length = 0;
	for (i = 1; i <= steps; i++) 
	{
		r = Math.floor(current_color.r * ((steps-i)/steps) + newColor.r * (i/steps));
		g = Math.floor(current_color.g * ((steps-i)/steps) + newColor.g * (i/steps));
		b = Math.floor(current_color.b * ((steps-i)/steps) + newColor.b * (i/steps));
		// color_to_queue(new Color(r,g,b));
		colors_array[steps-i] = new Color(r,g,b);
	}
	
	if (!cycle_running)
	{
		cycle_running = true;
		color_cycle();
	}
}

window.onload = function() {
	if (typeof document.getElementsByTagName=='undefined') return;

	if (typeof current_page=='undefined') 
	{
		logo = document.getElementById('logo');
		setup_colorAction();
		fnLoadPNG('logoIMG');
	} 
	else if (current_page=="home")
	{
		if (document.images) 
		{
			var pl = new Image;
			pl.src = "images/home_container_bg.gif";
		}
	}
}