// JavaScript Document

function ua(n){ return navigator.userAgent.indexOf(n)>=0; }
var browser_type = 0;
if(document.getElementById){
	browser_type = 1;
	if(ua("MSIE 7")||ua("MSIE 6")||ua("Firefox")||ua("Safari")||ua("Netscape/")||ua("Opera/9")) browser_type = 2;
	else if(ua("MSIE 5.5")||ua("Opera/8")) browser_type = 1.5;
	else if((ua("Mac") && ua("MSIE 5."))||ua("Opera 3")||ua("Opera 4")) browser_type = 0;
	else if( ua("MSIE 5.")||ua("Opera 5")||ua("Opera 6")||ua("Opera 7")||ua("Opera/7")) browser_type = 1;
	else if(ua("MSIE")||ua("Opera")) browser_type = 2;
};

function $btn(o,m) {
	var s = o.firstChild.src;
	var f = s.match(/-on.gif/i);
	if(!m && !f) o.firstChild.src = s.replace(/.gif/i,"-on.gif");
	if(m || f) o.firstChild.src = s.replace(/-on.gif/i,".gif");
};

function $btn_img(o,m) {//For Only IMG Swap (Set2007-11-8)
	var s = o.src;
	var f = s.match(/-on.gif/i);
	if(!m && !f) o.src = s.replace(/.gif/i,"-on.gif");
	if(m || f) o.src = s.replace(/-on.gif/i,".gif");
};

/* --------------------------- */
var g_Height = 500;
function getWinSize(){
	var d = document;
	if(ua("MSIE 6")||ua("MSIE 7")) var h = d.documentElement.clientHeight;
	else if(ua("MSIE")) var h = d.body.clientHeight;
	else var h = window.innerHeight;
	if(h > 260) var h = h - 260;
	g_Height = h;
	return h;
	//d.write('<style type="text/css" id="style-win">.AccordionPanelContent{height:'+ha+'px;}</style>');
};

function setWinSize(){
	var d = document;
	var h = getWinSize();
	d.write('<style type="text/css" id="style-win">.AccordionPanelContent{height:'+h+'px;}\n');
	if(ua("MSIE 6")){
		var smap_w = (d.documentElement.clientWidth)-47;
		var smap_h = h +186;
		d.write('#box-sitemap{height:'+smap_h+'px; width: ' + smap_w +'px; margin-top:-1px; }\n');
		d.write('#box-bg{height:'+(h+260)+'px;}\n');
	}
	document.write('.outline, .outline-open, .outline-left { height: '+ h +'px;}</style>');//for sub-Menu
};

var AcpDiv = new Array();
/*
window.onload = function() {
	var dv = document.getElementsByTagName("div");
	//getWinSize();
	for (var i=0; i<dv.length; i++){
		if(dv[i].className == "AccordionPanelContent") AcpDiv.push(dv[i]);
	}
	//initialize();
};
*/
var flag_ie_resize = "";
function for_ie_resize(){
	if(flag_ie_resize) clearTimeout(flag_ie_resize);
	flag_ie_resize = setTimeout("setWinResize()",300);/* bkp 400*/
};


$(window).resize(function(){
	if(ua("MSIE 6")||ua("MSIE 7")){
		//alert(getWinSize()+"--/// g_Height = "+g_Height);
		if(g_Height != getWinSize()) for_ie_resize();
	}else if(document.getElementById){
		setWinResize();
	}
});



/*
if(ua("MSIE 6")||ua("MSIE 7")){
	window.onresize = function() {
		for_ie_resize();
	}
}else if(document.getElementById){
	window.onresize = function() {
		setWinResize();
	}
}*/

function setWinResize(){
	var h = getWinSize();
	for (var i=0; i<AcpDiv.length; i++){
		if(AcpDiv[i].style.height != "0px"){
			AcpDiv[i].style.height = h+"px";
		}
	}
	acc1.fixedPanelHeight = h;
	g_Height = h;
	//apcHomeBody.MenuHeight();
	ApcAboutUs.MenuHeight();
	ApcWorks.MenuHeight();	
	// For IE 6
	if(ua("MSIE 6")){
		var smap_w = (document.documentElement.clientWidth)-31;
		var smap_h = h +186;
		$("#box-sitemap").css("height", smap_h+"px");
		$("#box-sitemap").width(smap_w);	
		$("#box-bg").height(h+260);
	}
	if($("#box-search").width() > 330) Search_Win_Risize();
}

setWinSize();// important

/*                  ------------------- var result = "";--------------*/

/*========= Search ------------*/
function Search_Win_Risize(){
	var t = g_Height + 190;
	t = t+"px";
	$("#box-search").css("margin-left", "0px");
	$("#box-search").css("margin-top", "0px");
	$("#box-search").css("top", "60px");
	$("#box-search").css("left", "15px");
	$("#box-search").css("right", "15px");
	$("#box-search").css("width", "auto");
	$("#box-search").css("height", t);
}

$(function(){
    // HTMLロード後に実行したい初期化コード
	var dv = document.getElementsByTagName("div");
	//getWinSize();
	for (var i=0; i<dv.length; i++){
		if(dv[i].className == "AccordionPanelContent") AcpDiv.push(dv[i]);
	}
	//initialize();
	//$("img.mouse-over").mouseover(function(){ $btn_img(this); });
	set_Btn_MouseOver();
});
