﻿/**
 * fullscreen.js
 * @usage
 * start("./pekepeke.html");
 */

var errorMessage = "本コンテンツをご覧いただくには 1024 × 768 ピクセル以上のモニター解像度が必要です。\n\n申し訳ございませんが、モニター解像度の設定をご確認ください。";

function checkScreenSize(w, h)
{
	var sw = screen.availWidth;
	var sh = screen.availHeight;
	
	return (sw >= w && sh >= h);
}

function varidate(w, h)
{
	var isOK = checkScreenSize(w, h);
	
	if(!isOK)
		alert(errorMessage);
	
	return isOK;
}

function start(url)
{
	if(!varidate(924, 633))	//1024 * 768 の場合
		return;
	
	var appver = navigator.appVersion;
	var appname = navigator.appName;
	var ua = navigator.userAgent;
	
	var fullWindow;
	
	if(appver.indexOf("Win") >= 0)
	{
		// Windows OS
		
		if (appname.indexOf("Microsoft") >= 0)
		{
			// IE
			if (appname == "Microsoft Internet Explorer" && parseInt(appver) >= 4)
			{
				// over v4
				var intpos = appver.indexOf("MSIE", 0);
				if (parseInt(appver.slice(intpos+5, intpos+6))>=6)
				{
					openFullScreenWinIE(url);
				}
				else
				{
					fullWindow = window.open("" ,"full","fullscreen=1,width=" + (screen.availWidth+3) + ",height=" + (screen.availHeight+1) + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
					fullWindow.resizeTo(Math.ceil(screen.availWidth+3),Math.ceil(screen.availHeight+1));
					fullWindow.moveTo  (0,0);
					fullWindow.document.open("text/html", "replace");
					fullWindow.document.write("<html><style type='text/css'>\n");
					fullWindow.document.write("body{ border: 1px solid #000000; overflow: hidden; margin: 0pt;}");
					fullWindow.document.write("#stillloadingDiv{ position: absolute; left: 0px; top: 0px; width: 100%px; height: 19px; z-index: 1; background-color: #C0C0C0; layer-background-color: #C0C0C0; clip:rect(0,100%,19,0);}");
					fullWindow.document.write("</style>\n");
					fullWindow.document.write("<body onload=\"top.document.location.replace('" + url + "')\" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0 scroll='no'>");
					fullWindow.document.write("<div ID='stillloadingDiv'></div>");
					fullWindow.document.write("</body></html>");
					fullWindow.document.close();
					
					fullWindow.focus();
				}
			}
			else
			{
				// under v4
				fullWindow = window.open(strURI,"full","width=" + (screen.availWidth+1) + ",height=" + (screen.availHeight-21) + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,left=0,top=0,screenX=0,screenY=0",true);
			}
		}
		else
		{
			// Others (Firefox, Safari, Chrome, Netscape, Opera, ...)
			openFullScreen(url);
		}
	}
	else if(appver.indexOf("Mac") >= 0)
	{
		// Mac OS
		
		/*
		if (appname.indexOf("Netscape") >= 0 && ua.indexOf("Chrome") >= 0)
		{
			// Chrome
			openFullScreenChrome(url);
		}
		else
		{
		*/
			openFullScreen(url);
		//}
	}
	else
	{
		// Other OS (Linux, ...)
		
		openFullScreen(url);
	}
}

function openFullScreen(url)
{
	var fullWindow;
	fullWindow = window.open("",
						"full",
						"scrollbars=0,resizable=0,width=" + screen.availWidth +",height=" + screen.availHeight +",top=0,left=0");
	fullWindow.moveBy(0, 0);
	fullWindow.location.href = url;
}

function openFullScreenWinIE(url)
{
	var fullWindow;
	fullWindow = window.open(url,
						"full",
						"width=" + (screen.availWidth-4) + ",height=" + (screen.availHeight+1) + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
}
