/* ===========================================
 * 心斎橋スリーアロークリニック
 * -------------------------------------------
 * JS Library
 * -------------------------------------------
 * 2011.08.04
=========================================== */


/* RollOver
=========================================== */

var rollover = {
	setInit : function(){
		rollover.p = new Object();
		$("img[src*='_n.'],input[src*='_n.']").each(function(){
			var n = this.src;
			var o = n.replace("_n.", "_o.");
			if(!rollover.p[n]){
				rollover.p[n] = new Image();
				rollover.p[n].src = n;
				rollover.p[o] = new Image();
				rollover.p[o].src = o;
			}
			if(!$(this).hasClass("ro_exc")){
				$(this).hover(function(){
					if(!$(this).hasClass("ro_stay") && this.src.lastIndexOf("_n.") > -1) this.src = rollover.p[o].src;
				}, function(){
					if(!$(this).hasClass("ro_stay") && this.src.lastIndexOf("_o.") > -1) this.src = rollover.p[n].src;
				});
			}
		});
	}
}


/* AnimeScroll
=========================================== */

jQuery.easing.quart = function(x, t, b, c, d){
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

var aniscroll = {
	setInit : function(){
		$('a[href*=#]').click(function(){
			if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname){
				var $target = $(this.hash);
				$target = $target.length && $target || $('[name='+this.hash.slice(1)+']');
				if($target.length){
					var targetOffset = $target.offset().top;
					var targetTag = navigator.appName.match(/Opera/)? "html" : "html,body";
					$(targetTag).animate({scrollTop: targetOffset}, 'quart');
					return false;
				}
			}
		});
	}
}


/* ========================================
 * START
=========================================== */

$(document).ready(function(){

	// RollOver
	rollover.setInit();

	// AnimeScroll
	aniscroll.setInit();

});

