// 音声ガイドON/OFFのフラグ。
talk_flag = 'ON';

// :::::::::::::::::::::::: //
// ::: クッキー読み込み ::: //
// :::::::::::::::::::::::: //
function readCookie(){

	// クッキー読み込み
	var cookieData = document.cookie + ";"; //文字列の最後に「;」を追加
	name = "talk_flag=";
	start = cookieData.indexOf(name);   　// キーワードを検索
	end = cookieData.indexOf(";", start);    // 情報の末尾位置を検索
	talk_flag = unescape(cookieData.substring(start + name.length, end));  // データ取り出し

	// 読み込んだtalk_flagによって表示するボタンを変更
	if(talk_flag == 'OFF'){
			document.getElementById('btn_off').style.display = "block";
	}else{
			document.getElementById('btn_on').style.display = "block";
			talk_flag = 'ON';
	}
}


// :::::::::::::::::::::::: //
// ::: クッキー書き込み ::: //
// :::::::::::::::::::::::: //
function writeCookie(flag){
	document.cookie = "talk_flag=" + flag + ";expires=Tue, 1-Jan-2030 00:00:00 GMT;"
}




//
// MPCompの立ち上げ
//
function loadSWF(name,speech)
{
	// ここを変えてください。
	//
	// Resize Flash here.
	//
	var size_x = 200;
	var size_y = 200;
	
	var off_x;
	var off_y;

	var so = new SWFObject(name, "mpcomp", size_x, size_y, "9", "#ffffff");
	
	//if(size_x>=size_y)
	//{
	//	off_x = 0;
	//	off_y = 0;
	//}
	//else
	//{
	//	off_x = 0;
	//	off_y = 0;
	//}
	
	off_x = 0.0;
	off_y = 0.0;
	
	
	
	
	//so.addParam("salign", "tl" );
	//so.addParam("salign", "m" );
	so.addParam("align", "middle" );
	
	// fixed model apspect ratio.
	// no display for outof the area size_x*size_y.
	so.addParam("scale", "noborder" );
	//so.addParam("scale", "noscale" );
	
	so.addParam("quality", "high");
	so.addParam("allowscriptaccess","always");
	so.addParam("allowfullscreen","false");
	
	// 引数 dataPath : 顔データへのパス
	so.addVariable("dataPath","MPViewer/facedata/FaceData.swf");
	// 引数 backGroundFile : 背景画像へのパス。指定が無ければ背景は描かない。
	so.addVariable("backGroundFile", "MPViewer/bg.jpg");
	
	
	
	// ここを変えてください。
	off_x += 0.0;
	off_y += -0.8;
	
	// MP variables
	so.addVariable("positionX", off_x );
	// MP variables
	so.addVariable("positionY", off_y );
	
	
	
	// ここを変えてください
	// MP variables
	so.addVariable("scale", 1.2 );
	
	so.write("flashcontent");

}


//
// MPCompの id を取得
//
function getSWF(name)
{
	if(navigator.appName.indexOf("Microsoft")!=-1){
		return window[name];
	}else{
		return document[name];
	}
}











//
// SWFから叩かれる関数
// stopボタンではなく、スピーチが最後まで終了したときに"mpcomp"から起動される関数
//
function onLipsyncComplete()
{
	//window.alert("unjarage");
	
	// スピーチが最後まで終わったらマウスを追尾するようになる
	// MP control
	getSWF("mpcomp").startTraceMouse();
	// MP control
	getSWF("mpcomp").stopLookForward();
}













function stopSpeech()
{
	getSWF("mpcomp").stopSpeech();
}

function startSpeech(talk)
{

	if(talk_flag == 'ON'){
		speech = 'MPViewer/sounds/'+talk+'.mp3';
		getSWF("mpcomp").realtimeLipsync(speech);
	}
}


// :::::::::::::::::::::: //
// ::: 音声ON/OFF制御 ::: //
// :::::::::::::::::::::: //

var talk_flag = 'ON';

// 音声ガイドのON/OFF制御
function flgTalk(value){

	if(value == 'ON'){

		talk_flag = 'ON';
		// ON/OFFボタンの表示制御
		document.getElementById('btn_on').style.display = "block";
		document.getElementById('btn_off').style.display = "none";
		writeCookie('ON');

	}else if(value == 'OFF'){

		stopSpeech();
		talk_flag = 'OFF';
		// ON/OFFボタンの表示制御
		document.getElementById('btn_on').style.display = "none";
		document.getElementById('btn_off').style.display = "block";
		writeCookie('OFF');

	}
}


// :::::::::::::::::::::::::::::::::: //
// ::: キャラクタースクロール用JS ::: //
// :::::::::::::::::::::::::::::::::: //

// 初期変数設定
offY = 0;
posY = offY;

// スクロール
function floatMenu(){

	sy = document.body.scrollTop  || document.documentElement.scrollTop;
	document.getElementById('inquiry_mp').style.top = posY + "px";
	movY = sy-posY+offY;
	cY = movY/2;
	posY += cY;

}
