/*
 * yuga.js 0.4.2 - 優雅な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-09-11
 *
 * jQuery 1.2.1
 * ThickBox 3.1
 * Interface 1.2 (Effects scroll)
 */

/* yuga.js内で使っているfunction群 */
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){
			if (!path.match(/^(mailto:)|(javascript:)/)) {
				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 fields = {'schema' : 2, 'username' : 5, 'password' : 6, 'host' : 7, 'path' : 9, 'query' : 10, 'fragment' : 11};
		var r = /^((\w+):)?(\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(this.absolutePath);
		for (var field in fields) {
			this[field] = r[fields[field]]; 
		}
	}
};


$(function(){
	
	//class="imgLink"でロールオーバーを設定（src属性を_over付きのものに差し替える）
	$('.imgLink img, img.imgLink,#gNavi li img,.bnr img,.rss img,.pageTop img,#guideNav img,.list_btn img,.btn img,.btn input,.service_navi li img,.sampleBtn img').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_over$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});

	//現在のページへのリンク
	$('a[@href]').each(function(){
		var href = new yuga.URI(this.getAttribute('href'));
		if (href.isSelfLink && !href.fragment) {
			$(this).addClass('active');
		}
	});
	

	$('body.indexBody li.topNavi img,body.newsBody #gNavi li.newsNavi img,body.infoBody #gNavi li.infoNavi img,body.contactBody #gNavi li.contactNavi img,body.serviceBody #gNavi li.serviceNavi img,body.publishingBody #gNavi li.publishingNavi img,body.map #guideNav li.sitemapNavi img,body.help #guideNav li.helpNavi img,body.policy #guideNav li.policyNavi img,body.faq #guideNav li.faqNavi img').each(function(){
		this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_over$1");
		$(this).attr('src',this.currentSrc)
			.hover(function(){
				$(this).attr('src',this.currentSrc);
			},function(){
				$(this).attr('src',this.currentSrc);
			});
	});


	//ページ内リンクはするするアニメーション(interface.js利用)
	$(function(){
		$('.pageTop a').click(function(){
			$('#pageTop').ScrollTo(600, 'easeout');
			return false;
		});
	})

	//画像へ直リンクするとthickboxで表示(thickbox.js利用)

	try {
		tb_init('a[@href$=".jpg"], a[@href$=".gif"], a[@href$=".png"]');
	} catch(e) {
	}	


	//奇数、偶数を自動追加
/*
	$('div#main').each(function(){
		$(this).find('div.item:odd').addClass('even');
		$(this).find('div.item:even').addClass('odd');
	});

	$('.recruitmentSubject table').each(function(){
		$(this).find('tr:odd').addClass('odd');
		$(this).find('tr:even').addClass('even');
	});
*/
	
});


//入力フィールドをクリックするとデフォルトのテキストが消える
var isInitialized = false; function initialize(object) {
	if(!isInitialized) {
		object.value = "";
		object.style.color = "#333"; isInitialized = true;
	}
}

	//外部リンクは別ウインドウを設定
$(document).ready( function () {
	$('a[@href^="http://"]').not('[@href^="http://www.zaikyo.or.jp/"]').click(function(){
	window.open(this.href, '');
	return false;
	});
	$('a[@href^="http://"]').not('[@href^="http://www.zaikyo.or.jp/"]').addClass("exLink");
	$('body.newsBody div.entry_body a[@href^="http://"]').not('[@href^="http://www.zaikyo.or.jp/"]').after(" <img src='/img/share/icon_exlink.gif' alt='別ウィンドウ表示' />");

	$('a[@href~="/bookshop/"]').click(function(){
	window.open(this.href, '');
	return false;
	});
	$('a[@href~="/bookshop/"]').addClass("exLink");
	$('p.btn a[@href^="/bookshop/"]').removeClass("exLink");
	$('body.newsBody div.entry_body a, body.indexBody dl.book_list.newly dt a').removeClass("exLink");
	$('body.newsBody div.entry_body a[@href~="/bookshop/"], body.indexBody dl.book_list.newly dt a').after(" <img src='/img/share/icon_exlink.gif' alt='別ウィンドウ表示' style='vertical-align: bottom;' />");

});

//フッターの最初の要素にクラス追加
$(function(){
	$('#footer p + ul, #footer ul li:first-child').addClass("first");
});

//各種CSS　IE6対策

$(document).ready(function(){
	$('.item_inner h2 + h3').css('margin-top','0');
	$('.publishingBody dl.book_list dt:first-child').css('background','none');
	$('.fontsize_change + p').css('margin','0');
});

$(function(){
	$('h2 + .rss,h3 + .rss,h4 + .rss').css({
		background : "url(/img/index/bg_rss.gif) no-repeat",
		width : "160px",
		height : "30px",
		padding : "5px 5px 0 0",
		position : "absolute",
		right : "10px",
		top : "5px"
	});
	$('.indexBody div.newly .rss').css({
		background : "url(/img/index/bg_rss_02.gif) no-repeat",
		right : "5px"
	});
	$('.bookList .item_inner .newly .rss').css('top','25px');

});


$(function(){
    //pdfのあとにアイコンつけるやつ
	$('a[@href$=".pdf"]').after(" <img src='/img/share/icon_pdf.gif' alt='PDFアイコン' />");

    // 電子ブックを別ウィンドウで開く
    $('a.ebook').click(function(e){
        e.preventDefault();
        var url = $(this).attr('href');
        url = url + '_SWF_Window.html';
        window.open(url, '_blank', 'width=1000, height=670');
    });

    //出たり消えたりするすごい子
    $('.related_article .newsBody,.faq_list dd').css("display","none");	//消したい要素
    $('.related_article h4,.faq_list dt').click(function() {	//押すと表示
    	$(this).next('.newsBody,dd').slideToggle("fast");
    });
    /*-------------
      $('.related_article div').click(function() {
        $(this).css("display","none");	//押すと消える
      });
    -------------*/
});

$(function(){
	$('.related_article h4 span,.faq_list dt span').css({
		color:"#1e6ccc",
		textDecoration : "underline"
	});
	$('.related_article h4 span,.faq_list dt span').hover(function(){
		$(this).css({
		cursor : "pointer",
		background : "#fffcc1",
		color:"#474a4e",
		textDecoration : "underline"
	});
	}
	,function(){
		$(this).css({
		background : "#ffffff",
		color:"#1e6ccc",
		textDecoration : "underline"
	});
	});
});


//タブ

// jQuery_Auto 0.9
// Automatic functions for webpages (using the wonderful jQuery library)

// Copyright: (c) 2006, Michal Tatarynowicz (tatarynowicz@gmail.com)
// Licenced as Public Domain (http://creativecommons.org/licenses/publicdomain/)
// $Id: jquery_auto.js 426 2006-05-06 19:54:39Z Michaﾅ・$

// customize: Takashi Hirasawa (http://css-happylife.com/)

// Initialization

$.auto = {
	init: function() {
		for (module in $.auto) {
			if ($.auto[module].init)
				$.auto[module].init();
		}
	}
};

$(document).ready($.auto.init);

// Switches tabs on click

$.auto.tabs = {

	init: function() {

		$('.service_inner').each(function(){
			var f = $.auto.tabs.click;
			var group = this;
			$('.service_navi li, li.service_navi', group).each(function(){
				this.group = group;
				$(this).click(f);
				$('#'+this.id+'_list').hide();
			}).filter(':first').trigger('click');
		});

	},

	click: function() {
		var tab = $('#'+this.id+'_list').get(0);
		$('.service_navi li, li.service_navi', this.group).each(function(){
			$(this).removeClass('active');
			$('#'+this.id+'_list').hide();
		});

		$(this).addClass('active');
		$(tab).show();
		this.blur();

		return false;
	}

};

$(function(){
	$('.service_navi li.active img').each(function(){
		this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_over$1");
		$(this).attr('src',this.currentSrc)
			.hover(function(){
				$(this).attr('src',this.currentSrc);
			},function(){
				$(this).attr('src',this.currentSrc);
			});
		});
});



/*--------------------------------------------------------------------------*
 *  
 *  heightLine JavaScript Library beta4
 *  
 *  MIT-style license. 
 *  
 *  2007 Kazuma Nishihata 
 *  http://www.webcreativepark.net
 *  
 *--------------------------------------------------------------------------*/
new function(){
	
	function heightLine(){
	
		this.className="hL";
		this.parentClassName="back_number"
		reg = new RegExp(this.className+"-([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/\s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}
		
		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		
		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",heightLine);
}

