/**
 * SWFFullWindow
 * @version 2.0.S-W
 * @author  Kenichi Nagai
 * @requirement SWFObject 2.1
 */
var swffullwindow = function(){
	return {
		init: function(swfElementId, minWidth, minHeight, maxWidth, maxHeight){
			new SWFFullWindow(swfElementId, minWidth, minHeight, maxWidth, maxHeight);
		}
	}
}();
function SWFFullWindow(swfElementId, minWidth, minHeight, maxWidth, maxHeight){
	this.minWidth = minWidth;
	this.minHeight = minHeight;
	this.maxWidth = maxWidth || -1;
	this.maxHeight = maxHeight || -1;
	this.swfElementId = swfElementId;
	var scope = this;
	swfobject.addLoadEvent(function(){scope.init()});
}
SWFFullWindow.prototype = {
	minWidth: 0,
	minHeight: 0,
	maxWidth: -1,
	maxHeight: -1,
	swfElementId: "",
	swfElement: null,
	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";
		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;
		}
		// footer size
		var footerHeight = 0;
		// set size
		if(!this.swfElement) this.swfElement = document.getElementById(this.swfElementId); // must be always updated!
		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-footerHeight) < minh) swfHeight = minh + "px";
		else if(maxh > 0 && (wh-footerHeight) > maxh)  swfHeight = maxh + "px";
		else swfHeight = (wh-footerHeight)+"px"; // "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-footerHeight) < minh ? "scroll": "hidden";
		}
		this.numResized += 1;
	},
	toString: function(){
		return "[SWFFullWindow minWidth=" + this.minWidth + ", minHeight=" + this.minHeight + "]";	
	}
}


