/*
* オトフレーム
* @auther  ---
* @version 0.9b, 2006.3.26
* @comment ---
*/

// フラッシュバージョンチェック用
var requiredMajorVersion = 6;// メジャーバージョン
var requiredMinorVersion = 0;//マイナーバージョン
var requiredRevision = 0;//リビジョン
// javascrptサポートバージョン
var jsVersion = 1.0;

var uagent=navigator.userAgent;
var flashVersion=0;
var ua = navigator.userAgent.toLowerCase(); 
var is_pc_ie  = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );
//init関数
function getURLs(){
	//マック_IEはジャケ写のみ対応(映像なし)20060315日現在
	if(uagent.indexOf("Mac") > -1){
		if(uagent.indexOf("MSIE") > -1 || uagent.indexOf("msie") > -1){
			changes();
			return;
		}
	}
	var doc_url_b="";
	var doc_url_c="";
	var doc_url_d="";
	var doc_hinban ="";
	var doc_url=document.URL.indexOf("?");
	if(doc_url > -1){
		doc_url_b=document.URL.substring(doc_url);
	}else{
		changes();
		return;
	}
	doc_url_b = doc_url_b.replace("?","");
	doc_url=doc_url_b.indexOf("&");
	if(doc_url > -1){
		doc_url_c = doc_url_b.substring(doc_url);
		doc_hinban = doc_url_b.substr(0,doc_url);
	}
	//引数があるかどうかを調べる。ない場合ジャケ写
	if(doc_url_c != "" && doc_url_c != undefined){
		doc_url_d  = doc_url_c.replace("&","");
	}else{
		changes();
		return;
	}
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	//リファラの取得
	var doc_ref =document.referrer;
	//checker.swfの起動
	var wmp_tag_ie="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='240' height='180 id='checker' align='middle'><param name='allowScriptAccess' value='always' /><param name='movie' value='/common2/aip/checker.swf' /><param name='wmode' value='transparent' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><PARAM NAME=FlashVars VALUE='ref="+doc_ref+"&ukey="+doc_url_d+"&aip_hinban_key="+doc_hinban+"'><embed src='/common2/aip/checker.swf'  FlashVars='ref="+doc_ref+"&ukey="+doc_url_d+"&aip_hinban_key="+doc_hinban+"' quality='high' bgcolor='#ffffff' width='240' height='180' name='checker' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	var wmp_tag_fox="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='1' height='1 id='checker' align='middle'><param name='allowScriptAccess' value='always' /><param name='movie' value='/common2/aip/checker.swf' /><param name='wmode' value='transparent' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><PARAM NAME=FlashVars VALUE='ref="+doc_ref+"&ukey="+doc_url_d+"&aip_hinban_key="+doc_hinban+"'><embed src='/common2/aip/checker.swf'  FlashVars='ref="+doc_ref+"&ukey="+doc_url_d+"&aip_hinban_key="+doc_hinban+"' quality='high' bgcolor='#ffffff' width='1' height='1' name='checker' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	var wmp_ctrl_tag="<table  align='left' width='242px' height=17px' border='0' cellpadding='0' cellspacing='0' background='/common2/aip/img/btn_bg.gif'><tr width='242px' height='2px'></tr><tr><td width='33px' height='13px'><img name='v_ctrl' alt='play'width='26px' height='13px' src='/common2/aip/img/btn_pause.gif' onClick='v_controller()'></td><td width='33px' height='13px'><img src='/common2/aip/img/btn_stop.gif' alt='stop' width='26px' height='13px' onClick=' video_stop()'></td><td  width='33px' height='13px'><img src='/common2/aip/img/btn_vol_on.gif' name='sound_ctrl'alt='sound' width='26px' height='13px' onClick='ctrl_snd()'></td><td  width='142px' height='13px' align='right'><a href=''><img src='/common2/aip/img/btn_otoframe.gif' alt='banner'width='67px' height='13px' border='0'></a></td></tr></table>";
	//?以下が空でなく、フラッシュの適切なバージョンが入っているときのみ動画表示(この次にリファラチェック)
	//リファラも空でないとき
	if(doc_url_d != "" && doc_ref !="" && doc_ref != undefined && hasReqestedVersion == true){
		if(navigator.userAgent.indexOf("Safari") != -1){
			wmp.innerHTML =wmp_tag_ie;
			wmp_ctrl.innerHTML =wmp_ctrl_tag;
		}else if(navigator.userAgent.indexOf("MSIE") != -1){
			document.all.wmp.innerHTML =wmp_tag_ie;
			document.all.wmp_ctrl.innerHTML =wmp_ctrl_tag;
		}else{
			if(apflg != 0){
				document.getElementById("wmp").innerHTML=wmp_tag_fox+ "<a href=\"#\" onclick=\"javascript:window.open('photo.html','','width=480,height=360,resizable=0,scrollbars=no');\"><img src=\"photo.jpg\" width=\"240px\" border=\"0\"></a>";
				document.getElementById("wmp_ctrl").innerHTML="<img src='/common2/aip/img/btn_bg.gif' width='242px' height=16px' border='0'>";
			}else{
				document.getElementById("wmp").innerHTML= wmp_tag_fox;
			}
		}
	}else{
		changes();
		return;
	}
}
function changes(){
	if(apflg != 0){
		if(navigator.userAgent.indexOf("Safari") != -1){
			wmp.innerHTML = "<a href=\"#\" onclick=\"javascript:window.open('photo.html','','width=480,height=360,resizable=0,scrollbars=no');\"><img src=\"photo.jpg\" width=\"240px\" border=\"0\"></a>";
			wmp_ctrl.innerHTML="<img src='/common2/aip/img/btn_bg.gif' width='242px' height=16px' border='0'>";
		}else if(navigator.userAgent.indexOf("MSIE") != -1){
			document.getElementById("wmp").innerHTML= "<a href=\"#\" onclick=\"javascript:window.open('photo.html','','width=480,height=360,resizable=0,scrollbars=no');\"><img src=\"photo.jpg\" width=\"240px\" border=\"0\"></a>";
			document.all.wmp_ctrl.innerHTML ="<img src='/common2/aip/img/btn_bg.gif' width='242px' height=16px' border='0'>";
		}else{
			document.getElementById("wmp").innerHTML= "<a href=\"#\" onclick=\"javascript:window.open('photo.html','','width=480,height=360,resizable=0,scrollbars=no');\"><img src=\"photo.jpg\" width=\"240px\" border=\"0\"></a>";
			document.getElementById("wmp_ctrl").innerHTML="<img src='/common2/aip/img/btn_bg.gif' width='242px' height=16px' border='0'>";
		}
	}
}

// Detect Client Browser type////三項演算子
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;//winIE
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;//ネスケ,winIE.opera
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;//opera
jsVersion = 1.1;

// JavaScript helper required to detect Flash Player PlugIn version information
//フラッシュバージョンチェッカー:返り値 バージョン
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	 // loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray = versionStr.split(" ");
				tempString = tempArray[1];
				versionArray = tempString.split(",");
			} else {
				versionArray = versionStr.split(".");
			}
			versionMajor = versionArray[0];
			versionMinor = versionArray[1];
			versionRevision = versionArray[2];

			versionString = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if (versionMajor == reqMajorVer) {
				if (versionMinor == reqMinorVer) {
					return (versionRevision >= reqRevision);
				} else {
					return (versionMinor > reqMinorVer);
				}
			} else {
				return (versionMajor > reqMajorVer);
			}
		}
	}
}

var v_onoff=false;
var snd_onoff=false
var v_url="";
var v_flag=false;

/*動画表示関数*/
var subWin;
function show_video(v_file,banner_path){
	//リンクの作成
	var oto_ref="";
	var a_flag = banner_path.substr(0,1);
	if(a_flag == "A"){
		var link_id = banner_path.substring(1);
		oto_ref = "http://otoframe.sonymusic.co.jp/ui/otoframe_a.html?"+link_id;
	}else{
		oto_ref = "http://otoframe.sonymusic.co.jp/ui/otoframe.html?"+banner_path;
	}
	if(navigator.userAgent.indexOf("Safari") != -1 || navigator.userAgent.indexOf("MSIE") != -1){
	wmp_ctrl.innerHTML ="<table  align='left' width='242px' height=17px' border='0' cellpadding='0' cellspacing='0' background='/common2/aip/img/btn_bg.gif'><tr><td width='33px' height='13px'><img name='v_ctrl' alt='play / pause' onmouseover=this.style.cursor='hand' onmouseout=this.style.cursor='auto' width='26px' height='13px' src='/common2/aip/img/btn_pause.gif' onClick='v_controller()' border='0'></td><td width='33px' height='13px'><img src='/common2/aip/img/btn_stop.gif' alt='stop' onmouseover=this.style.cursor='hand' onmouseout=this.style.cursor='auto' width='26px' height='13px' onClick=' video_stop()' border='0'></td><td  width='33px' height='13px'><img src='/common2/aip/img/btn_vol_on.gif' name='sound_ctrl' alt='sound on/off' onmouseover=this.style.cursor='hand' onmouseout=this.style.cursor='auto' width='26px' height='13px' onClick='ctrl_snd()' border='0'></td><td  width='142px' height='13px' align='right'><a href='"+oto_ref+"' target='_blank'><img src='/common2/aip/img/btn_otoframe.gif' alt='オトフレームを自分のブログに貼る' onmouseover=this.style.cursor='hand' onmouseout=this.style.cursor='auto' width='67px' height='13px' border='0'></a></td></tr></table>";
	wmp.innerHTML ="<object id='MediaPlayer1' width='240' height='180' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='URL' value='"+v_file+"'/><param name='ShowControls' value='false'/><param name='ShowControls' value='false'/><param name='InvokeURLs' value='true' /><param name='uiMode' value='none' /><param name='ShowPositionControls' value='false'/><param name='ShowAudioControls' value='false'/><param name='SendPlayStateChangeEvents' value='false'/><param name='ShowTracker' value='false'/><param name='AutoStart' value='true' /><param name='enableContextMenu' value='false' /><param name='enableErrorDialogs' vaue='false' /><param name='volume' value='50' /><param name='mute' value='false' /></object>";
	}else{
		subWin=window.open(v_file,"movie","width=1, height=1")
		setTimeout("closeWin()",0.5*1000); 
	}
	v_url=v_file;
}
//サブウインドウを自動的に閉じる
function closeWin(){
	if(!subWin.closed)subWin.close();
}


//動画操作関数

//終わったときの静止画きりかえ
function changeVtoPic(){
	if(v_flag == true){
		wmp.innerHTML = "<a href=\"#\" onclick=\"javascript:window.open('photo.html','','width=480,height=360,resizable=0,scrollbars=no');\"><img src=\"photo.jpg\" width=\"240px\" border=\"0\"></a>";
	}else if(v_flag == false){
		wmp.innerHTML ="<object id='MediaPlayer1' width='240' height='180' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='URL' value='"+v_url+"'/><param name='ShowControls' value='false'/><param name='ShowControls' value='false'/><param name='InvokeURLs' value='true' /><param name='uiMode' value='none' /><param name='ShowPositionControls' value='false'/><param name='ShowAudioControls' value='false'/><param name='SendPlayStateChangeEvents' value='false'/><param name='ShowTracker' value='false'/><param name='AutoStart' value='true' /><param name='enableContextMenu' value='false' /><param name='enableErrorDialogs' vaue='false' /><param name='volume' value='50' /><param name='mute' value='false' /></object>";
	}
};
//ビデオON OFFコントロール
function v_controller(){
	if(v_flag==true){
		v_flag=false;
		changeVtoPic();
		document.v_ctrl.src="/common2/aip/img/btn_pause.gif";
		v_onoff=false;
	}else{
		if(v_onoff == false){
			document.v_ctrl.src="/common2/aip/img/btn_play.gif";
			v_onoff=true;
			video_pause();
		}else{
			//document.all("wmp").style.visibility = "visible";
			document.v_ctrl.src="/common2/aip/img/btn_pause.gif";
			v_onoff=false;
			video_play();
		}
	}
}
//サウンドON OFFコントロール
function ctrl_snd(){
	if(v_flag==false){
		if(snd_onoff == false){
			snd_onoff=true;
			document.sound_ctrl.src="/common2/aip/img/btn_vol_off.gif";
			snd_stop();
		}else{
			snd_onoff=false;
			document.sound_ctrl.src="/common2/aip/img/btn_vol_on.gif";
			snd_play();
		}
	}
}
// #Video Clip Stop(停止)
function video_stop() {
	if(v_flag==false){
		v_onoff=true;
		 if(uagent.indexOf("MSIE",0)!=-1){
	 		document.MediaPlayer1.controls.Stop();
 		}else if(uagent.indexOf("Mozilla",0)!=-1){
 			document.MediaPlayer1.Stop();
		}else{
			document.MediaPlayer1.controls.Stop();
		}
	}
}
// #Video Clip Pause(一時停止)
function video_pause() {
	if (uagent.indexOf("MSIE") != -1) {
		document.MediaPlayer1.controls.Pause();
		return;
	} else if (uagent.indexOf("Mozilla") != -1) {
		document.MediaPlayer1.Pause();
		return;
	}
}
// #Video Clip Start(開始)
function video_play() {
	 if(uagent.indexOf("MSIE",0)!=-1){
	 	document.MediaPlayer1.controls.Play();
		 return;
 	}else if(uagent.indexOf("Mozilla",0)!=-1){
 		document.MediaPlayer1.Play();
		 return;
	}else{
		document.MediaPlayer1.controls.Play();
		return;
	}
}
// #Video Clip Volume Mute
function snd_stop() {
	if(uagent.indexOf("MSIE",0)!= -1) {
		document.MediaPlayer1.settings.volume = 0;
	} else if (uagent.indexOf("Mozilla",0) != -1) {
		document.MediaPlayer1.SetMute(false);
	}else{
		document.MediaPlayer1.settings.volume = 0;
	}
}
// #Video Clip Volume ON
function snd_play(){
	var changeVol=50; 
	if (uagent.indexOf("MSIE",0) != -1){
		document.MediaPlayer1.settings.volume = 50;
	} else if (uagent.indexOf("Mozilla",0) != -1) {
		var nnVol = (1000 - (changeVol * 10)) * (-1);
		document.MediaPlayer1.SetVolume(nnVol);
	}else{
		document.MediaPlayer1.settings.volume = 50;
	}
}
// #Get video Mute Status
function getMuteStatus(){
	var tmp;
	if (UserType.indexOf("ie") != -1) {
		tmp = mediaObj.settings.mute;
	} else if (UserType.indexOf("nn") != -1) {
		tmp = mediaObj.GetMute();
	}
	return (tmp);
}
