$(window).bind('load',function(){

    var $el, leftPos, newWidth,
        $mainNav = $("#navigation");
    
    if ($(".current_page_item").length) {
	    $mainNav.append("<li id='magic-line'></li>");
	    
	    var $magicLine = $("#magic-line");
	    
	    $magicLine
	        .width($(".current_page_item").width())
	        .css("left", $(".current_page_item a").position().left -5 )
	        .data("origLeft", $magicLine.position().left)
	        .data("origWidth", $magicLine.width());
	        
	    $("#navigation li").find("a").hover(function() {
	        $el = $(this);
	        leftPos = $el.position().left -5 ;
	        newWidth = $el.parent().width();
	        
	        $magicLine.stop().animate({
	            left: leftPos,
	            width: newWidth
	        });
	    }, function() {
	        $magicLine.stop().animate({
	            left: $magicLine.data("origLeft"),
	            width: $magicLine.data("origWidth")
	        });    
	    });
    }

});
