(function($) {
	
	// --------------------
	//   ロールオーバー処理
	// default : _o の画像と切り替え
	// alpha : 透明度を変更
	// --------------------
	$.fn.rollOver = function(options) {
		if(this.length == 0) return;
		var c = $.extend({
			mode: "default",  //default , alpha , fade , blink
			overImg:"_o",
			outImg:"",
			currentImg:"_c",
			speed: 200,
			overAlpha:"0.8",
			outAlpha:"1"
		}, options || {});
		
		$(this).each(function() {
			var img = $(this);
			if(c.mode == "fade"){
				var imgW = img.width();
				var imgH = img.height();
				var extension = img.attr("src").match(/.gif$|.jpg$|.png$/);
				var re = new RegExp(c.outImg+extension);
				var imgOverPath = img.attr("src").toString().replace(re,c.overImg+extension);
				$(img.parent()[0]).css({
					width:imgW+"px",
					height:imgH+"px",
					background:"url("+imgOverPath+")",
					display:"block"
				});
			}
			img.data("_options", c);
			img.bind("mouseover",imgoverfunc);
			img.bind("mouseout",imgoutfunc);
		});
	}
	
	function imgoverfunc(){
		var img = $(this);
		var c = img.data("_options");
		if(c.mode == "default"){
			var extension = img.attr("src").match(/.gif$|.jpg$|.png$/);
			var re = new RegExp(c.outImg+extension);
			img.attr("src",
				img.attr("src").replace(re,c.overImg+extension)
			);
		} else if(c.mode == "alpha" || c.mode == "fade"){
			img.stop().fadeTo(c.speed,c.overAlpha);
		} else if(c.mode == "blink"){
			//img.stop().fadeTo(0,c.overAlpha).fadeTo(c.speed,c.outAlpha);
			img.stop().fadeTo(0,c.overAlpha).animate({ opacity: c.outAlpha}, c.speed , "easeInQuad" );
		}
	}
	
	function imgoutfunc(){
		var img = $(this);
		var c = img.data("_options");
		if(c.mode == "default"){
			var extension = img.attr("src").match(/.gif$|.jpg$|.png$/);
			var re = new RegExp(c.overImg+extension);
			img.attr("src",
				img.attr("src").replace(re,c.outImg+extension)
			);
		} else if(c.mode == "alpha" || c.mode == "fade"){
			img.stop().fadeTo(c.speed,c.outAlpha);
		}
	}
	
	// --------------------
	//   該当クラスにあたるimgoverをOFFにする(最初からover状態とする)
	// --------------------
	$.fn.rollOverCurrent = function(options) {
		var img = $("img",this);
		var extension = img.attr("src").match(/.gif$|.jpg$|.png$/);
		var c =  img.data("_options");
		var re = new RegExp(c.outImg+extension);
		img.attr("src",
			img.attr("src").replace(re,c.currentImg+extension)
		);
		img.unbind("mouseover",imgoverfunc);
		img.unbind("mouseout",imgoutfunc);
	}
	
	// --------------------
	//   該当クラスにあたるimgoverをOFFにする
	// --------------------
	$.fn.rollOverIgnore = function(options) {
		var img = $("img",this);
		img.unbind("mouseover",imgoverfunc);
		img.unbind("mouseout",imgoutfunc);
	}
	
	$.fn.boxrollover = function(options) {
		$(this).each(function() {
			var c = $(this);
			c.css("cursor","pointer");
			c.click(function(){
				location.href = $(this).find("a").attr("href");
			});
			c.hover(
				function () {
					c.css("background","#308dcd");
				},
				function () {
					c.css("background","#FFFFFF");
				}
			);
		});
	}

})(jQuery)

jQuery(function($){
	//naviのロールオーバーをセット
	$('.imgover').rollOver({mode:"default"});
	$('.alphaover').rollOver({mode:"alpha",speed:0});
	$('.fadeover').rollOver({mode:"fade",speed:400,overAlpha:0});
	$('.blinkover').rollOver({mode:"blink",overAlpha:0.4,speed:700});
	
	//boxロールオーバー
	$('.boxrollover').boxrollover();
	
	//naviのクリックスライド
	var oldli;
	$('#navi > li').each(function(){
		var self = $(this);
		self.mouseover(function(){
			if(oldli == this) return;
			oldli = this;
			var target = $(this);
			$('#navi > li').each(function(){
				var snavi = $(".smallnavi",this);
				if(target.attr("id") == $(this).attr("id")){
					var snavi = $(".smallnavi",this);
					if ( !($.browser.msie && $.browser.version < 7)) $(".bglight",this).addClass("bglighton");
					snavi.data("_slide",true);
					snavi.stop(true,true).slideDown(400);
					target.trigger("gridsort"); //グリッドカテゴリソートのためにトリガーする。
				} else {
					if(snavi.data("_slide")){
						$(".bglight",this).removeClass("bglighton");
						snavi.data("_slide",false);
						snavi.stop(true,true).delay(20).slideUp(400);
					}
				}
			});
			//
		});
	})
	
//naviのcurrent表示
//console.log(window.location);
	var hostname = window.location.hostname;
	var path = window.location.pathname;
	var href = window.location.href;

	if(href.indexOf(hostname+"/service/") != -1){
		$("#navi_service").rollOverCurrent();
	} else if(href.indexOf(hostname+"/company/") != -1) {
		$("#navi_company").rollOverCurrent();
	} else if(href.indexOf(hostname+"/blog/") != -1) {
		$("#navi_blog").rollOverCurrent();
	}
	
	//ページ内スクロール
	$('a[href*=#]').not(".ignore").click(function() {
		//console.log(location.pathname.replace(/^\//,''));
		//console.log( this.pathname.replace(/^\//,'') ) ;
		//console.log(location.hostname);
		//console.log(this.hostname);
		
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $(this.hash);
			target = target.length && target;
			if (target.length) {
				var sclpos = 30;
				var scldurat = 700;
				var targetOffset = target.offset().top - sclpos;
				$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat,easing:"easeOutExpo"});
				return false;
			}
		}
	});
	
	
});


