/**
 * 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/
 */
 function SWFForceSize( swfObject, minWidth, minHeight, maxWidth, maxHeight )
{
	this.div = swfObject.getAttribute('id');
	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 );
}

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);
			};
		}
		
	},

	getWinSize: function()
	{
		var winH, winW;
		if (parseInt(navigator.appVersion,10)>3) {
			if ( document.body.offsetWidth ){ // Gecko / WebKit
				winW = document.body.offsetWidth;
				winH = document.body.offsetHeight;
			} else if ( document.body.offsetWidth ){ // MS
				winW = document.body.offsetWidth;
				winH = document.body.offsetHeight;
			}
		}
		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 winSize = this.getWinSize();
		var w;
		var h;
			
		/*var w = winSize.width < this.minW? this.minW+"px" : "100%";
		var h = winSize.height < this.minH? this.minH+"px" : "100%";*/
		
		
		if ( winSize.height < this.minH )
		{
			h = this.minH;
		}
		else
		{
			if ( winSize.height > this.maxH )
			{
				h = this.maxH;
			}
			else
			{
				h = "100%";
			}
		}
		
		/*
		if ( winSize.width < this.minW )
		{
			w = this.minW;
		}
		else
		{
			if ( winSize.width > this.maxW )
			{
				w = this.maxW;
			}
			else
			{
				w = "100%";
			}
		}
		*/
		
		var browserHeight = winSize.height;
		
		w = 784 * browserHeight / 560;
		//w = 1000 * browserHeight / 560;
		
		if ( w < this.minW )
		{
			w = this.minW;
		}
		else if ( w > this.maxW )
		{
			w = this.maxW;
		}
		
		
		var x = ( winSize.width - w ) / 2;
		var y = ( winSize.height - h ) / 2;
		
		if ( isNaN( x ) || x < 0)
		{
			x = 0;
		}
		
		if( isNaN( y ) || y < 0)
		{
			y=0;
		}
		/*
		 for IE on PC, turn off the disabled scrollbar 
		 on the right when there's no content to scroll
		*/
		if (document.all) {
			document.body.scroll = (w != "100%" || h != "100%") ? "auto" : "no";
		}
		document.getElementById( this.div ).style.width = ( w == "100%" ) ? w : w+ "px";
		document.getElementById( this.div ).style.height = ( h == "100%" ) ? h : h + "px";
		
		document.getElementById( this.div ).style.position = "absolute";
		document.getElementById( this.div ).style.top = y + "px";
		document.getElementById( this.div ).style.left = x + "px";
	}
};