/*/////////////////////////////////////////////////////////////////////////////////////////////////
	User's Guide
	TOP Page Only
	Modified : 2013-03-25
/////////////////////////////////////////////////////////////////////////////////////////////////*/


//桁揃え --------------------------------------
function initAlign(n, digit) {
	var r = new String(n);
	var cnt = digit - r.length;
	if(cnt <= 0) return r;
	while (cnt-- > 0) r = "0" + r;
	return r;
}
// ---------------------------------------------



// 配列の重複削除  -----------------
function uniqueArray(array){
	var storage = {};
	var uniqueArray = [];
	var i,value;
	for( i=0; i<array.length; i++){
		value = array[i];
		if(!(value in storage)){
			storage[value] = true;
			uniqueArray.push(value);
		}
	}
	return uniqueArray;
}
// -----------------------------------





if(ua._isIE6){
	document.write('<script src="'+sharedPath+'/js/__top_ie6.js" type="text/javascript"></script>');
}else if(ua._isSafari1){// Safari 1
	document.write('<script src="'+sharedPath+'/js/__top_safari1.js" type="text/javascript"></script>');
}else if((ua._isSafari2)||(ua._isSafari3_0)){// Safari 2 & Safari 3.0 
	document.write('<script src="'+sharedPath+'/js/__top_safari2.js" type="text/javascript"></script>');
}else{
	document.write('<script src="'+sharedPath+'/js/__top_latest.js" type="text/javascript"></script>');
}

$(function(){
	
	//トップページ言語依存テキストをtextData.jsから読み込み配置 /////////////////////////////
			//$('title').text(textData.userGuide);
			$('div#title h1').text(textData.userGuide);
			$('div#search form label').text(textData.SearchTxt);
			$('div#search form input#searchSubmit').attr('value', textData.SearchTxt);
			$('div#toolNavi h3').text(textData.topToolNaviH3Txt);
			$('h4#navi10 span').attr('title', textData.topNavi10AttrTitleTxt).text(textData.topNavi10Txt);
			$('h4#navi15 span').attr('title', textData.topNavi15AttrTitleTxt).text(textData.topNavi15Txt);
			$('h4#navi11 span').attr('title', textData.topNavi11AttrTitleTxt).text(textData.topNavi11Txt);
			$('div#featuresNavi h2').text(textData.topFeaturesNaviH2Txt);
			$('h3#navi1').attr('title', textData.topNavi1AttrTitleTxt).children('a').text(textData.topNavi1Txt);
			$('h3#navi2').attr('title', textData.topNavi2AttrTitleTxt).children('a').text(textData.topNavi2Txt);
			$('h3#navi3').attr('title', textData.topNavi3AttrTitleTxt).children('a').text(textData.topNavi3Txt);
			$('h3#navi7').attr('title', textData.topNavi7AttrTitleTxt).children('a').text(textData.topNavi7Txt);
			$('h3#navi6').attr('title', textData.topNavi6AttrTitleTxt).children('a').text(textData.topNavi6Txt);
			$('h3#navi4').attr('title', textData.topNavi4AttrTitleTxt).children('a').text(textData.topNavi4Txt);
			$('h3#navi5').attr('title', textData.topNavi5AttrTitleTxt).children('a').text(textData.topNavi5Txt);
			$('h3#navi9').attr('title', textData.topNavi9AttrTitleTxt).children('a').text(textData.topNavi9Txt);
			$('div#chassisNavi h2').text(textData.topChassisNaviH2Txt);
			$('a#navi13').attr('title', textData.topNavi13AttrTitleTxt).text(textData.topNavi13Txt);
			$('a#navi12').attr('title', textData.topNavi12AttrTitleTxt).text(textData.topNavi12Txt);
			$('a#navi001').attr('title', textData.topNavi001AttrTitleTxt).text(textData.topNavi001Txt);
			$('a#navi8').attr('title', textData.topNavi8AttrTitleTxt).text(textData.topNavi8Txt);
			$('a#navi14').attr('title', textData.topNavi14AttrTitleTxt).text(textData.topNavi14Txt);
			$('div#usingNavi h2').text(textData.topUsingNaviH2Txt);
			$('a#navi002').attr('title', textData.topNavi002AttrTitleTxt).text(textData.topNavi002Txt);
			$('a#navi003').attr('title', textData.topNavi003AttrTitleTxt).text(textData.topNavi003Txt);
			$('a#navi004').attr('title', textData.topNavi004AttrTitleTxt).text(textData.topNavi004Txt);
			$('div#illustNavi h2').text(textData.topIllustNaviH2Txt);
			$('a#navi005').attr('title', textData.topNavi005AttrTitleTxt).text(textData.topNavi005Txt);
			$('a#navi006').attr('title', textData.topNavi006AttrTitleTxt).text(textData.topNavi006Txt);
			$('div#footer address span#copyright').text(textData.topCopyrightTxt);
			$('span#comMessage img').attr('alt', textData.topComMessageTxt).attr('title', textData.topComMessageTxt);




//検索窓 ----------------------------------------------------------------------------------
	if(!$('#searchKey').val()){
		$('#searchKey').val(textData.searchDefTxt);
	}
	$('#searchKey').after('<span id="searchBtn"></span>')
		.focus(function(){
			if($(this).val() == textData.searchDefTxt){
				$(this).val('').addClass("keyIn");
			}else{
				$(this).addClass("keyIn");
			}
		})
		.blur(function(){
			$('#searchKey').val($(this).val().replace(/^\s+/, '').replace(/\s+$/,'').replace(/[　\s]+/g,' '));
			if(!$(this).val()){
				$('#searchKey').val(textData.searchDefTxt).removeClass("keyIn");
			}
		}
	);
	
	$('#searchBtn').click(function(){ $('#search form').submit(); });
	$('#search form').submit(function(){
		var str = $('#searchKey').val();
		if((str==textData.searchDefTxt)||str==""){
			return false;
		}else{
			var searchAction = $('#search form').attr('action');
			searchAction = (!NotHTTP)? searchAction.replace(/\.htm.?$/,".php") : searchAction ;
			window.location =  searchAction+"?k="+encodeURIComponent($('#searchKey').val());
			return false;
		}
	});
//-----------------------------------------------------------------------------------------------------------------



//メニュー閉じ （表示外をクリックしたとき） ----------------------------------------------------------------------------------
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if(!$clicked.parents().is("#toolNavi")){
			$("#toolNavi .naviList").hide().removeClass("openList").removeShadow();
		}
	});
//-----------------------------------------------------------------------------------------------------------------






//メインナビ ----------------------------------------------------------------------------------
	$('#featuresNavi #featuresMain h3').hover(
		function(){ 
			$('#featuresNavi #featuresMain h3').removeClass('hover');
			$(this).addClass('hover'); 
		},
		function(){ $(this).removeClass('hover'); }
	);
//-----------------------------------------------------------------------------------------------------------------





// 多言語振り分け処理 -----------------------------------------------------------------------------
	function multiLangProcess(){
		if(init){
			var langPack, hitKey=[], indiLang=[], appImg=[];
			var loopCount = 200;
			var thisDir = document.location.pathname.replace(/file:\/\/+/i, "").replace(/\\/g, "/").split('/').slice(-2).join('').replace(/index\.html?.*$/, "");
			
			var re = new RegExp('(^|-)'+lang.substr(0,2)+'(-|$)','i');
			
			for(var key in init){
				if(re.test(key)){
					langPack = langPack||key;
				}
				for(var langObj in init[key]){
					appImg.push(init[key][langObj].dir);
				}
			}
			init = init[langPack];
			appImg = uniqueArray(appImg);
			for(var i in appImg){
				var src = '../' + appImg[i] + reqImage;
				var img = new Image();
				img.id = appImg[i];
				img.onload=function(){
					indiLang.push(this.id);
				};
				img.src = src;
			}
			
			var langlinkDisplay = function(){
				for(var key in init){
					var reg = new RegExp('(^| )'+key+'( |$)','i');
					if(init[key].dir == thisDir){
						hitKey.push(new Array(true, init[key].dir, init[key].txt));
					}else{
						if(reg.test(indiLang.join(' '))){
							hitKey.push(new Array(false, init[key].dir, init[key].txt));
						}
					}
				}
				hitKey = uniqueArray(hitKey);
				if(hitKey.length == 2){
					var langLink = [];
					for(var i in hitKey){
						if(hitKey[i][0]){
							langLink.push('<span class="active">'+ hitKey[i][2] +'</span>');
						}else{
							langLink.push('<span><a href="../'+hitKey[i][1]+'/index.html">'+hitKey[i][2]+'</a></span>');
						}
					}
					langLink = '<div id="lang">' + langLink.join(' | ') + '</div>';
				}else if(hitKey.length > 2){
					var langLink = '';
					for(var i in hitKey){
						var ck = (hitKey[i][0]) ? ' selected="selected"' : '' ;
						langLink += '<option value="'+hitKey[i][1]+'"'+ck+'>'+hitKey[i][2]+'</option>\n';
					}
					langLink = '<div id="lang"><select>'+ langLink +'</select></div>';
				}
				$('#header').prepend(langLink);
			
				$('#lang select').change(function(){
					location.href = '../'+ $("#lang select :selected").val() +'/index.html';
				});
			};
			
			var folderSearch = function(){
				if(indiLang[1]){
					langlinkDisplay();
				}else{
					if(loopCount>0){
						loopCount--;
						setTimeout(function(){ folderSearch(); }, 20);
					}
				}
			};
			folderSearch();
			
		}
	}
	$('body').append('<img src="../_.gif" id="mlJudg">');
	$('#mlJudg').load(function(){
		window.multiLangProcess = multiLangProcess;
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = "../_init.js";
		var head = document.getElementsByTagName('head')[0];
		head.appendChild(script);
		//setTimeout( multiLangProcess, 100);
		//$('#mlJudg').remove();
	}).error(function(){
		$('#mlJudg').remove();
	});
	/* add by a.baba 140227 start タブレット縦横表示切り換え時トップページのheightをリサイズ ///////*/
	if(ua._isMobile){
		$(window).on('resize scroll', function(){
			$("#documentBody").height($(window).height());
		});
	}
	/* add by a.baba 140227 end ////////////////////////////////////////////////////////////////////////////*/
//-----------------------------------------------------------------------------------------------------------------









});//($function()の終了





