/* SWFForceSize code retrieved from DCOM site PL - 20071114 - orginally added and modified by Chris S. on 6 Sept. 2007 */


/**
 * 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 )
{

	this.windowStartedMinimizedFlag = false;
	allTheHTML = document.getElementsByTagName('html');
	this.theHTML = allTheHTML[0];

	this.div = swfObject.getAttribute('id');
	this.minW = minWidth;
	this.minH = minHeight;
	
	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)>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 };
	},
	
	turnDivOn: function()
	{
		document.getElementById( this.div ).style.visibility = "visible";
	},
	
	onLoadDiv: function()
	{
		var initialWindowSize = this.getWinSize();
		//alert("in onLoadDiv");
		if ((initialWindowSize.height === undefined) || (initialWindowSize.heigt == 0)) {
			//alert("should set the minimizedflag to true");
			forcesize.windowStartedMinimizedFlag = true;
		}

		//Delay the first resize til 1 second after the onLoad event.
		setTimeout("forcesize.onResizeDiv();", 1000);



	},
	
	onResizeDiv: function()
	{
	

		var winSize = this.getWinSize();
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		
		if (forcesize.windowStartedMinimizedFlag == true) {
			if ((!(winSize.height === undefined)) && (winSize.height > 0)) {
				forcesize.windowStartedMinimizedFlag = false;
	
				//If we're dealing with IE, reload the page once the window becomes visible
				if ((version >= 5.5) && (document.body.filters)) {
					location.reload();
				}
			}
		
		
		} else {
		
			//alert("forcesize.windowStartedMinimizedFlag is " + forcesize.windowStartedMinimizedFlag + ", winSize.width is " + winSize.width + ", and winSize.height is " + winSize.height);
			var w = winSize.width < this.minW? this.minW+"px" : "100%";
			var h = winSize.height < this.minH? this.minH+"px" : "100%";
			/*
			 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;
			document.getElementById( this.div ).style.height = h;




			/* Only fire this code if you're IE */
			if ((version >= 5.5) && (document.body.filters)) {

				if (winSize.width < this.minW) {
					this.theHTML.style.overflowX='auto';
				} else {
					this.theHTML.style.overflowX='hidden';
				}

				if (winSize.height < this.minH) {
					this.theHTML.style.overflowY='auto';
				} else {
					this.theHTML.style.overflowY='hidden';
				}
			}
		}
	}
}

