/*	swffit v1.0 (03/25/2008) <http://swffit.millermedeiros.com/>
	Copyright (c) 2008 Miller Medeiros <http://www.millermedeiros.com/>
	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
var NS=(navigator.appName=='Netscape')?true:false;
var ft;
var mw;
var mh;
var dt
var xw;
var xh;
var xc;

/*t = FlashID, w = minWidth, h = minHeight, d = ContainerDivID _w = maxWidth, _h = maxHeight, c = centered*/
function swffit(t,w,h,d,_w,_h,c){
	/*if the ID,width and height defined then*/
	if(t&&w&&h){
		ft=t;//ft = FlashID
		mw=w;//mw = minWidth
		mh=h;//mh = minHeight
		dt=d;//dt = ContainerDivID
		xw=_w;//xw = maxWidth
		xh=_h;//xh = maxHeight
		//xc=(c||c==null)?true:false;//if c is True or null set centered to True else set centered to False
		xc=false;
		if(swfobject.isDomLoaded){
			startFit();
		}else{
			swfobject.addDomLoadEvent(startFit);
		}
	}
}

function gEBI(x){
	return x;
}

function startFit(){
	document.getElementsByTagName('html')[0].style.height='100%'; //set HTML element height to 100%
	document.body.style.margin='0'; //set BODY margin to 0
	document.body.style.padding='0'; //set BODY padding to 0
	document.body.style.height='100%'; //set BODY height to 100%
	if(swfobject.getObjectById(ft)){
		ft=swfobject.getObjectById(ft); //use SWFobject to get the FlashID
	}else{
		ft=(NS)?document.getElementById(ft).getElementsByTagName('object')[0]:document.getElementById(ft); //get FLashID manually
	}
	gEBI(ft).style.position='absolute'; //set Flash with FlashID position to absolute
	window.onresize=fit; //when window resized do function fit()
	fit(); //do function fit()
}

function fit(){
	//iw=(NS)?window.innerWidth:document.body.clientWidth; //set iw = window width
	//ih=(NS)?window.innerHeight:document.body.clientHeight;//set ih = window height
	iw=document.getElementById(dt).offsetWidth
	ih=document.getElementById(dt).offsetHeight
	//if window width is greater tham maxWidth and MaxWidth is set
	//if div MiddleMiddle width is greater than maxWidth and maxWidth is set
	if(iw>xw&&xw){
		gEBI(ft).style.width=xw+'px'; //Set Flash Width to MaxWidth
		//if centered
		if(xc){
			gEBI(ft).style.left='50%'; //center the Flash
			gEBI(ft).style.marginLeft=-(xw/2)+'px';
		}
	}else{
		//if window width greater than minWidth but less than maxWidth
		//if div MiddleMiddle width is greater than minWidth but less than maxWidth
		if(iw>mw&&(iw<xw||!xw)){
			//gEBI(ft).style.width='100%'; //set Flash to 100% width
			gEBI(ft).style.width=iw+'px'; //set Flash to div MiddleMiddle width
		}else{
			gEBI(ft).style.width=mw+'px'; //set Flash to minWidth
		}
		//if centered
		if(xc){
			gEBI(ft).style.left='auto';  //center the Flash
			gEBI(ft).style.marginLeft='0';
		}
	}
	//if window height is greater than maxHeight
	//if div MiddleMiddle height is greater than maxHeight
	if(ih>xh&&xh){
		gEBI(ft).style.height=xh+'px'; //set Flash height to maxHeight
		//if centered
		if(xc){
			gEBI(ft).style.top='50%';	//center the Flash Virtically
			gEBI(ft).style.marginTop=-(xh/2)+'px';
		}
	}else{
		//if window height greater than minimum height and less than maxHeight
		//if div MiddleMiddle height greater than minimum height and less than maxHeight
		if(ih>mh&&(ih<xh||!xh)){
			//gEBI(ft).style.height='100%'; //set Flash height to 100%
			gEBI(ft).style.height=ih+'px'; //set Flash to div MiddleMiddle height
		}else{
			gEBI(ft).style.height=mh+'px'; //set Flash height to minHeight
		}
		//if centered
		if(xc){
			gEBI(ft).style.top='auto';		//center the Flash horizontally
			gEBI(ft).style.marginTop='0';
		}
	}
};
