window.addEvent( 'domready', function() {

	var tooltip = $( 'toolTip' );
	if( !tooltip ) return;
	var simulateTip = new Element( 'span.simulateTip' );
	simulateTip.inject( tooltip, 'after' );
	var tooltipText = tooltip.getChildren( '.right' )[0];
	tooltip.setStyle( 'display', 'none' );
	tooltip.addEvent( 'mouseover', function() {
		tooltip.setStyle( 'display', 'none' );
	});
	var coords, left;
	$$( '#operatorsMap area' ).each( function( item, index ) {
		simulateTip.set( 'html', item.get( 'alt' ) );
		item.set( 'rel', simulateTip.offsetWidth );
		item.addEvent( 'mouseover', function() {
			coords = item.get( 'coords' ).split( ',' );
			left = ( ( coords[2].toInt() - coords[0].toInt() ) / 2 ) + coords[0].toInt();
			tooltip.setStyles({
				'left': left,
				'top': coords[1].toInt()
			});
			tooltipText.set( 'html', item.get( 'alt' ) );
			tooltip.set( 'href', item.get( 'href' ) );
			tooltipText.setStyle( 'width', item.get( 'rel' ).toInt() );
			tooltip.setStyle( 'display', 'block' );
			tooltip.setStyle( 'left', tooltip.getStyle( 'left' ).toInt() - ( tooltip.offsetWidth / 2 ) );
		});
		item.addEvent( 'mouseleave', function() {
			tooltip.setStyle( 'display', 'none' );
		});
	});

});
