if( dojo == undefined )
{
	throw Error( 'FooterManager requires Dojo - not included before set_footer.js')
}

dojo.require( 'dojo.window' );
dojo.declare
(
	'FooterManager',
	null,
	{
		constructor: function()
		{
			this.positionFooter();
			this._connectEvents();
		},
		
		_connectEvents: function()
		{
			dojo.connect( window, 'onresize', this, this.positionFooter );
		},
		
		positionFooter: function()
		{
			var container, footer, viewport_coords, container_coords, footer_coords, vertical_gap;
			
			// checks			
			container = dojo.byId( 'container' );
			if( container == undefined )
			{
				throw Error( 'Template must have #container element for FooterManager to position footer' );
			}
			
			footer = dojo.byId( 'footer' );
			if( footer == undefined )
			{
				throw Error( 'Template must have #footer element for FooterManager to position footer' );
			}
			
			// we have the necessary elements so position #footer
			viewport_coords = dojo.window.getBox();
			container_coords = dojo.coords( container );
			footer_coords = dojo.coords( footer );
			vertical_gap = viewport_coords.h - ( container_coords.h + footer_coords.h );
			
			// space to push footer down?
			if( vertical_gap >= 0 )
			{
				dojo.style
				(
					'footer',
					{
						position: 'relative',
						top: vertical_gap + 'px'
					}	
				);
			}
			else
			{
				dojo.style
				(
					'footer',
					{
						position: 'static'
					}	
				);
			}
			
		}
	}
);

dojo.ready( function() { 
	window.oFooterManager = new FooterManager();
	console.log( 'FooterManager', oFooterManager );
} );
