////////////////////////////////////////////////////////////////////////////////////////////////////
//
// isjl.js
// Icd Standard Javascript library
// author:satoshi manaka
// notice:required jQuery and jQuery.easing 
// charCode:UTF-8
//
////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* init
*/
$(function() {
	initImageSwap();
	initImageBright();
	//initSearchTextArea();
	initSmartScroll();
});

/*--------------------------------------------------------------------------------------------------
[効能]
<img>にマウスオーバーした際に、「_on」の付いた画像とスワップさせる。プリロード機能付。
[設置]
<img>タグにclass「imgSwap」を設定。
--------------------------------------------------------------------------------------------------*/
function initImageSwap() {
	$("img.imgSwap").mouseover(function() {
		$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	}).mouseout(function() {
		$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
	}).each(function() {
		$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
    });
}

/*--------------------------------------------------------------------------------------------------
[効能]
<img>にマウスオーバーした際に、画像の不透明度を下げ、オンマウスを表現する。
[設置]
<img>タグにclass「imgBright」を設定。
--------------------------------------------------------------------------------------------------*/
function initImageBright() {
	$("img.imgBright").mouseover(function() {
		$(this).fadeTo(0,0.6);
	}).mouseout(function() {
		$(this).fadeTo(0,1);
    });
}

/*--------------------------------------------------------------------------------------------------
[効能]
テキストエリアにフォーカスでデフォルトの文字列を消去。フォーカスアウトで文字列を表示。
[設置]
<input>タグにid「searchTextArea」を設定。
--------------------------------------------------------------------------------------------------*/
function initSearchTextArea() {
	$("#searchTextArea").focus(function() {
		if ($(this).val()=="サイト内検索") {
			$(this).val("");
		}
	}).blur(function() {
		if ($(this).val()=="") {
			$(this).val("サイト内検索");
		}
	});
}
/*--------------------------------------------------------------------------------------------------
[効能]
ページ内リンクに、イージング付スクロールを提供。アンカー付URLでページに入ってきた時の処理にも対応。
[設置]
<a>タグにclass「smartScroll」を設定。
--------------------------------------------------------------------------------------------------*/
var interval = 1000;
var transition = "easeOutExpo";
var splitHref = location.href.split('#');
var incomingFrom = splitHref[1];
var scrolledElement = navigator.appName.match(/Opera/) ? "html" : "html,body";
//
function setSmartScroll() {
	$("a.smartScroll").click(function() {
		$(scrolledElement).queue([]).stop();
		$(this).blur();
		startSmartScroll(getScrollTargetY($(this.hash)));
		return false;
	});
}
function initSmartScroll() {
	setSmartScroll();
	//
	if(incomingFrom) {
		setTimeout(function(){scrollTo(0,0);startSmartScroll(getScrollTargetY($("#"+incomingFrom)));},50);
	}
}
function startSmartScroll(_targetY) {
	$(scrolledElement).animate({ scrollTop:_targetY += "px" }, interval, transition);
}
function getScrollTargetY(_targetElement) {
	var scrollTargetY = _targetElement.offset().top;
		if (scrollTargetY < 10) {
			scrollTargetY = 0;
		}
	return scrollTargetY;
}
/*--------------------------------------------------------------------------------------------------
[効能]
画像のプリロード
[設置]
JS内に記述。
[文法]
jQuery.preLoadImages(getThisPath() + "画像ファイル名");
--------------------------------------------------------------------------------------------------*/
(function($) {  
	var cache = [];  
	$.preLoadImages = function() {  
		var args_len = arguments.length;  
		for (var i = args_len; i--;) {  
		var cacheImage = document.createElement('img');  
		cacheImage.src = arguments[i];  
		cache.push(cacheImage);  
		}  
	}  
})(jQuery)

function getThisPath() {
	var root;
    var scripts = document.getElementsByTagName("script");
    var i = scripts.length;
    while (i--) {
        var match = scripts[i].src.match(/(^|.*\/)common\/js\/lib\/isjl\.js$/);
        if (match) {
            root = match[1];
            break;
        }
    }
    return root;
}
