//スムーススクロール
(function($){
	//プラグイン名
	var name_space = 'smoothscroll';

	//実行
	$(function (){
		$.fn[name_space]();
	});

	//プラグイン本体
	$.fn[name_space] = function(options){
		//設定
		var settings = $.extend({
			selector: "a[href^='#']",
			timer: 1200,
			defaulttop: '#top'
		}, 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");
				}
			}
			/*if(id != "#"){
				var target = $(id);
				if(target){
					$('html,body').animate({scrollTop:target.offset().top}, settings.timer, "easeOutExpo");
				}else if(id == settings.defaulttop){
					$('html,body').animate({scrollTop:0}, settings.timer, "easeOutExpo");
				}
			}*/
			return false;
		});
		//method chain
		return this;
	};
})(jQuery);

