/**
 * SWFFullWindow
 * @author Kenichi Nagai
 * @version 2.1.1
 * @requirement SWFObject 2.2
 */
if(typeof jp == "undefined") var jp = {};
if(typeof jp.naggg == "undefined") jp.naggg = {};
jp.naggg.swffullwindow = function(){
	return {
		init: function(swfElementId, minWidth, minHeight, option){
			return new jp.naggg.SWFFullWindow(swfElementId, minWidth, minHeight, option);
		},
		isLoaded: false
	}
}();
jp.naggg.SWFFullWindow = function(swfElementId, minWidth, minHeight, option){
	this.swfElementId = swfElementId;
	this.minWidth = minWidth;
	this.minHeight = minHeight;
	if(option){
		if(option.maxWidth != undefined) this.maxWidth = option.maxWidth;
		if(option.maxHeight != undefined) this.maxHeight = option.maxHeight;
		if(option.autoHide != undefined) this.autoHide = option.autoHide;
	}
	if(this.autoHide && document.getElementById(swfElementId)) document.getElementById(swfElementId).style.visibility = this.v0;
	var scope = this;
	if(swffullwindow.isLoaded) this.init();
	else swfobject.addLoadEvent(function(){scope.init()});
}
jp.naggg.SWFFullWindow.prototype = {
	swfElementId: "",
	swfElement: null,
	minWidth: 0,
	minHeight: 0,
	maxWidth: -1,
	maxHeight: -1,
	autoHide: true,
	v1: "visible",
	v0: "hidden",
	numResized: 0,
	init: function(){
		var html = document.getElementsByTagName("html")[0];
		var body = document.body;
		html.style.height = "100%";
		body.style.height = "100%";
		body.style.margin = "0";
		body.style.padding = "0";
		this.swfElement = document.getElementById(this.swfElementId);
		if(this.swfElement){
			this.swfElement.style.visibility = this.v1;
			this.swfElement.style.outline = "none"; // FF3.6
		}
		var scope = this;
		window.onresize = function(){ scope.onWindowResize();}
		setTimeout(window.onresize, 50); // delayed call
	},
	onWindowResize: function(){
		// get winsow size
		var ww, wh;
		if(self.innerHeight){ // FF, Opera, Safari, Google Chrome
			ww = self.innerWidth;
			wh = self.innerHeight;
		}else if(document.documentElement && document.documentElement.clientHeight){ // IE6+
			ww = document.documentElement.clientWidth;
			wh = document.documentElement.clientHeight;
		}else if(document.body.clientHeight){ // IE5.5
			ww = document.body.clientWidth;
			wh = document.body.clientHeight;
		}
		// for null
		if(!this.swfElement) this.swfElement = document.getElementById(this.swfElementId);
		if(!this.swfElement) return; // no flash
		// set size
		var minw = this.minWidth;
		var minh = this.minHeight;
		var maxw = this.maxWidth;
		var maxh = this.maxHeight;
		var swfWidth;
		var swfHeight;
		if(ww < minw) swfWidth = minw + "px";
		else if(maxw > 0 && ww > maxw) swfWidth = maxw + "px";
		else swfWidth = "100%";
		if(wh < minh) swfHeight = minh + "px";
		else if(maxh > 0 && wh > maxh) swfHeight = maxh + "px";
		else swfHeight = "100%";
		this.swfElement.style.width = swfWidth;
		this.swfElement.style.height = swfHeight;
		// set scrollbar style for IE
		var html = document.getElementsByTagName("html")[0];
		if(navigator.userAgent.indexOf("MSIE") != -1){
			html.style.overflowX = ww < minw ? "scroll": "hidden";
			html.style.overflowY = wh < minh ? "scroll": "hidden";
		}
		this.numResized += 1;
	},
	toString: function(){
		return "[SWFFullWindow minWidth=" + this.minWidth + ", minHeight=" + this.minHeight + "]";
	}
}
var swffullwindow = jp.naggg.swffullwindow;
var SWFFullWindow = jp.naggg.SWFFullWindow;
swfobject.addLoadEvent(function(){jp.naggg.swffullwindow.isLoaded = true;});

