$(function(){

    var $el, leftPos, newWidth,
        $mainNav = $("#menu-one");    
    /*
        MENU ONE
    */
    $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)
        .data("origLeft", $magicLine.position().left)
        .data("origWidth", $magicLine.width());
        
    $("#menu-one li").find("a").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();
        
        $magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        $magicLine.stop().animate({
            left: $magicLine.data("origLeft"),
            width: $magicLine.data("origWidth")
        });    
    });
    
});

/*テキストリンク*/

$(function() {

    var $el = $(),
        linkHeight = parseInt($("p").css("line-height")),
        speed = 175;  //  1000 = 1 second
    
    
    // FIRST TECHNIQUE      
    $("#first a").each(function() {
    
        $el = $(this);
        
        // If the link spans two lines, put a line break before it.
        if ($el.height() > linkHeight) {
            $el.before("<br />");  
        }
        
        $el.prepend("<span></span>");
    
    }).hover(function() {
        
        $el = $(this);
                
        $el.find("span").stop().animate({ height: linkHeight, opacity: 0.3 }, speed);
    
    }, function() {
    
        $el = $(this);
                
        $el.find("span").stop().animate({ height: "1px", opacity: 1}, speed);
    
    });
    
    
    // SECOND TECHNIQUE
    $("#second a").hover(function() {
        
        $el = $(this);
                
        $el.stop().animate({ backgroundPosition: "(0px 0px)", color: "white" }, speed);
    
    }, function() {
    
        $el = $(this);
                
        $el.stop().animate({ backgroundPosition: "(0px 15px)", color: "#900" }, speed);
    
    });
    
    // SECOND TECHNIQUE
    $("#third a").hover(function() {
        
        $el = $(this);
                
        $el.stop().animate({ backgroundPosition: "(0px 0px)", color: "white" }, 300);
    
    }, function() {
    
        $el = $(this);
                
        $el.stop().animate({ backgroundPosition: "(0px 100px)", color: "#900" }, 300);
    
    });

// SECOND TECHNIQUE
    $("#third02 a").hover(function() {
        
        $el = $(this);
                
        $el.stop().animate({ backgroundPosition: "(0px 0px)", color: "white" }, 300);
    
    }, function() {
    
        $el = $(this);
                
        $el.stop().animate({ backgroundPosition: "(0px 100px)", color: "#900" }, 300);
    
    });


});

/*ボックスの真ん中にリンク*/
var $el, $tempDiv, $tempButton, divHeight = 0;

$.fn.middleBoxButton = function(text, url, rel) {
    
    return this.hover(function(e) {
    
        $el = $(this).css("border-color", "white");
        divHeight = $el.height() + parseInt($el.css("padding-top")) + parseInt($el.css("padding-bottom"));
                
        $tempDiv = $("<div />", {
            "class": "overlay rounded"
        });
                
        $tempButton = $("<a />", {
            "href": url,
			"target": "_blank",
            "text": text,
			"rel": "imgbox",
            "class": "widget-button rounded",
            "css": {
                "top": (divHeight / 2) - 7 + "px"
            }
        }).appendTo($tempDiv);
                
        $tempDiv.appendTo($el);
        
    }, function(e) {
    
        $el = $(this).css("border-color", "#999");
    
        $(".overlay").fadeOut("fast", function() {
            $(this).remove();
        })
    
    });
    
}

$(function() {
    
    $(".widget-one").middleBoxButton("Go to Sample01","http://www.timsnavi.net/temp/01/");
    $(".widget-two").middleBoxButton("Go to Sample02", "http://www.timsnavi.net/temp/02/");
    $(".widget-three").middleBoxButton("Go to Sample03", "http://www.timsnavi.net/temp/03/");
    $(".widget-four").middleBoxButton("Go to Sample04", "http://www.timsnavi.net/temp/04/");
    $(".widget-five").middleBoxButton("Go to Sample05","http://www.timsnavi.net/temp/05/");
    $(".widget-six").middleBoxButton("Go to Sample06", "http://www.timsnavi.net/temp/06/");
    $(".widget-seven").middleBoxButton("Go to Sample07", "http://www.timsnavi.net/temp/07/");
    $(".widget-eight").middleBoxButton("Go to Sample08", "http://www.timsnavi.net/temp/08/");
    $(".widget-nine").middleBoxButton("Go to Sample09", "http://www.timsnavi.net/temp/09/");
    $(".widget-ten").middleBoxButton("Go to Sample10", "http://www.timsnavi.net/temp/10/");
});
