function isMobile () {
	var useragents = [
		'iPhone',         // Apple iPhone
		'iPod',           // Apple iPod touch
		'Android',        // 1.5+ Android
		'dream',          // Pre 1.5 Android
		'CUPCAKE',        // 1.5+ Android
		'blackberry9500', // Storm
		'blackberry9530', // Storm
		'blackberry9520', // Storm v2
		'blackberry9550', // Storm v2
		'blackberry9800', // Torch
		'webOS',          // Palm Pre Experimental
		'incognito',      // Other iPhone browser
		'webmate'         // Other iPhone browser
	];
	var pattern = new RegExp(useragents.join('|'), 'i');
	return pattern.test(navigator.userAgent);
}

// 
{
	// CSS リンクを付加
	var link = document.createElement('link');
	link.rel = 'stylesheet';
	link.type = 'text/css';
	{
		reg = new RegExp("^http:", "ig");
		if (location.href.match(reg))
		{
			// オンラインの場合、PC または Mobile 用の CSS
			if (isMobile()) { link.href = '/VoS/mobile.css'; } else { link.href = '/VoS/pc.css'; }
		} else {
			// ローカル編集の場合
			link.href = 'file:///D:/ShellFolders/MyDocuments/HomePage/VoS/pc.css'
		}
	}
	document.getElementsByTagName('head')[0].appendChild(link);

	if (isMobile())
	{
		// ビューポートの設定
		var meta = document.createElement('meta');
		meta.name = 'viewport';
		meta.content = 'width=device-width, user-scalable=yes, initial-scale=0.6, minimum-scale=0.6, maximum-scale=1.6';
		document.getElementsByTagName('head')[0].appendChild(meta);
		
		// アイコン
		var link1 = document.createElement('link');
		link1.rel = 'shortcut icon';
		link1.href = 'http://smkymnky.com/VoS/favicon/favicon.ico'
		document.getElementsByTagName('head')[0].appendChild(link1);

		var link2 = document.createElement('link');
		link2.rel = 'apple-touch-icon-precomposed';
//		link2.rel = 'apple-touch-icon';
		link2.href = 'http://smkymnky.com/VoS/favicon/touch-icon.png'
		document.getElementsByTagName('head')[0].appendChild(link2);
	}
}


function toggleDivDisplay(divid) {
	if (document.getElementById(divid)){
		if(document.getElementById(divid).style.display == 'none'){
			document.getElementById(divid).style.display = 'block';
		}else{
			document.getElementById(divid).style.display = 'none';
		}
	}
}

function YouTubeMovie() {
	if (isDirectAccess() && !(isMobile())){
		document.write('<div style="padding: 60px 0px 60px 0px; background-color: #D0D0D0; text-align: center; line-height: 150%; font-size: 1em; color: #606060; font-weight: bold; width: 250px;">');
		document.write('トップページから閲覧すると<br /><br />ここに動画が表示されるかも</div>');
		return;
	}else{
		document.write('<div style="padding: 0px; margin: 0px; text-align: center; font-size: 0.7em; line-height: 150%;">');
		document.write('<object width= "' + YouTubeMovie.arguments[1] + '" height="' + YouTubeMovie.arguments[2] + '" allowScriptAccess="never" allowNetworking="internal">');
		document.write('<param name="movie" value="http://www.youtube-nocookie.com/v/' + YouTubeMovie.arguments[0] + '&autoplay=0&rel=0&fs=0&color1=0xd6d6d6&color2=0xf0f0f0&border=0&loop=0&iv_load_policy=3" />');
		document.write('<param name="allowScriptAccess" value="never" />');
		document.write('<param name="allowNetworking" value="internal" />');
		document.write('<embed src="http://www.youtube-nocookie.com/v/' + YouTubeMovie.arguments[0] + '&autoplay=0&rel=0&fs=0&color1=0xd6d6d6&color2=0xf0f0f0&border=0&loop=0&iv_load_policy=3" ');
		document.write('type="application/x-shockwave-flash" allowfullscreen="false" width="' + YouTubeMovie.arguments[1] + '" height="' + YouTubeMovie.arguments[2] + '" allowScriptAccess="never" allowNetworking="internal" />');
		document.write('</object>');

		document.write('<img src="/clear.gif" alt="" width="1" height="2"><br />');
		document.write('<a href="http://youtube.com/watch?v=' + YouTubeMovie.arguments[0] + '" class="movie" target="_blank">' + YouTubeMovie.arguments[3] + '</a><br />');
		document.write('</div>');
	}
}


function _YouTubeMovie() {
	if (isDirectAccess() && !(isMobile())){
		document.write('<div style="padding: 60px 0px 60px 0px; background-color: #D0D0D0; text-align: center; line-height: 150%; font-size: 1em; color: #606060; font-weight: bold; width: 250px;">');
		document.write('トップページから閲覧すると<br /><br />ここに動画が表示されるかも</div>');
		return;
	}else{
		document.write('<div style="padding: 0px; margin: 0px; text-align: center; font-size: 0.7em; line-height: 150%;">');
/*
 old ver
		document.write('<object data="http://www.youtube.com/v/' + YouTubeMovie.arguments[0] + '&rel=0&color1=0xd6d6d6&color2=0xf0f0f0&border=0" width="' + YouTubeMovie.arguments[1] + '" height="' + YouTubeMovie.arguments[2] + '" type="application/x-shockwave-flash" allowScriptAccess="never" allowNetworking="internal">');
		document.write('<param name="allowScriptAccess" value="never" />');
		document.write('<param name="allowNetworking" value="internal" />');
		document.write('<param name="movie" value="http://www.youtube.com/v/' + YouTubeMovie.arguments[0] + '&rel=0&color1=0xd6d6d6&color2=0xf0f0f0&border=0" />');
		document.write('</object></br />');
*/
		document.write('<object width= "' + YouTubeMovie.arguments[1] + '" height="' + YouTubeMovie.arguments[2] + '" allowScriptAccess="never" allowNetworking="internal">');
		document.write('<param name="movie" value="http://www.youtube.com/v/' + YouTubeMovie.arguments[0] + '&autoplay=0&rel=0&fs=0&color1=0xd6d6d6&color2=0xf0f0f0&border=0&loop=0&iv_load_policy=3" />');
		document.write('<param name="allowScriptAccess" value="never" />');
		document.write('<param name="allowNetworking" value="internal" />');
		document.write('<embed src="http://www.youtube.com/v/' + YouTubeMovie.arguments[0] + '&autoplay=0&rel=0&fs=0&color1=0xd6d6d6&color2=0xf0f0f0&border=0&loop=0&iv_load_policy=3" ');
		document.write('type="application/x-shockwave-flash" allowfullscreen="false" width="' + YouTubeMovie.arguments[1] + '" height="' + YouTubeMovie.arguments[2] + '" allowScriptAccess="never" allowNetworking="internal" />');
		document.write('</object>');
/*
iv_load_policy=1 annotations, 3 no annotations
*/

		document.write('<img src="/clear.gif" alt="" width="1" height="2"><br />');
		document.write('<a href="http://youtube.com/watch?v=' + YouTubeMovie.arguments[0] + '" class="movie" target="_blank">' + YouTubeMovie.arguments[3] + '</a><br />');
		document.write('</div>');
	}
}


function getWindowWidth() {
	if(window.innerWidth){
		return window.innerWidth;
	}else if(document.documentElement && document.documentElement.clientWidth){
		return document.documentElement.clientWidth;
	}else if ( document.body && document.body.clientWidth){
		return document.body.clientWidth;
	}
	return 0;
}

function getWindowHeight() {
	if (window.innerHeight){
		return window.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight != 0 ){
		return document.documentElement.clientHeight;
	}else if (document.body){
		return document.body.clientHeight;
	}
	return 0;
}
function getScrollWidth() {
	var docW, bdyW;
	docW = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : 0;
	bdyW = (document.body && document.body.scrollWidth) ? document.body.scrollWidth : 0;
	return Math.max(Math.max(docW, bdyW), getWindowWidth());
}

function getScrollHeight() {
	var docH, bdyH, retH;
	docH = (document.documentElement && document.documentElement.scrollHeight != 0 ) ? document.documentElement.scrollHeight : 0;
	bdyH = (document.body) ? document.body.scrollHeight : 0;
	return Math.max(Math.max(docH, bdyH), getWindowHeight());
}

function getScrollPosition() { 
	var obj = new Object(); 
	obj.left = document.body.scrollLeft || document.documentElement.scrollLeft;
	obj.top = document.body.scrollTop  || document.documentElement.scrollTop;
	return obj; 
}

function isDirectAccess() {
	reg = new RegExp("^http:", "ig");
	if (location.href.match(reg))	// オンラインの場合
	{
		reg = new RegExp(window.name, "ig");
		regRdir = new RegExp("^http://www.smkymnky.com/VoS/redirect/", "ig");
		if (top.name.match(reg) || top.location.href.match(regRdir))	// 自分が親ウィンドウの場合 or リダイレクト
		{
			return true;	// ダイレクトアクセスと判定
		}
	}
	return false;
}

function AccImg() {
	reg = new RegExp("^http:", "ig");
	if (location.href.match(reg))	// オンラインの場合
	{
		document.write("<img src='http://www.smkymnky.com/top/acc/acclog.cgi?");
//		document.write("referrer="+document.referrer+"&");
		document.write("referrer="+parent.document.referrer+"&");
		document.write("width="+screen.width+"&");
		document.write("height="+screen.height+"&");
		document.write("color="+screen.colorDepth+"'");
		document.write(" width='1' height='1'>");
	}
}

function links(){
	if (!isDirectAccess() || isMobile()){
		linkurl=links.arguments[1];
		document.write(linkurl.link(links.arguments[2] + links.arguments[0] + links.arguments[3]));
	}
}

function BGRank(eff, dif) {
	var nEff, nDif;
	isNaN(eff) ? nEff = 0 : nEff = eff * 10;
	isNaN(dif) ? nDif = 0 : nDif = dif * 10;
	switch(eff){
		case 0:
		case 0.5:
			eff = "ガ〜ン";
			break;
		case 1:
		case 1.5:
			eff = "アセ・・";
			break;
		case 2:
			eff = "う〜ん";
			break;
		case 2.5:
		case 3:
			eff = "ニヤリ";
			break;
		case 3.5:
		case 4:
			eff = "いひひ";
	}
	switch(dif){
		case 0:
		case 0.5:
			dif = "いひひ";
			break;
		case 1:
		case 1.5:
			dif = "ニヤリ";
			break;
		case 2:
			dif = "う〜ん";
			break;
		case 2.5:
		case 3:
			dif = "アセ・・";
			break;
		case 3.5:
		case 4:
			dif = "ガ〜ン";
	}
	document.write('<div class="bgrank">');
	document.write('<img src="../../rank_img/effectivness_' + nEff + '.gif" alt="効果度：' + eff + '">');
	document.write('<img src="../../clear.gif" alt="" width="200" height="1">');
	document.write('<img src="../../rank_img/difficulty_' + nDif + '.gif" alt="難易度：' + dif + '">');
	document.write('</div>');
}

