//ポップアップ制御（ファイル名、幅、高さ）
function wOpen(theURL,wWidth,wHeight,sb) {

	//ウィンドウ設定
	var settings = "status=yes,scrollbars=yes,menubar=yes,resizable=yes,toolbar=yes,location=yes,directory=yes,width=200";
	
	if (sb){
		settings +=',scrollbars=no'
	}else{
		settings +=',scrollbars=yes'
	}

	if(!wWidth&&!wHeight){
		//target="_blank"と同等
		window.open(theURL,'',settings);
		return false;
	}else if(wWidth&&!wHeight){
		//幅のみ指定
		window.open(theURL,'',''+settings+'');
		return false;
	}else if(!wWidth&&wHeight){
		//高さのみ指定
		settings += 'height=' + wHeight +'' 
		window.open(theURL,'',''+settings+'');
		return false;
	}else{
		//幅・高さ指定
		window.open(theURL,'',''+settings+',width='+wWidth+',height='+wHeight+'');
		return false;
	}
}

var nowPos;
var nowPosSrc;
var nowFlag;
var nowPage;
//マウスアクション制御
function mAction(mPos,mAct){
	if(mPos.firstChild.getAttribute("src")){
		var i = mPos.firstChild.src;
		if(mAct){
			//マウスオーバー
			mPos.firstChild.src = i.replace("_off","_on");
			//オーバーしたボタンがグローバルメニューの時、ローカルメニューを表示
			if (mPos.firstChild.className == 'imgover') {
				//マウスオーバー表示になったままのボタンを、アウト画像に変える
				if (mPos != nowPos && nowPos != undefined && nowPos != nowPage){
					nowPos.firstChild.src = nowPosSrc.replace("_on","_off");
				}
				nowPos = mPos;
				nowPosSrc = i;
				var n = mPos.id.charAt( mPos.id.length - 1 );
				mopen(n);
			}	
		}else{
			//アウトしたボタンがグローバルメニューの時、ローカルメニューを非表示
			if (mPos.firstChild.className == 'imgover' && mPos.id != "gnavi0") {
				mclosetime();
			}else{
				//マウスアウト
				mPos.firstChild.src = i.replace("_on","_off");
			}
		}
	}
}

//第2階層のプルダウンメニュー
var TimeOut         = 200;
var currentLayer    = null;
var currentitem     = null;
var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

//グローバルメニュー・サブメニューでそれぞれボックスNo.を取得
function mopen(n){
	var l = document.getElementById("lnavi"+n);
	var g = document.getElementById("gnavi"+n);

//オンマウスでプルダウン表示
	if(l){
		mcancelclosetime();
		l.style.visibility='visible';
		if(currentLayer && (currentLayerNum != n))
			currentLayer.style.visibility='hidden';
			currentLayer = l;
			currentitem = g;
			currentLayerNum = n;
	} else if(currentLayer) {
		currentLayer.style.visibility='hidden';
		currentLayerNum = 0;
		currentitem = null;
		currentLayer = null;
	}
}

//オンリリースで非表示に戻す
function mclosetime() {
	closeTimer = window.setTimeout(mclose, TimeOut);
}

function mcancelclosetime() {
	if(closeTimer) {
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}

function mclose() {
	if(currentLayer && noClose!=1) {
		currentLayer.style.visibility='hidden';
		currentLayerNum = 0;
		currentLayer = null;
		currentitem = null;
	} else {
		noClose = 0;
	}
	currentLayer = null;
	currentitem = null;
	if(nowPos != nowPage && nowPos.id != "gnavi0") nowPos.firstChild.src = nowPosSrc.replace("_on","_off");
}


//デフォルト文字列の消去
function kwdComment(obj){
	if(obj.value == obj.defaultValue){
		obj.value = "";
	}
}

function check_keyword() {
	if(document.keywordSearch.keyword.value == "キーワードを検索..."){
		document.keywordSearch.keyword.value = "";
	}
}


//ActiveX対策
function dispSWF(fName,fWidth,fHeight){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+fWidth+'" height="'+fHeight+'" align="middle" id="FortuneTelling">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+ fName +'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#FFFFFF" />');
	document.write('<embed src="'+ fName +'" quality="high" bgcolor="#FFFFFF" width="'+fWidth+'" height="'+fHeight+'" name="FortuneTelling" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}


//グローバルナビゲーションの設定

var url = document.URL;
var myMenu = [ "http://www.gundam.info/" , "topic/"   , "/content"   , "channel.or.jp/" ];
var gId =    [ "HomeNavi"                           , "TopicsNavi" , "ContentsNavi" , "ProductNavi" ]
	
function globalNaviChange(){
	for (var m = 0; m <myMenu.length; m++) {
		if (m == 0 ){
			if ( myMenu[m] == url || myMenu[m] + "index.html" == url){
				vageta(m);
				break;
			}
		}else if (url.match(myMenu[m])) {
			vageta(m);
			break;
		}else{
			var gClass = getElementsByClass("globalNavigation");
			gClass[0].id = "OtherNavi";
		}
	}
}
window.onload = globalNaviChange;

function vageta(m){
	var gClass = getElementsByClass("globalNavigation");
	gClass[0].id = gId[m];

	var gnaviId = document.getElementById("gnavi" + m);
	var str = gnaviId.firstChild.src;
	gnaviId.firstChild.src = str.replace("_off" , "_on");
	nowPos = gnaviId;
	nowPosSrc = nowPos.firstChild.src;
	nowPage = nowPos;

	//gnaviId.onmouseover =function() { mopen(m); }
	if (m==0) gnaviId.onmouseover =function() { return }
	gnaviId.onmouseout =function() { mclosetime(); }
}


//クラス取得関数
function getElementsByClass(searchClass) {
	if (document.all) {
		var classElements = new Array();
		var allElements = document.all;
		for (i = 0, j = 0; i < allElements.length; i++) {
			if (allElements[i].className == searchClass) {
				classElements[j] = allElements[i];
				j++;
			}
		}
	} else if (document.getElementsByTagName) {
		var classElements = new Array();
		var allElements = document.getElementsByTagName("*");

		for (i = 0, j = 0; i < allElements.length; i++) {
			if (allElements[i].className == searchClass) {
				classElements[j] = allElements[i];
				j++;
			}
		}
	} else {
		return;
	}
	return classElements;
}


//グローバルメニューのためのOS判別
function getOSType(){
	var agent = navigator.userAgent.toUpperCase();

	if(agent.indexOf("MAC") > 0) {
		document.write ("<link rel='stylesheet' href='http://www.gundam.info/css/mac.css' type='text/css'>");
	} else {
		return;
	}
}

