// RollOver
$(function () {
    $.rollover = {
        init: function () {
            $('a img,input[type="image"]').not('[src*="_on."]')
                .bind('mouseover', this.over)
                .bind('mouseout',  this.out)
                .each(this.preload);
        },

        over : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_off.', '_on.'));
        },

        out : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_on.', '_off.'));
        },

        preload : function () {
            new Image().src = this.getAttribute('src').replace('_off.', '_on.');
        }
    };
    
    // ページトップへ
    $('p.pagetop a').each(function(){
        var href = document.location.href.split('/');
        href.shift();
        href.shift();
        href.shift();
        href = '/'+href.join('/');
        if (href.indexOf('#')!=-1) {
            href = href.split('#')[0];
        }
        $(this).attr('href', href+'#top');
    });
    
    // スムーズスクロール
    $('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')) {
            var $target = jQuery(this.hash);
            $target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                jQuery('html,body').animate({ scrollTop: targetOffset }, 1400, 'quart');
                return false;
            }
        }
    });
    
    // グローバルメニュー
    $('ul#nav a').each(function(){
        if (document.location.href == this.href) {
            $(this).parent().addClass('current');
        }
    });
    
    // サブメニュー
    $('ul#submenu a').each(function(){
        if (document.location.href == this.href) {
            var src = $('img', this).attr('src');
            if (src) {
                $('img', this).attr('src', src.replace('_off','_on'));
            }
        }
    });
    
    $.rollover.init();
    
});

// Easingの追加
jQuery.easing.quart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
