﻿/*
 * yuga.js 0.3.0 - 優雅なWeb制作のためのJS
 *
 * Copyright (c) 2007 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2006-10-30
 * Modified:  2007-06-18
 * Modified:  2010-09-04 by M.Tanaka
 *
 */

/* common.js内で使っているfunction群 */
myDate = new Date();
var $thisYear = myDate.getFullYear();
var yuga = {
	// imageのプリローダー
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	},
	// URIを解析したオブジェクトを返すfunction
	URI: function(s){
		this.originalPath = s;
		
		// 絶対パスを取得
		this.getAbsolutePath = function(path){
			var img = new Image();
			img.src = path;
			path = img.src;
			img.src = '#';
			return path;
		};
	
		this.absolutePath = this.getAbsolutePath(s);
	
		// 同じ文書にリンクしているかどうか
		this.isSelfLink = (this.absolutePath == location.href);
	
		// 絶対パスを分解
		var a = this.absolutePath.split('://');
		this.schema = a[0];
		var d = a[1].split('/');
		this.host = d.shift();
		var f = d.pop();
		this.dirs = d;
		this.file = f.split('?')[0].split('#')[0];
		var fn = this.file.split('.');
		this.fileExtension = (fn.length == 1) ? '' : fn.pop();
		this.fileName = fn.join('.');
		var fq = f.split('?');
		this.query = (fq[1]) ? fq[1].split('#')[0] : '';
		var ff = f.split('#');
		this.fragment = (ff[1]) ? ff[1].split('?')[0] : '';	
	}
};

$(function(){
		
	// [RollOver] Alpha
	$('#service a img').hover(function(){ $(this).css('opacity','0.7'); },function(){	$(this).css('opacity','1');	});
	$('#side li img').not('#side li img.over').hover(function(){ $(this).css('opacity','0.7'); },function(){	$(this).css('opacity','1');	});
	$('#group li img').hover(function(){ $(this).css('opacity','0.7'); },function(){	$(this).css('opacity','1');	});
	$('#categorylist img').hover(function(){ $(this).css('opacity','0.7'); },function(){	$(this).css('opacity','1');	});
	
	// [RollOver] class="over"
	$('.over').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});
	if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)) {
		$('#main-img ul li a img').each(function(){
			this.originalSrc = $(this).attr('src');
			this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
			yuga.preloader.load(this.rolloverSrc);
		}).hover(function(){
			$(this).attr('src',this.rolloverSrc);
		},function(){
			$(this).attr('src',this.originalSrc);
		});
	}
	
	// Link Setting
	//   [1] Blank
	$('a[href$=".xls"], a[href$=".xlsx"],a[href$=".doc"], a[href$=".docx"],a[href$=".ppt"], a[href$=".pptx"],a[href$=".pdf"]').attr('target', '_blank');
	$('a[href^="http"],a[href^="https"],area[href^="http"]').filter(function(){
		var $SearchResult1 = $(this).attr('href').indexOf("http://www.moshimoshi.co.jp/",0);
		var $SearchResult2 = $(this).attr('href').indexOf("https://www.moshimoshi.co.jp/",0);
		var $Result = ($(this).attr('class') != 'notblank' && $SearchResult1 < 0 && $SearchResult2 < 0 );
		return $Result;
	}).attr('target', '_blank');

	//   [2] External
	$('#main a[href^="http"]').filter(function(){
			var $SearchResult1 = $(this).attr('href').indexOf("http://www.moshimoshi.co.jp/",0);
			var $SearchResult2 = $(this).attr('href').indexOf("https://www.moshimoshi.co.jp/",0);
			var $ThisContent = $(this).html().toLowerCase();
			var $ImgResult = $ThisContent.indexOf("img",0);
			var $Result = ($(this).attr('class') != 'notexternal' && $(this).attr('class') != 'notblank' && $SearchResult1 < 0 && $SearchResult2 < 0 && $ImgResult < 0);
			return $Result;
		}).addClass('external');

	//   [3] FileLink
	$('#main a[href$=".xls"], #main a[href$=".xlsx"]').each(function(){ $(this).addClass('xls'); });
	$('#main a[href$=".doc"], #main a[href$=".docx"]').each(function(){ $(this).addClass('doc'); });
	$('#main a[href$=".ppt"], #main a[href$=".pptx"]').each(function(){ $(this).addClass('ppt'); });
	$('#main a[href$=".pdf"]').each(function(){ $(this).addClass('pdf'); });

	// PAGETOP
	var pageUrl = location.href.split('#')[0];
	$('#wrapper a[href]').not('ul.tabs a[href]').not('.tabArea a[href]').each(function() {
	if (this.href.indexOf(pageUrl + '#') == 0) {
	    var id = this.href.split('#')[1];
	    $(this).click(function() {
	      var idLink = '#' + id;
		  $.scrollTo( idLink , {duration: 1000, axis:"y",easing:"easeOutQuart"});
	      return false;
	    });
	  }
	});
	
	// [TOP] Site Search input - JPN
	$('#u-navi #searchform #inputbox input').val("サイト内検索").css("color","#AAAAAA").one("focus",function(){
		$(this).val("").css("color","#333333");
	}).blur(function(){
		if($(this).val()==""){
			$(this).val("サイト内検索").css("color","#AAAAAA").one("focus",function(){ $(this).val("").css("color","#333333"); })
		}
	})
	
	// [TOP] Site Search input - ENG
	$('#u-navi #searchform-eng #inputbox input').val("Site Search").css("color","#AAAAAA").one("focus",function(){
		$(this).val("").css("color","#333333");
	}).blur(function(){
		if($(this).val()==""){
			$(this).val("Site Search").css("color","#AAAAAA").one("focus",function(){ $(this).val("").css("color","#333333"); })
		}
	})
	
	// [SUB] #s-navi
	$('#s-navi ul li:last-child').addClass('end');
	$('#s-navi ul ul:last').addClass('end');
	$('#s-navi2 ul li:last-child').addClass('end');
	$('#s-navi2 ul ul:last').addClass('end');
	$('#related ul li:last-child').addClass('end');

	// [top] .menulist
	$('#menulist li:nth-child(3n)').addClass('end');
	$('#menulist li:nth-child(3n+1)').addClass('clear');

	// [Category] .categorylist
	$('#categorylist li:nth-child(3n)').addClass('end');
	$('#categorylist li:nth-child(3n+1)').addClass('clear');
	
	// [Detail] .box
	$('.box').wrapInner("<span></span>");
	$('.box').css("padding","0");

	// [Detail] line
	$('.dotline-green02').wrapInner("<span></span>");
	$('.dotline02').wrapInner("<span></span>");
	
	// [toggle]
	$('.toggle > h2').hover(function(){
		$(this).css("cursor","pointer"); 
	},function(){
		$(this).css("cursor","default"); 
		});
	$('.toggle > .box').css("display","none");
	$('.toggle > h2').click(function(){
		$(this).next().slideToggle("fast");
		});

});

// [table] 行ごとに色分け
$(document).ready(function(){
  $("table.tr-gw").each(function(){
    jQuery(this).find("tr:even").addClass("even");
  });
});

// [POPUP] map
function open_map(html) {
	SubWindow=window.open(html,"open_map","width=560,height=710,left=50,top=50,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1");
	SubWindow.focus();
}
function open_map2(html) {
	SubWindow=window.open(html,"open_map2","width=500,height=600,left=50,top=50,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1");
	SubWindow.focus();
}
function open_privacy(html) {
	SubWindow=window.open(html,"open_privacy","width=750,height=600,left=50,top=50,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1");
	SubWindow.focus();
}

// [TABS]
$(document).ready(function() {
	
	// 初期設定
	var i = 1;

	$('div.tab_group').each(function(){
		var tb_i = 'tb-' + i;
		$(this).addClass(tb_i);

		tb_i = '.' + tb_i + ' ';

		//Default Action
		$(tb_i + ".tab_content").hide(); //Hide all content
		$(tb_i + "ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(tb_i + ".tab_content:first").show(); //Show first tab content
		
		//On Click Event
		$(tb_i + "ul.tabs li").click(function() {
			$(tb_i + "ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(tb_i + ".tab_content").hide(); //Hide all tab content
			var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active content
			return false;
		});
		i++;
	});
});
