$(function() {
	var $el, leftPos, newWidth, id, nocurrent,
	$mainNav;

	if(!$("#aboutus").hasClass('hideme')) { id = 'aboutus'; }
	else if(!$("#projects").hasClass('hideme')) {  id = 'projects'; }
	else if(!$("#services").hasClass('hideme')) {  id = 'services'; }
	else { id = ''; }

	if(id) {
		$mainNav = $('#'+id);
		$mainNav.append("<li id='magic-line'></li>");
		var $magicLine = $("#magic-line");
		var mylen = 0;
		if($('.mcurrent').length == 0) {
			nocurrent = 1; 
			mylen = 50;
			myleft = $('ul').position().left;;
			$magicLine.css('display','none');
		} else {
			mylen = $('.mcurrent a').width();
			if(mylen > 300) {mylen = 125; }
			myleft = $('.mcurrent a').position().left;
		}
		
		$magicLine.width(mylen).css("left", myleft).css("height", "1px").css("position", "absolute").data("origLeft", $magicLine.position().left).data("origWidth", $magicLine.width());
		
		$("."+id+" li a").hover(function() {
								$el = $(this);
								leftPos = $el.position().left;
								newWidth = $el.width();
								$magicLine.css('display','').stop().animate({left: leftPos,width: newWidth});
								}, function() {
								if(nocurrent) { $magicLine.stop().css('display', 'none'); } else {$magicLine.stop().animate({left: $magicLine.data("origLeft"), width: $magicLine.data("origWidth")});}
								});
}});
