﻿/*
 * 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
	$('#banner a 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.actio.co.jp/",0);
		var $SearchResult2 = $(this).attr('href').indexOf("https://www.actio.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.actio.co.jp/",0);
			var $SearchResult2 = $(this).attr('href').indexOf("https://www.actio.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;
	    });
	  }
	});
	
	// [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');

	// [toggle]
	$('.toggle > h2').hover(function(){
		$(this).css("cursor","pointer"); 
	},function(){
		$(this).css("cursor","default"); 
		});
	$('.toggle > .box01').css("display","none");
	$('.toggle > p').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=700,height=600,left=50,top=50,toolbar=1,location=1,status=1,menubar=1,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++;
	});
	
	// Hover時の処理
	$('.toggle h2').hover(
		function(){
			$("span",this).css({"color":"#df2b2f","text-decoration":"none","cursor":"pointer"});
		},
		function(){
			$("span",this).css({"color":"#000000","text-decoration":"underline","cursor":"pointer"});
		}
	);

});

function main_over(num) {
  $("#result-img img").attr({src:"img/main-img2_"+num+".jpg"});
}
function main_out() {
  $("#result-img img").attr({src:"img/main-img2.jpg"});
}

//$(document).ready(function(){ 
//$('#result-btn,#result-img').hover(function(){
//$('#result-btn').stop().animate({'bottom' : '211px'}, 500);
//$('#result-img').stop().animate({'top' : '0px'}, 500);
//}, function(){$('#result-btn').stop().animate({'left' : '20px', 'bottom' : '0px'}, 500);
//$('#result-img').stop().animate({'left' : '0px', 'top' : '211px'}, 500);});
//});


$(document).ready(function(){
	var resultFlag = 0;
	$('.img-z-index').mouseover(function(){
		resultFlag = 1;
		$('.img-z-index').stop().animate({'bottom' : '211px'}, 500);
		$('#result-img').stop().animate({'top' : '0px'}, 500);
	});
	$('#main-img').hover(function(){
		if (resultFlag == 1) {
			$('.img-z-index').stop().animate({'bottom' : '211px'}, 500);
			$('#result-img').stop().animate({'top' : '0px'}, 500);
		}
	}, function(){
		resultFlag = 0;
		$('.img-z-index').stop().animate({'left' : '20px', 'bottom' : '0px'}, 500);
		$('#result-img').stop().animate({'left' : '0px', 'top' : '211px'}, 500);
	});
});
