
MIN_WIDTH = 940;
MIN_HEIGHT = 580;


//-------------------
function BrowserInfo(userAgent) {

	/*****************************************
	 * Geckoエンジンバージョンチェッカー
	 * (返値 int 合致しない場合は-1)
	 *****************************************/
	this.geckoVersionChecker = function(){
		var num = this.ua.match(new RegExp("Gecko/20[0-9]{6}"));
		return ( num == null ) ? -1 : parseInt(String(num).replace("Gecko/",""));
	}

	/*****************************************
	 * WebKitバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.webkitVersionChecker = function(){
		var num = this.ua.match(new RegExp("WebKit/[0-9]{1,4}(\.[0-9]{1,2})?"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Firefox/",""));
	}

	/*****************************************
	 * IEバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.ieVersionChecker = function(){
		var ienum = this.ua.match(new RegExp("MSIE [0-9]{1,2}\.[0-9]{1,3}"));
		return ( ienum == null ) ? -1 : parseFloat(String(ienum).replace("MSIE ",""));
	}
	

	/*****************************************
	 * Firefoxバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.firefoxVersionChecker = function(){
		var num = this.ua.match(new RegExp("Firefox/[0-9]{1,2}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Firefox/",""));
	}

	/*****************************************
	 * Operaバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.operaVersionChecker = function(){
		var num = this.ua.match(new RegExp("Opera[/ ][0-9]{1,2}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).substr(6));
	}

	/*****************************************
	 * Safariバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.safariVersionChecker = function(){
		var num = this.ua.match(new RegExp("Safari/[0-9]{1,4}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Safari/",""));
	}

	/*****************************************
	 * Netscapeバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.netscapeVersionChecker = function(){
		var num = this.ua.match(new RegExp("Netscape[0-9]?/[0-9]{1,2}\.[0-9]{1,3}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace(new RegExp("Netscape[0-9]?/"),""));
	}

	/*****************************************
	 * Mozillaバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.mozillaVersionChecker = function(){
		var num = this.ua.match(new RegExp("Mozilla/[0-9]{1,2}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Mozilla/",""));
	}
	// -- コンストラクタ --

	this.ua = (userAgent) ? userAgent : navigator.userAgent;

	this.geckoVersion = this.geckoVersionChecker();
	this.gecko = (this.geckoVersion > 0 );

	this.webkitVersion = this.webkitVersionChecker();
	this.webkit = (this.webkitVersion > 0 );

	this.ieVersion = this.ieVersionChecker();
	this.ieMVersion = Math.floor(this.ieVersion);
	this.isIE = ( this.ieVersion >= 3 );
	this.macie = ( this.ua.match("Mac_PowerPC") != null );

	this.firefoxVersion = this.firefoxVersionChecker();
	this.firefoxMVersion = Math.floor(this.firefoxVersion);
	this.isFirefox = (this.firefoxVersion > 0 );

	this.safariVersion = this.safariVersionChecker();
	this.safariMVersion = Math.floor(this.safariVersion);
	this.isSafari = (this.safariVersion > 85 );

	this.operaVersion = this.operaVersionChecker();
	this.operaMVersion = Math.floor(this.operaVersion);
	this.isOpera = (this.operaVersion > 1 );
	
	this.netscapeVersion = this.netscapeVersionChecker();
	this.netscapeMVersion = Math.floor(this.netscapeVersion);
	this.isNetscape = (this.netscapeVersion > 1 );
	
	this.mozillaVersion = this.mozillaVersionChecker();
	this.mozilla = ( !this.isFirefox && !this.isOpera && !this.isIE && !this.isNetscape && this.mozillaVersion > 0 ); 

	if (this.isIE){
		this.browser="IE";
	} else if (this.isFirefox){
		this.browser="Firefox";
	} else if (this.isSafari){
		this.browser="Safari";
	} else if (this.isOpera) {
		this.browser="Opera";
	} else if (this.isNetscape){
		this.browser="Netscape";
	} else {
		this.browser="other";
	};
	
	if (document.compatMode && document.compatMode != "BackCompat"){
		//標準モード
		this.isCompat = false;
	} else {
		//互換モード
		this.isCompat = true;
	}
	
}

function WindowManager(){
		this.getWidth = function(){
		var br = new BrowserInfo();
		switch(br.browser){
			case "IE":
				var w = (br.isCompat==true) ? document.body.clientWidth : document.documentElement.clientWidth;
				return w;
			break;
			case "Safari"://v3			
				var w = (br.isCompat==true) ? window.innerWidth : document.documentElement.clientWidth;
				var scbar = (this.getPageWidth() > w)? 15 : 0;
				w = (br.isCompat==true) ? w-scbar : w;
				return w;
			break;
			case "Firefox":
				var w = (br.isCompat==true) ? document.body.clientWidth : document.documentElement.clientWidth;
				return w;
			break;
			default://とりあえずIEと同じ
				var w = (br.isCompat==true) ? document.body.clientWidth : document.documentElement.clientWidth;
				return w;
			break;
		}
	}
	this.getHeight = function(){
		var br = new BrowserInfo();
		switch(br.browser){
			case "IE":
				var h = (br.isCompat==true) ? document.body.clientHeight : document.documentElement.clientHeight;
				return h;
			break;
			case "Safari"://v3			
				var h = (br.isCompat==true) ? window.innerHeight : document.documentElement.clientHeight;
				var scbar = (this.getPageHeight() > h)? 15 : 0;
				h = (br.isCompat==true) ? h-scbar : h;
				return h;
			break;
			case "Firefox":
				var h = (br.isCompat==true) ? document.body.clientHeight : document.documentElement.clientHeight;
				return h;
			break;
			default://とりあえずIEと同じ
				var h = (br.isCompat==true) ? document.body.clientHeight : document.documentElement.clientHeight;
				return h;
			break;
		}
	}
	
	//現在の見えているページの始まりの位置
	this.getScrollX = function(){
		//IE6,7 / firefox2,3 / safari3 にて動作確認済み
		var x = document.body.scrollLeft || document.documentElement.scrollLeft;
		return x;
	}
	
	this.getScrollY = function(){
		//IE6,7 / firefox2,3 / safari3 にて動作確認済み
		var y = document.body.scrollTop || document.documentElement.scrollTop;
		return y;
	}
	
	this.getPageWidth = function(){
		var br = new BrowserInfo();
		switch (br.browser) {
			case "IE":
				var w = (br.isCompat == true) ? document.body.scrollWidth : document.documentElement.scrollWidth;
				return w;
				break;
			case "Safari"://v3		
				var w = (br.isCompat == true) ? document.body.scrollWidth : document.documentElement.scrollWidth;
				return w;
				break;
			case "Firefox":
				var w = (br.isCompat == true) ? document.documentElement.scrollWidth : document.body.scrollWidth;
				var w2 = this.getWidth() + window.scrollMaxX;
				w = (w<this.getWidth()) ? w : w2;
				return w;
				break;
			default://
				var w = (br.isCompat == true) ? document.body.scrollWidth : document.documentElement.scrollWidth;
				return w;
				break;
		}
	}
	
	this.getPageHeight = function(){
		var br = new BrowserInfo();
		switch (br.browser) {
			case "IE":
				var h = (br.isCompat == true) ? document.body.scrollHeight : document.documentElement.scrollHeight;
				return h;
				break;
			case "Safari"://v3		
				var h = (br.isCompat == true) ? document.body.scrollHeight : document.documentElement.scrollHeight;
				return h;
				break;
			case "Firefox":
				var h = (br.isCompat == true) ? document.documentElement.scrollHeight : document.body.scrollHeight;
				var h2 = this.getHeight() + window.scrollMaxY;
				h = (h<this.getHeight()) ? h : h2;
				return h;
				break;
			default://
				var h = (br.isCompat == true) ? document.body.scrollHeight : document.documentElement.scrollHeight;
				return h;
				break;
		}
	}
}



function keepDisplaySize(){
	var br_w = wm.getWidth();
	var br_h = wm.getHeight();
	
	var div_w = (br_w < MIN_WIDTH) ? MIN_WIDTH + "px" : "100%"
	var div_h = (br_h < MIN_HEIGHT) ? MIN_HEIGHT + "px" : "100%";
	
	var box = document.getElementById("flashcontent");
	
	box.style.width = div_w;
	box.style.height = div_h;
}

function init(){
	wm = new WindowManager();
	keepDisplaySize();
}

window.onresize = function(){
	keepDisplaySize();
}
