window.resizeFunctionCode = '{123-abc-456}'; 

/*
try {
	// hide scrollbars while loading
	if (window.frameElement) {
		$("<style type='text/css'> body {overflow: hidden;} </style>").appendTo("head");
		$(window.frameElement).attr('scrolling', 'no');
	} // if (window.frameElement)
}
catch (ex) { }
*/

window.resize = function (parResizeTopWindow, parDirection) {

    if (typeof parResizeTopWindow == 'undefined') parResizeTopWindow = false;
    if (typeof parDirection == 'undefined') parDirection = 'both';

	var varDebugMessage = '';
	//uncomment to debug
	//varDebugMessage = 'window.resize(' + parResizeTopWindow + ',\'' + parDirection + '\');';
	
	if (parDirection == 'down' || parDirection == 'both') {
		
		$(this.document).find('iframe').each(function () {
			try {
				
				if (window.resizeFunctionCode != this.contentWindow.resizeFunctionCode) throw 'Invalid Parent Domain';
				
				this.contentWindow.resize(parResizeTopWindow, 'down');
			}
			catch (ex) { }
		});
		
	} // if (parDirection == 'down' || parDirection == 'both')

    if (!this.parent || this.parent == this) {

        if (!parResizeTopWindow) return;

        var lngWidth = Math.min($(this.document).width(), this.screen.availWidth);
        var lngHeight = Math.min($(this.document).height(), this.screen.availHeight);

        this.resizeTo(lngWidth, lngHeight);

    } else { // if (!this.parent || this.parent == this)

		try
		{
			if (this.parent.resizeFunctionCode != this.resizeFunctionCode) throw 'Invalid Parent Domain';
			
			// IE8 is a stupid browser that doesn't know min-width and min-height
			var varMinWidth = parseInt($(this.frameElement).css('min-width')) || 0;
			var varMinHeight = parseInt($(this.frameElement).css('min-height')) || 0;
			
			// IE8 is a stupid browser that miscalculates document.width and document.height
			var varExtraWidth = 0;
			var varExtraHeight = 0;			
			if ($.browser.msie && $.browser.version.slice(0, 1) == '8'){
				varExtraWidth = 4;
				varExtraHeight = 2;
			} // if ($.browser.msie && $.browser.version.slice(0, 1) == '8')
			
			// And Safari and Chrome miscalculate as well.
			if ($.browser.webkit) {
				varExtraWidth = 2;
			} // if ($.browser.webkit)
			
			// als de frame een ATTRIBUUT width heeft, dan gaan we de breedte niet aanpassen.
			if (!$(this.frameElement).attr('width')) {
			
				$(this.frameElement).css('width', '1px');
				
				if (varDebugMessage) varDebugMessage += '<br />' + 'width <- ' + Math.max(varMinWidth, $(this.document).width() + varExtraWidth) + 'px';
				
				$(this.frameElement).css('width', Math.max(varMinWidth, $(this.document).width() + varExtraWidth) + 'px');
			
			} // if (!$(this.frameElement).attr('width'))
			
			// als de frame een ATTRIBUUT height heeft
			if ($(this.frameElement).attr('height')) {
				
				// als dit attribuut een percentage is dan gaan we de hoogte van de iframe niet aanpassen
				if ($(this.frameElement).attr('height').indexOf('%') >= 0) { /* do nothing*/ }
				
				// als dit attribuut geen percentage is dan behandelen we het als een min-height
				else {
					
					$(this.frameElement).css('height', '1px');
					
					if (varDebugMessage) varDebugMessage += '<br />' + 'height <- ' + Math.max(varMinHeight, parseInt($(this.frameElement).attr('height')), $(this.document).height() + varExtraHeight) + 'px';
					
					$(this.frameElement).css('height', Math.max(varMinHeight, parseInt($(this.frameElement).attr('height')), $(this.document).height() + varExtraHeight) + 'px');
					
				}
				
			} // if (!$(this.frameElement).attr('height'))
			
			// als de frame geen ATTRIBUUT height heeft dan nemen we gewoon de nieuwe hoogte
			else { // if (!$(this.frameElement).attr('height'))
			
				$(this.frameElement).css('height', '1px');
				
				if (varDebugMessage) varDebugMessage += '<br />' + 'height <- ' + Math.max(varMinHeight, $(this.document).height() + varExtraHeight) + 'px';
				
				$(this.frameElement).css('height', Math.max(varMinHeight, $(this.document).height() + varExtraHeight) + 'px');
				
			} // else // if (!$(this.frameElement).attr('height'))
			
			if (parDirection == 'up' || parDirection == 'both') this.parent.resize(parResizeTopWindow, 'up');
			
		}
		catch (ex)
		{
			if (this.FB) if (this.FB.Canvas) if (this.FB.Canvas.setSize) {
				this.FB.Canvas.setSize({ width: 520, height: $(this.document).height() });
			} // if (this.FB) if (this.FB.Canvas) if (this.FB.Canvas.setSize)
		}
		
    } // else // if (!this.parent || this.parent == this)

	if (varDebugMessage) DebugWindow(varDebugMessage);

}  // window.resize

$(window).load(function(){
						
	this.resize(false, 'up');
	
	// if necessary, show scrollbars after loading
	/*
	try {
		if (this.frameElement) {
			$(this.document.body).css('overflow', 'auto');
			$(this.frameElement).attr('scrolling', 'auto');
		} // if (this.frameElement)
	}	
	catch (ex) { }
	*/	
});

