/*
	version:
		1.1
	
	homepage:  
		http://www.eberhardt.ca/swfresize/
	
	useage: 
		var sr = new SWFResize(_elementID, _idealWidth, _idealHeight, _minWidth, _minPixelsAboveFold);
			-- _elementID - the ID of the div used for the SWFObject
			-- _idealWidth - the original width of the FLA file (used to calculate the fullRatio)
			-- _idealHeight - the original height of the FLA file (used to calculate the fullRatio)
			-- _minWidth -- the minimum width of the SWF
			-- _minPixelsAboveFold -- the of pixels of the original FLA, if your SWF was at 100%, that MUST remain visible above the fold.
		
	notes:
		It's a good idea to put this immediately before you put your "new SWFObject()" command, if you are using SWFObject

*/

if(typeof eberhardt=="undefined"){var eberhardt=new Object();}

eberhardt.SWFResize=function(_elementID, _idealWidth, _idealHeight, _minWidth, _minPixelsAboveFold){
	var element;
	var visibleRatio;
	var fullRatio;
	var minWidth;
	if(!document.getElementById){return;}
	this.element = _elementID;
	this.visibleRatio = (_minPixelsAboveFold == undefined) ? _idealWidth/_idealHeight : _idealWidth/_minPixelsAboveFold;
	this.fullRatio = _idealWidth / _idealHeight;
	this.minWidth =  (_minWidth == undefined) ? 0 : _minWidth;
	
	eberhardt.addEvent(window, 'resize', eberhardt.delegate(this,this.resize), false);
	
	this.resize();
};

eberhardt.SWFResize.prototype={
	resize:function(){
		docWidth = document.body.clientWidth;
		docHeight = document.body.clientHeight;
		var newFlashWidth = docWidth;
		while (newFlashWidth / docHeight > this.visibleRatio){
			newFlashWidth = newFlashWidth - 5;
		}
		if (newFlashWidth < this.minWidth){
			newFlashWidth = this.minWidth;
		}
		
		document.getElementById(this.element).style.width = newFlashWidth + "px";
		document.getElementById(this.element).style.height = newFlashWidth / this.fullRatio + "px";
	}
}

var SWFResize = eberhardt.SWFResize;

// These two functions below are used to handle adding the event to the body onresize.
// They are too generic to actually be considered part of SWFResize, but I didn't want them to conflict with any other names,
// so I added them to "eberhardt".
eberhardt.delegate = function( that, thatMethod )
{
    return function(e) { return thatMethod.call(that,e); }
}

eberhardt.addEvent = function(el, eType, fn, uC) {
	if (el.addEventListener) {
		el.addEventListener(eType, fn, uC);
		return true;
	} else if (el.attachEvent) {
		return el.attachEvent('on' + eType, fn);
	} else {
		el['on' + eType] = fn;
	}
}

/*
deconcept.SWFObject.prototype.swfresize = function(){
	alert (this);	
}
*/
