/* -------------------------------------------------------------------
	* 共通関数実行
	* init
 ------------------------------------------------------------------- */
$(function(){
	imageOver();
})
 
//イメージのロールオーバー設定
function imageOver() {
 
	$("#GlobalNav a img,.subNav a img,img.over").each(function() {
 
		//イメージURLから拡張子を取り出し、ロールオーバー用イメージURLを作成
		var image = this.src;
		var extension = image.substr(image.lastIndexOf("."), image.length-1);
		var image_over = image.replace(extension, "on"+extension);
 
		//ロールオーバー用イメージを読み込み
		new Image().src = image_over;
 
		//ロールオーバー、ロールアウト時のイメージURL設定
		$(this).hover(
			function(){this.src = image_over},
			function(){this.src = image}
		);
	});
}

	
/* -------------------------------------------------------------------
	* 共通関数定義
	* @function
 ------------------------------------------------------------------- */
(function($){

	//プラグイン名
	var name_space = 'smoothscroll';

	//実行
	$(function (){
		$.fn[name_space]();
	});

	//プラグイン本体
	$.fn[name_space] = function(options){
		//設定
		var settings = $.extend({
			selector: "a[href^='#']",
			timer: 1200,
			defaulttop: '#'
		}, options);

		//イージング
		$.extend($.easing,{
			easeOutExpo: function (x, t, b, c, d) {
				return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
			}
		});
		//スムーススクロール処理
		$(settings.selector).click(function() {
			var id = this.href.substring(this.href.indexOf('#'),this.href.length);
			if(id != "#"){
				var target = $(id);
				var t = navigator.appName.match(/Opera/) ? "html" : "html,body";
				if(target){
					$(t).animate({scrollTop:target.offset().top}, settings.timer, "easeOutExpo");
					
				}else if(id == settings.defaulttop){
					$(t).animate({scrollTop:0}, settings.timer, "easeOutExpo");
				}
			}
			return false;
		});
		//method chain
		return this;
	};
	
})(jQuery)


