/**
 * jQuery.config
 *
 * @author     sugimoto
 * @copyright  2011- ashitaba.jp
 * @comment
 * 各種設定を記述
 * 多くのページで共通で利用するものについて記載
 * 単体ページでの利用についてはそのページのhead部に記載の事
 */
jQuery(function($){

    // ロールオーバー
    $('.nav a img, .rollover').rollover();

    // スムーススクロール
    $(".scroll").scrollAnchors({duration: 1000, easing: "swing"});

    // 別窓を開く xhtmlでは、target="_blank"は駄目
    $("a._blank").click(function(){
        window.open(this.href,'_blank');
        return false;
    });

    // 別窓を開く
    $("a.popup").click(function(){
        window.open(this.href,'_blank', "WindowName", "width=300, height=200, resizable=none, scrollbars=none");
        return false;
    });
});

/**
 * jQuery.rollover
 *
 * @version    1.0.4
 * @author     Hiroshi Hoaki <rewish.org@gmail.com>
 * @copyright  2010-2011 Hiroshi Hoaki
 * @license    http://rewish.org/license/mit The MIT License
 * @link       http://rewish.org/javascript/jquery_rollover_plugin
 */
jQuery.fn.rollover = function(suffix) {
	suffix = suffix || '_on';
	var check = new RegExp(suffix + '\\.\\w+$');
	return this.each(function() {
		var img = jQuery(this);
		var src = img.attr('src');
		if (check.test(src)) return;
		var _on = src.replace(/\.\w+$/, suffix + '$&');
		jQuery('<img>').attr('src', _on);
		img.hover(
			function() { img.attr('src', _on); },
			function() { img.attr('src', src); }
		);
	});
};

// スムーススクロール
jQuery.fn.scrollAnchors = function(options) {
    var settings = {duration: 500, easing: "swing"};
    if (options) $.extend(settings,options);
    return $(this).click(function(event) {
        event.preventDefault();
        var target_offset = $("a[name="+this.hash.slice(1)+"]").offset();
        var target_top = target_offset.top;
        $('html, body').animate(
            {scrollTop:target_top},
            settings.duration,
            settings.easing
        );
    });
}
