﻿var playerpath = "http://ultra-zone.net/file/player.swf"; //JW FLV MEDIA PLAYER のパス
var logopath = "http://ultra-zone.net/file/video_logo.png"; //ビデオ右上に表示されるロゴのパス
var volume = 50; //音量
var autostart = false; //自動で再生開始

function mediaplayer(filename,caption,width,height){

	//背景の表示
	var s1 = document.createElement("div");
	s1.setAttribute("id", "mpback");
	s1.style.cssText = "position:absolute;left:0;margin:0;padding:0;width:100%;height:100%;z-index:100;background:#000;border:none;filter:alpha(opacity=80);opacity:.8;";
	document.body.appendChild(s1);

	//メデイアの表示
	var s2 = document.createElement("div");
	s2.setAttribute("id", "mpbody");
	if(navigator.userAgent.indexOf("MSIE")!=-1) s2.setAttribute("onclick",new Function("mpclose()"));
	else                                        s2.setAttribute("onclick","mpclose()");
	s2.style.cssText = "position:absolute;left:0;margin:0;padding:0;width:100%;height:100%;z-index:101;color:#ccc;border:none;font-size:12px;line-height:32px;";
	document.body.appendChild(s2);

	//クレジットの表示
/*	var s3 = document.createElement("a");
	s3.setAttribute("id", "mpcredit");
	s3.setAttribute("href", "http://ultra-zone.net/t003");
	s3.setAttribute("target", "_blank");
	s3.style.cssText = "position:absolute;right:8px;z-index:101;color:#888;font-family:Arial;font-size:10px;line-height:12px;text-decoration:none;";
	document.body.appendChild(s3);
	s3.appendChild(document.createTextNode("POWERED BY ultra-zone.net"));
*/
	//ファイル形式の判別
	switch(filename.substr(filename.lastIndexOf(".") + 1)){
		//静止画
		case "jpg": case "jpeg": case "gif": case "png": case "bmp": case "JPG": case "JPEG": case "GIF": case "PNG": case "BMP":
			var m1 = document.createElement("img");
			m1.setAttribute("id", "mpimg");
			if(navigator.userAgent.indexOf("MSIE")!=-1) m1.setAttribute("onload",new Function("adjustImgSize();"));
			else                                        m1.setAttribute("onload","adjustImgSize();");
			m1.setAttribute("src", filename);
			break;
		//動画
		case "flv": case "mp4": case "FLV": case "MP4":
			var m1 = document.createElement("embed");
			m1.setAttribute("src", playerpath);
			m1.setAttribute("allowscriptaccess", "always");
			m1.setAttribute("width", width ? width : 512 );
			m1.setAttribute("height", height ? height : 384 );
			m1.setAttribute("bgcolor","#000000");
			m1.setAttribute("flashvars", "&logo=" + logopath + "&controlbar=over&volume=" + volume + "&autostart=" + autostart + "&file=" + filename);
			break;
		//音声
		case "mp3": case "aac": case "MP3": case "AAC":
			var m1 = document.createElement("embed");
			m1.setAttribute("src", playerpath);
			m1.setAttribute("allowscriptaccess", "always");
			m1.setAttribute("width", 480);
			m1.setAttribute("height", 20);
			m1.setAttribute("bgcolor","#000000");
			m1.setAttribute("flashvars", "&backcolor=cccccc&volume=" + volume + "&autostart=" + autostart + "&file=" + filename);
			break;
		//未対応の形式
		default:
			var m1 = document.createElement("div");
			m1.appendChild(document.createTextNode("EROOR: 未対応のファイル形式です。"));
		}
		s2.appendChild(m1);

	//キャプションの表示
	var d1 = document.createElement("div");
	d1.setAttribute("id", "mpcaption");
	d1.style.cssText = "border:none;";
	s2.appendChild(d1);
	d1.appendChild(document.createTextNode( caption ? caption : "" ));

	//位置調整
	if(document.getElementById("mpimg"))
		adjustImgSize();
	else
		s2.style.padding = (document.body.clientHeight - m1.offsetHeight - d1.offsetHeight)/2 + "px 0 0 0";
	document.getElementById("mpback").style.top = document.body.scrollTop;
	document.getElementById("mpbody").style.top = document.body.scrollTop;
	//document.getElementById("mpcredit").style.top = document.body.scrollTop + document.body.clientHeight - 16;
}

//静止画のサイズ調整
function adjustImgSize(){
	mi = document.getElementById("mpimg");
	mc = document.getElementById("mpcaption");
	mb = document.getElementById("mpbody");
	dbch = document.body.clientHeight;
	dbcw = document.body.clientWidth;
	try{
		if( (mi.height + mc.offsetHeight) > dbch){
			mi.width *= (dbch - mc.offsetHeight) / mi.height;
			mi.height = dbch - mc.offsetHeight;
		}
		if(mi.width > dbcw){
			mi.height *= dbcw / mi.width;
			mi.width = dbcw;
		}
		mb.style.padding = (document.body.clientHeight - mi.offsetHeight - mc.offsetHeight)/2 + "px 0 0 0";
	}catch(e){};
}

//クローズ
function mpclose(){
	document.getElementById("mpbody").innerHTML = "";
	//document.body.removeChild(document.getElementById("mpcredit"));
	document.body.removeChild(document.getElementById("mpbody"));
	document.body.removeChild(document.getElementById("mpback"));
}
