$(function(){

    var $el, leftPos, newWidth,

        $mainNav = $("#example-two"),
        pageOffset = $mainNav.offset().left;
    
    
    // Fixing the offset if the window changes size    
    $(window).resize(function() {
        pageOffset = $mainNav.offset().left;
    });

    /*
        EXAMPLE TWO
    */
    $mainNav.append("<li id='magic-line-two'></li>");
    
    var $magicLineTwo = $("#magic-line-two");
    
    $magicLineTwo
        .width($(".current_page_item_two").width())
        .height($mainNav.height())
        .css("left", $(".current_page_item_two a").offset().left - pageOffset)
        .data("origLeft", $magicLineTwo.offset().left - pageOffset)
        .data("origWidth", $magicLineTwo.width())
        .data("origColor", $(".current_page_item_two a").attr("rel"));
        
    $("#example-two li").find("a").hover(function() {
        $el = $(this);
        leftPos = $el.offset().left - pageOffset;
        newWidth = $el.parent().width();
        $magicLineTwo.stop().animate({
            left: leftPos,
            width: newWidth,
            backgroundColor: $el.attr("rel")
        }, "slow", "easeOutBounce")
    }, function() {
        $el = $(this);
        $magicLineTwo.stop().animate({
            left: $magicLineTwo.data("origLeft"),
            width: $magicLineTwo.data("origWidth"),
            backgroundColor: $magicLineTwo.data("origColor")
        }, "slow", "easeOutBounce");    
    });
});
