/*
 * 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:  2008-08-05 by TA
 *
 * jQuery 1.1.2
 * Interface 1.2 (Effects scroll)
 */

/* 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(){
		
	// class="btn"はロールオーバーを設定（src属性を_on付きのものに差し替える）
	$('.btn').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);
	});
	
	// フッターコピーライト西暦自動表示
	$(".copyright a").before($thisYear);
	
	//PDF,Word,Exelファイルを別ウィンドウで表示
	$("a[@href^='http://'],a[@href^='https://']").each(function(){
		var $ThisLink = $(this).attr('href');
		var $SearchResult1 = $ThisLink.indexOf("http://www.seg.co.jp/",0);
		var $SearchResult2 = $ThisLink.indexOf("http://www0.seg.co.jp/",0);
			if($SearchResult1 < 0 && $SearchResult2 < 0 ){
				$(this).addClass('window');
				$(this).attr("target", "_blank");
			}
	})

	//PDF,Word,Exelファイルを別ウィンドウで表示
	$("a[@href$='.pdf'], a[@href$='.ppt'], a[@href$='.doc'], a[@href$='.xls'], a[@href$='.jpg'], a[@href$='.gif'], a[@href$='.zip'], a[@href$='.xml'], a[@href$='.txt']").each(function(){
				$(this).attr("target", "_blank" );
				$(this).removeClass('window');
	})

	// ファイルの種類により、Class追加
	$("a[@href$='.pdf']").addClass('pdf'); //pdf
	$("a[@href$='.xls']").addClass('excel'); //excel
	$("a[@href$='.doc']").addClass('word'); //word
	$("a[@href$='.ppt']").addClass('ppt'); //ppt

	// Classを追加しない
	$(".icon-no a[@href$='.pdf']").removeClass('pdf'); //pdf
	$(".icon-no a[@href$='.xls']").removeClass('excel'); //excel
	$(".icon-no a[@href$='.doc']").removeClass('word'); //word
	$(".icon-no a[@href$='.ppt']").removeClass('ppt'); //ppt
	$(".icon-no a[@href^='http://'],.icon-no a[@href^='https://']").removeClass('window'); //window

	// ページ内リンクはするするアニメーション(interface.js利用)
	var pageUrl = location.href.split('#')[0];
	$("#footer a[@href],#sub-contents a[@href],#side a[@href]").each(function() {
	  if (this.href.indexOf(pageUrl + '#') == 0) {
		var id = this.href.split('#')[1];
		$(this).click(function() {
		  $('#' + id).ScrollTo('slow');
		  return false;
		});
	  }
	});

});

// 【よくある質問】=========================================

$(function(){
	
	// ---------------------- menu -----------------------
	// 初期設定
	$('li.switch > ul').hide(); //switchを非表示:
	$('li.switch > p > a').before("<span><img src='/img/icon_plus.gif' alt='' width='20' height='20' /></span>"); //btn設置
	$('li.switch > p > em').before("<span><img src='/img/icon_plus.gif' alt='' width='20' height='20' /></span>"); //btn設置
	
	var $i = 1;
	var $j = 1;
	var $k = 1;
	//中身：<ul>タグにclass="set-●"を追加
	$('li.switch > ul').each(function(){
		$(this).addClass('set-' + $i);
		$i++;
	});
	//リンク：<span>タグにclass="set-●"を追加
	$('li.switch span').each(function(){
		$(this).addClass('set-' + $j);
		$j++;
	});
	//画像：<img>タグにclass="set-●"を追加
	$('li.switch > p > span > img').each(function(){
		$(this).addClass('set-' + $k);
		$k++;
	});

	// CLICKしたときの処理
	$('li.switch span').toggle(
		function(){
			var $imgClass = $(this).attr('class');
			$('li.switch > ul.' + $imgClass).slideDown(200); // OPEN
			$('li.switch > p span > img.' + $imgClass).attr('src','/img/icon_minus.gif'); // btn書き換え
			return false;
		},
		function(){
			var $imgClass = $(this).attr("class");
			$('li.switch > ul.' + $imgClass).slideUp(200); // CLOSE
			$('li.switch > p span > img.' + $imgClass).attr('src','/img/icon_plus.gif'); // btn書き換え
			return false;
		}
	);


	// ---------------------- challenge-タブ -----------------------
	// 初期設定
	var $i = 1;
	var $j = 1;
	var $k = 1;
	// タブ：<li>タグに"tb-●"を追加
	$('.tab-challenge > li a').each(function(){
		$(this).addClass('tb-' + $i);
		$i++;
	});
	// リンク：<a>タグに"tb-●"を追加
	$('.tab-challenge > li img').each(function(){
		$(this).addClass('tb-' + $j);
		$j++;
	});
	// 内容：<div>タグに"id=tb-●"を追加
	$('div.tab-inner').each(function(){
		$(this).addClass('tb-' + $k);
		$k++;
	});
	
	// 初期設定
	$('div.tab-inner').hide(); /* 内容を消す */
	$('div.tb-1').show(); /* 内容【1】を表示 */
	$('.tab-challenge > li > a > img.tb-1').attr('src','/img/btn_challenge_on.gif'); // btn書き換え

	// Click時の処理
	$('.tab-challenge > li a').click(function(){
		$('.tab-challenge > li a:first-child').removeClass('firstChild'); /* 無駄なクラス削除 */
		$('.tab-challenge > li a:last-child').removeClass('lastChild'); /* 無駄なクラス削除 */
		var $tabClass = $(this).attr('class');
		$('.tab-challenge > li > a > img.tb-1').attr('src','/img/btn_challenge.gif'); // btn書き換え
		$('.tab-challenge > li > a > img.tb-2').attr('src','/img/btn_ryoppi.gif'); // btn書き換え

		var $imgSrc = 1;
		var $tabSrc = 1;
		
		$imgSrc = $('.tab-challenge > li > a > img.' + $tabClass).attr('src');
		$tabSrc = $imgSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		
		$('.tab-challenge > li > a > img.' + $tabClass).attr('src',$tabSrc);// btn書き換え

		$('div.tab-inner').hide(); /* 内容を消す */
		$('div.' + $tabClass).show(); /* ONの内容を表示 */
		return false;
	});
	
	// TAB指定OPENの設定
	var myPm = location.href.split("?")[1];
	switch (myPm) {
		case "id=02":
			$('.tab-challenge > li > a > img.tb-1').attr('src','/img/btn_challenge.gif'); /* ON画像タブをOFFに切り替え */
			$('.tab-challenge > li > a > img.tb-2').attr('src','/img/btn_ryoppi_on.gif'); // btn書き換え
			$('div.tb-1').hide(); /* 内容【1】を消す */
			$('div.tb-2').show(); /* ONの内容を表示 */
			break;
	}

	// ---------------------- 開閉用 -----------------------
	var $i = 1;
	var $j = 1;
	// リンク：<dt><span>タグにclass="toggle-●"を追加
	$(".toggle h3").each(function(){
		$(this).addClass("toggle-" + $i);
		$(this).css({"font-weight":"bold","text-decoration":"underline","cursor":"pointer"});
		$i++;
	});
	// 中身：<dd>タグにclass="toggle-●"を追加
	$(".toggle .answer").each(function(){
		$(this).css("display","none");
		$(this).addClass("toggle-" + $j);
		$j++;
	});
	// Hover時の処理
	$(".toggle h3").hover(
		function(){
			$(this).css({"font-weight":"bold","text-decoration":"none","cursor":"pointer"});
		},
		function(){
			$(this).css({"font-weight":"bold","text-decoration":"underline","cursor":"pointer"});
		}
	);
	// Click時の処理
	$(".toggle h3").toggle(
		function(){
			var $SetClass = $(this).attr("class");
			$(".toggle .answer." + $SetClass).show();
		},
		function(){
			var $SetClass = $(this).attr("class");
			$(".toggle .answer." + $SetClass).hide();
		});
});


(function() {
	var f = document.getElementById('cse-search-box');
	if (!f) {
		f = document.getElementById('searchbox_demo');
	} 
})();
