/*
 * makeStuffFit stelt de hoogte van "content" in en volgt de volgende logica:
 * 1)	Als de hoogte van de html in content groter is dan de minimale 
 *		"content" hoogte EN als de som van de hoogte van de html in "content" 
 *		en de hoogte van de header en footer ook groter is dan de viewport 
 *		hoogte: stel geen hoogte in, de footer wordt 
 *		naar onderen gedrukt door de html in "content".
 * 2)	Anders: Als de som van de minimale hoogte van de content en de hoogte 
 * 		van de header en footer kleiner is dan de hoogte van de viewport: maak 
 * 		de content dan zo hoog dat de onderkant van de footer de onderkant van  
 * 		de viewport raakt.
 * 3)	Anders: de som van minimale hoogte van de content en de hoogte van de 
 * 		header en footer is groter dan de hoogte van de viewport: stel als 
 * 		hoogte de minimale hoogte van de content in. 
 */
//dojo.require('dijit._base.place');

var MIN_CONTENT_HEIGHT	= 586;
var FIXED_STUFF_HEIGHT	= 275; 

dojo.connect(window, 'onresize', makeStuffFit);

function makeStuffFit() {
	//var vp = dijit.getViewport().h;
	var vp = getWindowHeight();
	var c	= dojo.byId('content');
	var sn	= dojo.byId('contentScrollHeightSniffer'); 
//	console.log('vp: ' + vp);
//	console.log(c+'c: ' + c.style.height);
//	console.log(sn+'sn: ' + sn.scrollHeight);
	if (sn != null && sn.scrollHeight > MIN_CONTENT_HEIGHT 
		&& sn.scrollHeight + FIXED_STUFF_HEIGHT > vp) {
		c.style.height = sn.scrollHeight + 'px';				// 1)
	} else if (c !=null && vp > MIN_CONTENT_HEIGHT + FIXED_STUFF_HEIGHT)  {
		c.style.height = (vp - FIXED_STUFF_HEIGHT) + 'px';		// 2)
	} else if(c !=null) {
		c.style.height = MIN_CONTENT_HEIGHT + 'px';				// 3)
	}
}
if (makeStuffFit) { 
	try {
		makeStuffFit();
	} catch (e) { setTimeout('makeStuffFit()',50); } 
} else { 
	setTimeout('makeStuffFit()',50);
}

function getWindowHeight() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
		 return myHeight;
}

function getCorrectPopupHeight(normalPopupHeight){
	var currentWindowHeight = getWindowHeight();
	if( typeof( currentWindowHeight ) == 'number' ) {
		return (normalPopupHeight < currentWindowHeight) ? normalPopupHeight : currentWindowHeight;
	}
}