/**
 * SWFForceSize v1.0: Flash container size limiter for SWFObject - http://blog.pixelbreaker.com/
 *
 * SWFForceSize is (c) 2006 Gabriel Bucknall and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Dependencies: 
 * SWFObject v2.0 - (c) 2006 Geoff Stearns.
 * http://blog.deconcept.com/swfobject/
 *
 * add: Max size edited by quqjp hello[at]quq.jp 2009.01.29
 *
 */
function SWFForceSize( divIdString, minWidth, minHeight, maxWidth, maxHeight )
{
	this.div = divIdString;;
	this.minW = minWidth;
	this.minH = minHeight;
	this.maxW = maxWidth;
	this.maxH = maxHeight;
	
	var o = this;
	this.addWindowEvent( 'onload', this, this.onLoadDiv );
	this.addWindowEvent( 'onresize', this, this.onResizeDiv );
	this.wsiid = null;
}

SWFForceSize.prototype = {

	addWindowEvent: function( eventName, scope, func )
	{
		var oldEvent = window[ eventName ];
		if (typeof window[ eventName ] != 'function') window[ eventName ] = function(){ func.call( scope ); };
		else
		{
			window[ eventName ] = function()
			{ 
				if( oldEvent ) oldEvent();
				func.call( scope );
			}
		}
		
	},

	getWinHeight: function()
	{
		var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number') {
			windowHeight = window.innerHeight;
		} else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			} else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	},

	getWinWidth: function()
	{
		var windowWidth = 0;
		if (typeof(window.innerWidth) == 'number') {
			windowWidth = window.innerWidth;
		} else {
			if (document.documentElement && document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			} else {
				if (document.body && document.body.clientWidth) {
					windowWidth = document.body.clientWidth;
				}
			}
		}
		return windowWidth;
	},

	getWinSize: function()
	{
		var winH, winW;
		winW = this.getWinWidth();
		winH = this.getWinHeight();
		return { height: winH, width: winW };
	},
	
	onLoadDiv: function()
	{
		document.getElementById( this.div ).style.width = "100%";
		document.getElementById( this.div ).style.height = "100%";
		this.onResizeDiv();
	},
	
	onResizeDiv: function()
	{
		var s = this;
		var winSize = this.getWinSize();

		var t = 0;
		var l = 0;
		
		var w;
		if(winSize.width < this.minW){
			w = this.minW+"px";
		}else if(winSize.width > this.maxW){
			l = (winSize.width - this.maxW) / 2;
			w = this.maxW+"px";
		}else{
			w = "100%";
		}

		var h;
		if(winSize.height < this.minH){
			h = this.minH+"px";
		}else if(winSize.height > this.maxH){
			t = (winSize.height - this.maxH) / 2;
			h = this.maxH+"px";
		}else{
			h = "100%";
		}

		var f = function(){
			document.getElementById( s.div ).style.width = w;
			document.getElementById( s.div ).style.height = h;
			document.getElementById( s.div ).style.top = t + "px";
			document.getElementById( s.div ).style.left = l + "px";
		}
	
		/*
		 for IE on PC, turn off the disabled scrollbar 
		 on the right when there's no content to scroll
		*/
		if( document.all )
		{
			if ( (document.body.scroll = ( w!="100%" || h!="100%" )? "auto" : "no") == "auto")
			{
				document.body.style.overflow = "auto";
			}
		}
		
		if(!this.resizeDivFlg && document.all){
			this.resizeDivFlg = true;
			clearInterval(s.wsiid);
			this.wsiid = setInterval(function(){
				clearInterval(s.wsiid);
				f();
			},0);
		}else{
			f();
		}
	}
}
