/* Min-width functionality for MSIE. From Ruthsarian at http://webhost.bridgew.edu/etribou/ */

/* event_attach() takes care of attaching event handlers (functions) to events. this 
 * simplifies the process of attaching multiple handlers to a single event
 */
function event_attach( event , func )
{
	if ( window.attachEvent )
	{
		window.attachEvent( event , func );
	}
	else
	{
		if ( ( typeof( func ) ).toLowerCase() != 'function' )
		{
			return;
		}
		if ( ( typeof( document.event_handlers ) ).toLowerCase() == 'undefined' )
		{
			document.event_handlers = new Array();
		}
		if ( ( typeof( document.event_handlers[ event ] ) ).toLowerCase() == 'undefined' )
		{
			document.event_handlers[ event ] = new Array();
		}
		if ( ( typeof( eval( 'window.' + event ) ) ).toLowerCase() != 'function' )
		{
			eval( 'window.' + event + ' = function () { if ( ( typeof( document.event_handlers[ \'' + event + '\' ] ) ).toLowerCase() != \'undefined\' ) { for ( i = 0 ; i < document.event_handlers[ \'' + event + '\' ].length ; i++ ) { document.event_handlers[ \'' + event + '\' ][ i ](); } } } ' );
		}
		document.event_handlers[ event ][ document.event_handlers[ event ].length ] = func;
	}
}

/* set_min_width_rs() takes a different approach to emulating min-width functionality
 */
function set_min_width_rs( element_id , min_width )
{
	if ( document.getElementById && navigator.appVersion.indexOf( "MSIE" ) > -1 && !window.opera )
	{
		document.mw_element_id = element_id;
		document.mw_min_width = min_width;
		event_attach('onload' , control_min_width_rs );
		event_attach('onresize' , control_min_width_rs );
	}
}

/* control_min_width_rs() is the event handler used by set_min_width_rs. This method fixes a couple bugs with
 * the p7 approach that can lead to the browser crashing. This method specifically targets IE although perhaps
 * it could be modified to work with other browsers later.
 */
function control_min_width_rs()
{
	var e = document.getElementById( document.mw_element_id );
	var offset = parseInt( 0 + e.currentStyle.paddingLeft ) + parseInt( 0 + e.currentStyle.paddingRight ) + parseInt( 0 + e.currentStyle.borderLeftWidth ) + parseInt( 0 + e.currentStyle.borderRightWidth );

	if ( ( document.body.clientWidth - ( e.offsetLeft * 2 ) ) <= ( document.mw_min_width - offset ) && parseInt( 0 + e.style.width ) != document.mw_min_width )
		e.style.width = document.mw_min_width + "px";
	else if ( document.body.clientWidth > ( document.mw_min_width + offset + e.offsetLeft * 2 ) )
		e.style.width = "auto";
}