function CRUX_TTIP_show ( sSenderId, sType, sText, iXOffset, iYOffset, iWidth, bFixedWidth ) {
	
	oAnchor = $( '#' + sSenderId );

	return CRUX_TTIP_showForObject( oAnchor, sType, sText, iXOffset, iYOffset, iWidth, bFixedWidth );
	
}


function CRUX_TTIP_showForObject( oAnchor, sType, sText, iXOffset, iYOffset, iWidth, bFixedWidth ) {
	
	if ( !iWidth ) iWidth = 300;
	sTooltipId = 'CRUX_TTIP_' + sType;
	
	var oTT = $( '#' + sTooltipId );
	if ( oTT.get(0) == null ) {
		if ( ! ( oTT = CRUX_TTIP_createTooltip( sType ) ) ) {
			return false;
		}
	}
	
	if ( oAnchor.get(0) == null ) {
		return false;
	}

	oContent = oTT.find( '.content' );
	oContent.html( sText );

	if (iXOffset == undefined)
		iXOffset = 0;
	  
	if (iYOffset == undefined)
		iYOffset = 0;
	
	oOffset = oAnchor.offset();
		
	iYOffset += oAnchor.height();
	
	oTT.css ( 'left', iXOffset + oOffset.left );
	oTT.css ( 'top', iYOffset + oOffset.top );

	oTT.width ( iWidth );
	
	oTT.show();
	
	if ( bFixedWidth ) {
		iContentWidth = iWidth;
	} else {
		iContentWidth = oContent.width();
		oContent.children().each( function() {
			if ( $( this ).css( 'display' ) != 'inline' ) {
				return;
			}
			var iCurrentWidth = $(this).width();
			if ( iCurrentWidth > iContentWidth ) {
				iContentWidth = iCurrentWidth;
			}
		});
	}

	oTT.width ( 
		min(
			iContentWidth,
		min (
				iWidth,
			Math.floor ( $(window).width() * 0.3 ) 
		)
		)
	);

	if ( oTT.offset().left + oTT.width() > $(window).width() - 50 ) {
		oTT.css ( 'left', oAnchor.offset().left - oTT.width() + 'px')
	}
	return sTooltipId;
}

function CRUX_TTIP_close( sType ) {
	sTooltipId = 'CRUX_TTIP_' + sType;
	if ( ( oTT = $('#' + sTooltipId ) ).get(0) ) {
		oTT.hide();
		return true;
	}
	return false;
}

function min (a, b) {
	return a < b ? a : b;
}

function CRUX_TTIP_createTooltip ( sStyle ) {
	oTT = $( aCRUX_TTIP_styles[ sStyle ] );
	if (oTT.get(0)) {
		oTT.appendTo('body');
		return oTT;
	}
	return null;
}

