//=========================================
//	JavaScriptとの通信チェック
//=========================================
function JavaScriptAviable() {
	return true;
}

//=========================================
//	URLの取得
//=========================================
function GetURL() {
	return location.href;
}

//=========================================
//	アンカー移動
//=========================================
function SetLocationHash(_name) {
	location.hash = _name;
}

//=========================================
//	エレメント座標の設定
//=========================================
function SetElementPos(_name, _x, _y) {
	document.getElementById(_name).style.left = _x+'px';
	document.getElementById(_name).style.top  = _y+'px';
}

//=========================================
//	マウスホイール対策
//=========================================
if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', evtMouseWheel, false);
window.onmousewheel = document.onmousewheel = evtMouseWheel;
function evtMouseWheel(_evt) {
	var delta = 0;
	if (!_evt)						// for IE.
		_evt = window.event;
	if (_evt.wheelDelta) {			// IE/Opera.
		delta = _evt.wheelDelta/120;
		if (window.opera)
			delta = -delta;
	} else if (_evt.detail) {		// Mozilla case.
		delta = -_evt.detail/3;
	}
	if (delta) {
		if (navigator.appName.indexOf('Microsoft') != -1)
			window.externalswf.asMouseWheel(delta);
		else
			document.externalswf.asMouseWheel(delta);
	}
}

//=========================================
//	Flashが見れない端末のページ遷移
//=========================================
window.onload = function () {
	if (document.getElementById('noswf')) {
		if (noFlashURL) {
			location.replace(noFlashURL);
		}
	}
	document.body.style.backgroundColor = flashBGColor;
}

//=========================================
//
//	ニコ動外部プレイヤ
//
//=========================================
var divNicoFrame;
var divNicoBg;
var divNicoClose;
var nicodouWidth = 0;
var nicodouHeight = 0;
function NicodouSetup(_frameColor, _w, _h) {

	// 明示的に指定しなかった場合のデフォルト値
	if (_frameColor == undefined)
		_frameColor = '#ffffff';
	if (_w == undefined)
		_w = 701;
	if (_h == undefined)
		_h = 411;

	// レイヤーの作成(最初だけ)
	if (divNicoFrame == undefined) {

		// 枠線
		divNicoFrame = document.createElement('div');
		divNicoFrame.style.overflow = 'hidden';
		divNicoFrame.style.position = 'fixed';
		document.body.appendChild(divNicoFrame);

		// 内側
		divNicoBg = document.createElement('div');
		divNicoBg.style.position = 'absolute';
		divNicoBg.style.overflow = 'hidden';
		divNicoBg.style.left = '1px';
		divNicoBg.style.top  = '1px';
		divNicoBg.style.backgroundColor = '#000000';
		divNicoFrame.appendChild(divNicoBg);

		// CLOSE
		imgNicoClose = document.createElement('img');
		imgNicoClose.src = 'script/swfcontrol/nico-close-text.png';

		aNicoClose = document.createElement('a');
		aNicoClose.href = 'javascript:ClickedNicoClose()';
		aNicoClose.appendChild(imgNicoClose);
		
		divNicoClose = document.createElement('div');
		divNicoClose.style.overflow = 'hidden';
		divNicoClose.style.position = 'fixed';
		divNicoClose.style.width  = '70px';
		divNicoClose.style.height = '20px';
		divNicoClose.appendChild(aNicoClose);

		document.body.appendChild(divNicoClose);

		divNicoFrame.style.display = 'none';
		divNicoClose.style.display = 'none';
	}

	nicodouWidth  = _w+2;
	nicodouHeight = _h+2;

	divNicoFrame.style.width  = (_w+2)+'px';
	divNicoFrame.style.height = (_h+2)+'px';
	divNicoFrame.style.backgroundColor = _frameColor;
	divNicoBg.style.width  = _w+'px';
	divNicoBg.style.height = _h+'px';
	divNicoClose.style.backgroundColor = _frameColor;

	NicodouSetPos(-nicodouWidth-100, 0);
}

function ClickedNicoClose() {
	if (navigator.appName.indexOf("Microsoft") != -1)
		window.externalswf.asNicoClose();
	else
		document.externalswf.asNicoClose();
}

function NicodouSetPos(_x, _y) {
	_x = Math.ceil(_x-1);
	_y = Math.ceil(_y-1);
	divNicoFrame.style.left = _x+'px';
	divNicoFrame.style.top  = _y+'px';
	divNicoClose.style.left = (_x+nicodouWidth-70)+'px';
	divNicoClose.style.top  = (_y-20)+'px';
}

var jsLoad;
function cb_nicodou(_player) {
	divNicoBg.innerHTML = _player.getHTML();
}
function NicodouLoad(_id) {
	divNicoFrame.style.display = 'block';
	divNicoBg.innerHTML = '';
	if (jsLoad != undefined)
		document.body.removeChild(jsLoad);
	jsLoad = document.createElement('script');
	jsLoad.type = 'text/javascript';
	jsLoad.src = 'http://ext.nicovideo.jp/thumb_watch/'+_id+'?w='+nicodouWidth+'&h='+nicodouHeight+'&n=1&tr=1&cb=cb_nicodou';
	document.body.appendChild(jsLoad);
}

function NicodouHide() {
	divNicoFrame.style.display = 'none';
	divNicoBg.innerHTML = '';
	if (jsLoad != undefined) {
		document.body.removeChild(jsLoad);
		jsLoad = undefined;
	}
}

function NicodouShowClose(_flag) {
	divNicoClose.style.display = _flag ? 'block' : 'none';
}

