/**
* FixedComponentManager
*
* The fixed component manager contains a collection of component objects which should remain fixed as the page user scrolls their
* window.
**/
function FixedComponentManager() { 

	this.component_array = new Array();
	this.old_top = 0;
	this.old_left = 0;

}

new FixedComponentManager();

/**
* FixedComponentManager.addComponent
*
* Add a component object to the manager
*
* @param c The component object to add
**/
FixedComponentManager.prototype.addComponent = function( c ) { 
	
	this.component_array.push( c );

}

/**
* FixedComponentManager.updatePositions
*
* @param new_left The new leftmost position of the visible window
* @param new_top The new topmost position of the visible window
**/
FixedComponentManager.prototype.updatePositions = function( new_left, new_top ) { 

	for( var i=0; i<this.component_array.length; i++ ) { 
		var d = this.component_array[i].getDOM();

		d.style.top = parseInt( d.style.top ) + ( parseInt( new_top ) - parseInt( this.old_top ) );
		d.style.left = parseInt( d.style.left ) + ( parseInt( new_left ) - parseInt( this.old_left ) );

		//alert( "new_left: " + new_left + " new_top: " + new_top + " DOM.top: " + d.style.top + " DOM.offsetHeight: " + d.offsetHeight + " Window Height: " + getWindowHeight() );


		/*
		//make sure the DOM element has not left the bottom or right of the screen.  This causes endless scrolling
		if ( parseInt( d.style.left ) + parseInt( d.offsetWidth ) > parseInt( getWindowWidth() ) + parseInt( getWindowLeft() )  ) { 
			d.style.left = parseInt( getWindowWidth() ) + parseInt( getWindowLeft() ) - parseInt( d.offsetWidth );
		}
		if ( parseInt( d.style.top ) + parseInt( d.offsetHeight ) > parseInt( getWindowHeight() ) + parseInt( getWindowTop() ) ) { 
			d.style.top = parseInt( getWindowHeight() ) + parseInt( getWindowTop() ) - parseInt( d.offsetHeight );
		}
		*/
		
	}

	this.old_top = parseInt( new_top );
	this.old_left = parseInt( new_left );

}

/**
* FixedComponentManager.startManager
*
* Attaches the manager to the window objectand adds an onScroll function to the window object
**/
FixedComponentManager.prototype.startManager = function() { 

	window.fixed_component_manager = this;
	window.onscroll = function() { 
		window.fixed_component_manager.updatePositions( getWindowLeft(), getWindowTop() );
	};

}


