
function getBaseImageName(image) {
	image = image.replace(/^\s|\s$/g, ""); //trims string
	
	var regexp = image.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
	var filepath = regexp[1];
	var filename = regexp[2];

	if (filename.match(/([^\/\\]+)\.(gif|jpg|png)$/i))
		filename = RegExp.$1;
		
	if(filename.match(/([^\/\\]+)\-(bold|pink|white)$/i))
		filename = RegExp.$1;
		
	return {path:filepath, name:filename};
}

function highlightNavItem(elem) {
	$('li:visible > a > img', elem).mouseenter(
		function () {
			var fileInfo = getBaseImageName($(this).attr('src'));
			$(this).attr({src:fileInfo.path + "/" + fileInfo.name + "-pink.gif"});
		}
	);
	
	$('li:visible > a > img', elem).mouseleave(
		function () {
			var selected = $(this).parent().parent().attr('class') == "selected";
			var imageType = selected ? "bold" : "white";
			var fileInfo = getBaseImageName($(this).attr('src'));
			$(this).attr({src:fileInfo.path + "/" + fileInfo.name + "-" + imageType + ".gif"}); 
		}
	);
}

$(document).ready(function () { 
     
    $('#nav li').hover(
        function () {
            //show its submenu
            $('ul', this).slideDown(100);
			highlightNavItem(this);
        }, 
        function () {
            //hide its submenu
            $('ul', this).slideUp(100);         
        }
    );
     
});
