
/*
				var ides4Tooltip = new Array( 'video_9512', 'video_9511', 'video_9510', 'video_9509', 'video_9508', 'video_9507', 'video_9506', 'video_9505', 'video_9504', 'video_9503', 'video_9502', 'video_9501', 'video_9499', 'video_9498', 'video_9497', 'video_9496', 'video_9495', 'video_9494', 'video_9493', 'video_9486' );
				YAHOO.util.Event.addListener( window, "load", createTooltips );
	    */
	    
function $( _id ) {
	return document.getElementById( _id );
}
function Tooltip( idTltp, aConfig ) {
	var _anO = {};
	var _me = this;
	var _pageX = 0, _pageY = 0;
	var _contexts = {};
	var _titleDefault = aConfig.text || false;
	var _idShow = false;
	var _showDelay = aConfig.showdelay || 250;
	
	var _clearShow = function() {
		if( _idShow ) {
			clearTimeout( _idShow );
			_idShow = false;
		}
	}
	
	var _getTitle = function( obj ) {
		var _sId = obj.id;
		return ( _contexts[_sId] && _contexts[_sId].title ) || _titleDefalut;
	}
	
	var _attachToContext = function( ctxs ) {
		if( ctxs instanceof Array ) {
			_attachToContextArray( ctxs );
		} else if( 'string' == typeof( ctxs ) ) {
			_attachToContextStr( ctxs );
		} else {
			throw 'For create Tooltip I can use array or string only';
		}
	}
	
	var _attachToContextArray = function( anArray ) {
		for( var i = 0; i < anArray.length; i++ ) {
			if( 'string' == typeof( anArray[i] ) ) {
				_attachToContextStr( anArray[i] );
			}
		}
	}
	
	var _attachToContextStr = function( sId ) {
		if( 0 == sId.length ) {
			return;
		}
		var isFound = _contexts[sId] || false;
		if( !isFound ) {
			var _o = $( sId );
			YAHOO.util.Event.addListener( _o, "mouseover", _me.onContextMouseOver, _me );
			var _t = ( _o && _o.title ) || false;
			_contexts[sId] = { title: _t };
			if( _t ) {
				_o.title = '';
			}
		}
	}
	
	this.init = function( isDef ) {
		if( 'boolean' != typeof( isDef ) ) {
			isDef = true;
		}
		if ( isDef && document.readyState && document.readyState != "complete" ) {
			var deferredInit = function() {
				_me.init();
			};
			YAHOO.util.Event.addListener( window, "load", deferredInit, _me, true );
			return;
		}
		_anO = new YAHOO.widget.Overlay( idTltp, { visible: false } );
		if( aConfig && ( 'number' == typeof( aConfig.opacity ) ) ) {
				YAHOO.util.Dom.setStyle( 'tltp', 'opacity', aConfig.opacity );
		}
		_attachToContext( ( aConfig.context || '' ) );
	}

	this.setBody = function( _str ) {
		_anO.setBody( "<table border='0' cellpadding='0' cellspacing='0' class='tooltipTable'><tr><td class='dialogLeftM'></td><td class='dialogCenterM'><div style='width: 224px; overflow: hidden;'>" + _str.replace(/&/g,'&amp;') + "</div></td><td class='dialogRightM'></td></tr></table>" );
	}

	this.show = function( obj ) {
		_idShow = false;
		_me.moveTo( _pageX, _pageY );
		_anO.show();
		YAHOO.util.Event.removeListener( obj, "mousemove", _me.onContextMouseMoveHided );
		YAHOO.util.Event.addListener( obj, "mousemove", _me.onContextMouseMoveShowed, _me );
	}
	
	this.hide = function( obj ) {
		_clearShow();
		_anO.hide();
		YAHOO.util.Event.removeListener( obj, "mousemove", _me.onContextMouseMoveHided );
		YAHOO.util.Event.removeListener( obj, "mousemove", _me.onContextMouseMoveShowed );
		YAHOO.util.Event.removeListener( obj, "mouseout", _me.onContextMouseOut );
	}
	
	this.moveTo = function( toX, toY ) {
		_anO.moveTo( toX, toY );
	}
	
	this.onContextMouseMoveShowed = function( e, obj ) {
		_pageX = YAHOO.util.Event.getPageX( e ) + 20;
		_pageY = YAHOO.util.Event.getPageY( e ) + 20;
		_me.moveTo( _pageX, _pageY );
	}
	
	this.onContextMouseMoveHided = function( e, obj ) {
		_pageX = YAHOO.util.Event.getPageX( e ) + 20;
		_pageY = YAHOO.util.Event.getPageY( e ) + 20;
		if( _idShow ) {
			_clearShow();
			var _m = this;
			_idShow = setTimeout( function(){ _me.show( _m ); }, _showDelay );
		}
	}
	
	this.onContextMouseOut = function( e, obj ) {
		_me.hide( this );
	}
	
	this.onContextMouseOver = function( e, obj ) {
		var _m = this;
		var _t = _getTitle( _m );
		if( _t ) {
			_me.setBody( _t );
			_pageX = YAHOO.util.Event.getPageX( e ) + 20;
			_pageY = YAHOO.util.Event.getPageY( e ) + 20;
			_me.moveTo( _pageX, _pageY );
			_idShow = setTimeout( function(){ _me.show( _m ); }, _showDelay );
			YAHOO.util.Event.addListener( this, "mouseout", _me.onContextMouseOut, _me );
			YAHOO.util.Event.addListener( this, "mousemove", _me.onContextMouseMoveHided, _me );
		}
	}
	
	this.init( ( aConfig && aConfig.isInitDefered ) );
}

var myTooltip = {};

function createTooltips() {
    ( new Image() ).src = "images/dialog/descr/topC.png";
    ( new Image() ).src = "images/dialog/descr/bottomC.png";
    ( new Image() ).src = "images/dialog/descr/leftM.png";
    ( new Image() ).src = "images/dialog/descr/rightM.png";
    myTooltip = new Tooltip( "tltp", { context: ides4Tooltip, showdelay: 1, opacity: 0.95, isInitDefered: false } );
}
