
function getStyle(el,styleProp)
{
	//styleProp.replace("-","");
	var x = document.getElementById(el);

	if (window.getComputedStyle)
	{
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	}
	else if (x.currentStyle)
	{
		var s = styleProp.indexOf("-");
		styleProp = styleProp.substring(0,s)+styleProp.substring(s+1,styleProp.length);
		var y = x.currentStyle[styleProp];
	}
	return y;
}

var stateFlashing = "yellow none";
var stateNormal;
var isFlashing = 0;
var timer;
var flashID;

function startFlashing(eid, newbg)
{
	eid = replaceAll(eid," ","");
	eid = replaceAll(eid,"'","");
	stateNormal = getStyle(eid, "background-Color") + " " + getStyle(eid, "background-Image") + " " + getStyle(eid, "background-Repeat") + " " + getStyle(eid, "background-Attachment");
	stateFlashing = getStyle(eid, "background-Color") + " url('" + newbg + "') " + getStyle(eid, "background-Repeat") + " " + getStyle(eid, "background-Attachment");
	timer = setTimeout("flash()", 500);
	flashID = eid;
}

function flash()
{
	var el = document.getElementById(flashID);
	
	if(isFlashing == 1)
	{
		el.style.background = stateNormal;
		isFlashing = 0;
	}
	else
	{
		el.style.background = stateFlashing;
		isFlashing = 1;
	}
	timer = setTimeout("flash()", 500);
}

function stopFlashing()
{
	clearTimeout(timer);
	if(flashID)
	{
		var el = document.getElementById(flashID);
		el.style.background = stateNormal;
	}
}

function menuSelect(mid)
{
	mid = replaceAll(mid," ","");
	mid = replaceAll(mid,"'","");
	var el = document.getElementById(mid);
	el.style.background = "transparent " + getStyle(mid, "background-Image") + " no-repeat scroll 0% -23px";
	el.onmouseover = function () {this.style.background = "transparent " + getStyle(mid, "background-Image") + " no-repeat scroll 0% -23px";};
	el.onmouseout = function () {this.style.background = "transparent " + getStyle(mid, "background-Image") + " no-repeat scroll 0% -23px";};
}

function menuUnselect(mid)
{
	mid = replaceAll(mid," ","");
	mid = replaceAll(mid,"'","");
	var el = document.getElementById(mid);
	el.style.background = "transparent " + getStyle(mid, "background-Image") + " no-repeat scroll 0% 0%";
	el.onmouseover = function () {this.style.background = "transparent " + getStyle(mid, "background-Image") + " no-repeat scroll 0% -23px";};
	el.onmouseout = function () {this.style.background = "transparent " + getStyle(mid, "background-Image") + " no-repeat scroll 0% 0%";};
}

function subMenuSelect(mid, sid)
{
	mid = replaceAll(mid," ","");
	sid = replaceAll(sid," ","");
	mid = replaceAll(mid,"'","");
	sid = replaceAll(sid,"'","");
	menuSelect(mid);
	var mel = document.getElementById(mid);
	var melSub = document.getElementById(mel.className);
	melSub.parentNode.className = "hover";

	var sel = document.getElementById(sid).firstChild;
	sel.style.backgroundColor = "#5B5B5B";
	sel.style.color = "#FFFFFF";
	sel.onmouseout = function () { this.style.color = "#FFFFFF"; this.style.backgroundColor = "#5B5B5B"; };
	sel.onmouseover = function () { this.style.color = "#FFFFFF"; this.style.backgroundColor = "#5B5B5B"; };

}


function subMenuUnselect(mid, sid)
{
	mid = replaceAll(mid," ","");
	sid = replaceAll(sid," ","");
	mid = replaceAll(mid,"'","");
	sid = replaceAll(sid,"'","");
	menuUnselect(mid);
	var mel = document.getElementById(mid);
	var melSub = document.getElementById(mel.className);
	
	melSub.parentNode.className = "";
	
	var sel = document.getElementById(sid).firstChild;
	sel.style.backgroundColor = "#ffcc00";
	sel.style.color = "#000000";
	sel.onmouseout = function () { this.style.color = "#000000"; this.style.backgroundColor = "#ffcc00"; };
	sel.onmouseover = function () { this.style.color = "#FFFFFF"; this.style.backgroundColor = "#5B5B5B"; };
}

function resetAll()
{
	stopFlashing();
	var navigation = document.getElementById("navigation");	
	var menuItems = navigation.getElementsByTagName("li");
	for(var i = 0; i < menuItems.length; i++)
	{
		if(menuItems[i].id)
		{
			var sid = menuItems[i].id;
			var mid = menuItems[i].parentNode.parentNode.childNodes[0].id;
			subMenuUnselect(mid, sid);
		}
	}
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }

    return str;
}