/**
 *	@filename		lib.js
 *	@charset		utf-8
 *	@created		Augst 21, 2009
 *	@lastmodified	Augst 21, 2009
 *	@description	共通js
 */
(function(){



//
//	スクロール用
//
var moveObject = function(){
	var y = document.body.scrollTop || document.documentElement.scrollTop;
	var target = Math.max(Math.floor(y - (y / 8)));
	scrollTo(0, target);
	if(target > 0){
		setTimeout(moveObject,10);
	}
};



//
//	IE用objectタグ関係
//
var removeData = function(obj){
	var data = obj.getAttribute("data");
	if(data){
		obj.removeAttribute("data");
	}
};



//
//	リンクの点線を消す
//
var disableLinkOutline = function() {
	$(document.links).each(function(){
		$(this).focus(function(){
			this.blur();
		});
	});
};



////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	DOM読み込み完了後に実行
//
////////////////////////////////////////////////////////////////////////////////////////////////////
$(function(){
		   
//
//	フォントサイズ可変
//
//
//	フォントサイズ変更用
//

/*----- ボタン挿入 -----*/
/*
var header = new blades.DOM();
header = header.addElements("div.inner", "#header").get(0);
header.innerHTML = header.innerHTML + [
	'<ol id="fontSize">',
		'<li id="fontSizeNavSmall"><a href="#" title="文字サイズを「小」にする">小</a></li>',
		'<li id="fontSizeNavMedium"><a href="#" title="文字サイズを「中」にする">中</a></li>',
		'<li id="fontSizeNavLarge"><a href="#" title="文字サイズを「大」にする">大</a></li>',
	'</ol>',
	'<form name="fSiteSearch" id="fSiteSearch">',
		'<p id="siteSearch">',
			'<input type="text" id="fQuery" name="q" value="サイト内検索" />',
			'<input type="hidden" name="test" value="testimony" />',
			'<a href="', (new blades.Script("lib.js")).getSrc().getLocation().replace("/js/common", ""), 'search/index.html', '" id="buttonSearch" title="検索">検索</a>',
		'</p>',
	'</form>'
].join("");
header = null;
*/

if($("body#fcilitiesItem").length==0){

	var fSize = new blades.FontSize({path:"/"},["#wrapper","#copyright"]);
	var buttonS = new blades.DOM($("#fontSizeS a").get(0));
	var buttonM = new blades.DOM($("#fontSizeM a").get(0));
	var buttonL = new blades.DOM($("#fontSizeL a").get(0));
	
	switch(fSize.getSize()){
		case "90":
			buttonS.addClass("selected");
			break;
		case "100":
			buttonM.addClass("selected");
			break;
		case "130":
			buttonL.addClass("selected");
			break;
		default:
			fSize.setSize("100");
			buttonM.addClass("selected");
	}
		
	buttonS.addListener("click", function(){
		fSize.setSize("90");
		//buttonS.addClass("selected");
		buttonM.removeClass("selected");
		buttonL.removeClass("selected");
		(new blades.DOM(this)).addClass("selected");
		return false;
	});
	buttonM.addListener("click", function(){
		fSize.setSize("100");
		buttonS.removeClass("selected");
		buttonM.addClass("selected");
		buttonL.removeClass("selected");
		return false;
	})
	buttonL.addListener("click", function(){
		fSize.setSize("130");
		buttonS.removeClass("selected");
		buttonM.removeClass("selected");
		buttonL.addClass("selected");
		return false;
	});
}


//
//	このページの先頭へボタン動作
//
$(".anchorTop a").click(function(){
	moveObject();
	return false;
});
$("#anchorTop a").click(function(){
	moveObject();
	return false;
});


//
//	リンクの点線を消す
//
disableLinkOutline();



//
//	ポップアップリンク用
//
$(".popup").click(function(){
	var url = this.href;
	if(url){
		var win = window.open(url);
		win.focus();
	}
	return false;
});


//
//	閉じるボタン
//
$(".btnClose a").click(function(){
	window.close();
	return false;
});


//
//	別ウィンドウリンク
//
var win = null;
var width = null;
var height = null;

$("a.popupWindow").click(function(){
							
	var href = $(this).attr("href");
	var url = href.split("#")[0];
	var q = href.split("#")[1].split("&");
	var params = new Array();
	
	for(var i = 0; i != q.length; i++) {
		params[q[i].split('=')[0]]
			  =  q[i].split('=')[1];
	}
	
	//Win1ウィンドウが無い場合
	if(win==null||win.closed==true){
		if(params["width"]&&params["height"]){
			width = params["width"];
			height = params["height"];
			win = window.open(url,"Win1","location='0',status=0,menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height+"\"");
		}else{
			width = null;
			height = null;
			win = window.open(url);
		}
	}
	//Win1ウィンドウが在る場合
	else{
		//新規ウィンドウのwidth とheight が同じ場合はlocationだけ変更
		if(!width && !height && !(params["width"]&&params["height"])){
			win.location = url;
		}else if((width == params["width"])&&(height == params["height"])){
			win.location = url;
		}
		//そうでない場合はwinを閉じて、Win1ウィンドウが無い場合と同じ処理
		else{
			win.close();
			if(params["width"]&&params["height"]){
				width = params["width"];
				height = params["height"];
				win = window.open(url,"Win1","location='0',status=0,menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height+"\"");
			}else{
				width = null;
				height = null;
				win = window.open(url);
			}
		}
	}
	
	win.focus();
	return false;
});


//
//	トップページFlash埋め込み用
//
if($("p#flashBanner").length!=0){
	if(swfobject.getFlashPlayerVersion().major < 9){
		$("p#flashBanner").css({"display":"block"});
	}else{
		var img_path = $("p#flashBanner img").attr("src");
		var swf_file = img_path.replace(/^(.*)?\.(jpg|gif|png)$/i,"$1.swf");
		swfobject.embedSWF(swf_file,"flashBanner","898","282","9.0.0",null,
				   {},
				   {allowScriptAcces:"sameDomain",allowFullScreen:"false",quality:"high",bgcolor:"#ffffff",menu:"false"},
				   {} );
	}
}


//
//	#categoryTitleの内部にpを挿入
//
$("#categoryTitle").wrapInner("<p></p>");

//
//	ul.pickUpList liのうち、３の倍数番目のliにclass="by3"を付与する
//
$("ul.pickUpList li").each(function(){
	if((parseInt($("ul.pickUpList li").index(this))+1)%3==0){
		$(this).addClass("by3");
	}
});
	
//
//	ul.pickUpList liの高さを揃える
//
if($("ul.pickUpList").length!=0){
	ajustPickUpListHeight();
	
	var prevHeight = $("body").height();
	
	setInterval(ajustPickUpListHeight,100);
	
	$(window).unload(function(){
		clearInterval(ajustPickUpListHeight);
	});
	
}

function ajustPickUpListHeight(){
	curHeight = $("body").height();
	
	if(curHeight != prevHeight){
		$("ul.pickUpList li").each(function(){
			if(parseInt($("ul.pickUpList li").index(this))%3==0){
				var next = $(this).next();
				var next2 = next.next();
				
				$("p.caption span",this).height("auto");
				$("p.caption span",next).height("auto");
				$("p.caption span",next2).height("auto");
				
				var height1 = $("p.caption span",this).height();
				var height2 = $("p.caption span",next).height();
				var height3 = $("p.caption span",next2).height();
				
				var maxHeight = function(){
					if(height1 > height2){
						if(height1 > height3){
							return height1;	
						}else{
							return height3;	
						}
					}else{
						if(height2 > height3){
							return height2;
						}else{
							return height3;
						}
					}
				}();
				
				var b = jQuery.browser;
				var v = jQuery.browser.version;
				var padding = function(){
					if(b.msie&&v=="6.0"){
						return 0;
					}else if(b.msie&&v=="8.0"){
						return 0;
					}else{
						return 0;
					}
				}();
				
				$("p.caption span",this).height(maxHeight - padding);
				$("p.caption span",next).height(maxHeight - padding);
				$("p.caption span",next2).height(maxHeight - padding);
		   }
		});
	}
	prevHeight = curHeight;
}

//
//	リンクの高さを揃える
//
if($("body#link").length!=0){
	ajustLinkListHeight();
	
	var prevHeight = $("body").height();
	
	setInterval(ajustLinkListHeight,100);
	
	$(window).unload(function(){
		clearInterval(ajustLinkListHeight);
	});
	
}

function ajustLinkListHeight(){
	curHeight = $("body").height();
	
	if(curHeight != prevHeight){
		$("div#sectionLink ul li:even").each(function(){
			
			var next = $(this).next();
			
			$(this).height("auto");
			$(next).height("auto");
			
			var height1 = $(this).height();
			var height2 = $(next).height();
			
			var maxHeight = function(){
				if(height1 > height2){
					return height1;	
				}else{
					return height2;	
				}
			}();
			
			var b = jQuery.browser;
			var v = jQuery.browser.version;
			var padding = function(){
				if(b.msie&&v=="6.0"){
					return -41;
				}else if(b.msie&&v=="8.0"){
					return 0;
				}else{
					return 0;
				}
			}();
			
			$(this).height(maxHeight - padding);
			$(next).height(maxHeight - padding);
		   
		});
	}
	prevHeight = curHeight;
}

//
//	Google検索ボックス
//

//
//	検索ウィンドウブラー効果
//
var defaultKeyword = "キーワードを入力";
$("input.searchWindow").focus(function(){
	$(this).addClass("focused");
	if($(this).attr("value")==defaultKeyword){
		$(this).attr("value","");
	}
});
$("input.searchWindow").blur(function(){
	$(this).removeClass("focused");
	if($(this).attr("value")==""){
		$(this).attr("value",defaultKeyword);
	}
});


$("p.searchBtn a").click(function(){
	//
	//	ドメインを設定
	//
	var searchDomains = "http://www.daito-japan.co.jp/";
	$("#fSiteSearch input#domains").attr("value",searchDomains);
	$("#fSiteSearch p input:checked").attr("value",searchDomains);
	
	if($("input.searchWindow").attr("value")!=defaultKeyword){
		
	}else{
		$("input.searchWindow").attr("value","");
	}
	$("#fSiteSearch").submit();
});

});
////////////////////////////////////////////////////////////////////////////////////////////////////



})();