/* 
 * Copyright (c) 2003 Autometa Corporation
 * All Rights Reserved
 * License:  Closed
 * Platform:  Autometa DOM (LGPL)
 */
var gAM_dom = null;

function JI_onload ()
{
    AM_domId.prototype  =   new AM_dom   ( 'JI_hover' )    			;
    var _oHover         =   new JI_Hover ( 'JI_hover' )				;

    // FIXME: workaround for Konqueror setTimeout()
    gAM_dom             =   AM_domId.prototype                      ;

    AM_domId.prototype.setCaptureHandlers
    (
            [
               { name: 'JI_hover' , obj: _oHover  }
            ]
        ,   [
                 [ 'mouseover', 'JI_hover'  ]
               , [ 'mouseout' , 'JI_hover'  ]
            ]
    )                                                       		;

    window.onfocus           = _oHover.setCapture()                 ;
    window.onlosefocus       = _oHover.releaseCapture()             ;
    window.onblur       	 = _oHover.releaseCapture()             ;

	_oHover.setCapture();
}

function JI_Hover ( p_domID )
{
	var		_dom                =   new AM_domId ( p_domID )        ;
    this.AM_DOM                 =   _dom                            ;
    this.node                   =   this.AM_DOM.node				;
    if ( ! this.node ) return null                                  ;

	var		self				=	this						
		, 	_dS					=	this.node.style					;

    _dS.zIndex                  =   '16384'                         ;
	_dS.border              	=   'none'							;
	_dS.position            	=   'absolute'                      ;

	var _boxElem	=	null
		_linkElem	=	null
		_elemTitle	=	null										;

	var _aLic = [ 		'<font size=+0 color="darkgreen"> BSD</font>'
					,	'<font size=+0 color="darkgreen"> MIT</font>'
					,	'<font size=+0 color="darkgreen"> Apache</font> v1.1'
					,	'<font size=+0 color="darkred"> GPL</font> v2+'
					,	'<font size=+0 color="indigo"> LGPL</font> v2.1' 
					,	'<font size=+0 color="indigo"> LGPL</font> v2' 
					,	'<font size=+0 color="darkred"> Mozilla</font> 1.0' 
					,	'<font size=+0 color="indigo"> LGPL</font> unspecified version' 
					,	'<font size=+0 color="indigo"> LGPL</font> v2.1+' 
					,	'<font size=+0 color="darkred"> Globus TPL</font> v2' 
					,	'<font size=+0 color="darkred"> Sun ISSL</font> v1.2' 
					,	'<font size=+0 color="darkgreen"> Apache-like</font>' 
					,	'<font size=+0 color="darkred"> IBM CPL 1.0</font>' 
					,	'<font size=+0 color="darkgreen"> Apache</font> v2.0'
				]													;

	var _aSup = [ 		'Commercial'
					,	'Informal'
					,	'SourceForge'
					,	'Mailing List'
				]													;

	var _aNat = [ 		'United&nbsp;States'
					,	'France'
					,	'United&nbsp;Kingdom'
					,	'Sweden'
					,	'Netherlands'
					,	'Czech&nbsp;Republic'
					,	'Switzerland'
					,	'Canada'
					,	'Belarus'
					,	'Australia'
					,	'Germany'
				]													;

	var _aProj = [		'Apache&nbsp;Jakarta'
					,	'Sourceforge'
				 ]													;

	var _fMarkupRow = function ( p_szName, p_szValue )
	{
		return '<tr><td class="pop-h">' 
					+ p_szName + ':</td><td class="pop-v">' 
					+ p_szValue + '</td></tr>'						;
	};

    this.mouseover = function ( p_domEv )
    {
        var e    	=   new AM_domEvent ( _dom , p_domEv )
		  , elem	=	null										;

        if      (    e.srcElem.tagName == 'A' 
                  && e.srcElem.href              )
            elem	=	e.srcElem                                   ;
                
        else if (    e.parElem 
                  && e.parElem.tagName == 'A'
                  && e.parElem.href              )
            elem	=	e.parElem                                   ;
        
        else
            return e.free ()                                        ;

        var szLicense 		=	elem.getAttribute ('l')
          , szSupport 		=	elem.getAttribute ('s')
          , szOrigin 		=	elem.getAttribute ('o')
          , szPlatform 		=	elem.getAttribute ('p')
          , szFeatures 		=	elem.getAttribute ('f')
          , szNation		=	elem.getAttribute ('n')
          , szAffiliate		=	elem.getAttribute ('a')
          , szProject		=	elem.getAttribute ('j')
		  , szTitle		=	''										;

		szLicense 	=	szLicense 	?	_aLic [ elem.getAttribute ('l') ]				: '';
		szSupport 	=	szSupport 	?	_fMarkupRow ( 'Support' , _aSup [ szSupport ] ) : '';
		szNation	=	szNation	?	_fMarkupRow ( 'Nation'  , _aNat [ szNation ] )	: '';
		szProject	=	szProject	?	_fMarkupRow ( 'Project'  , _aProj [ szProject ] )	: '';
		szOrigin 	=	szOrigin	?	_fMarkupRow ( 'Origin' , szOrigin ) 	:	''	;
		szPlatform 	=	szPlatform	?	_fMarkupRow ( 'Platform' , szPlatform ) :	''	;
		szFeatures 	=	szFeatures	?	_fMarkupRow ( 'Features' , szFeatures ) :	''	;
		szAffiliate	=	szAffiliate	?	_fMarkupRow ( 'Affiliate', szAffiliate ):	''	;

		if ( _elemTitle = elem.title )
		{
			szTitle		=	'<tr><td colspan=2>' 
								+ _elemTitle + '</td></tr>'				;
			elem.title	=	''											;
			_linkElem	=	elem										;
		}

		if ( szLicense || szTitle )
		{
			_boxElem				=	e.parElem							;
			_boxElem.style.borderBottom 	
									= 'solid 2px lightsteelblue'			;
			_dS.top                 =   getRealTop (_boxElem )  
											- self.node.offsetHeight		;

			if (szLicense) 
				self.node.innerHTML 	=	'<table class="pop-t">'
												+ _fMarkupRow ( 'License', szLicense )
												+ szSupport 	
												+ szFeatures						
												+ szPlatform						
												+ szOrigin						
												+ szAffiliate						
												+ szProject						
												+ szNation						
												+ szTitle						
												+ '</table'					;
			else if (szTitle)
				self.node.innerHTML 	=	'<table class="pop-t">' 
												+ szTitle + '</table'		;

			var _left               =   getRealLeft (_boxElem ) 
											+ _boxElem .offsetWidth			;

			if ( _left > _dom.curWidth - self.node.offsetWidth )
				_left				=	_dom.curWidth
											- self.node.offsetWidth			;

			_dS.left				=	_left 								;
			_dS.visibility          =   'visible'                           ;
		}

		return e.free()												;
	}

    this.mouseout = function ( p_domEv )
	{
        var e    =   new AM_domEvent ( _dom , p_domEv )          	;

		if ( e.fromElement )
		{
			_dS.visibility          =	'hidden'                    ;
			self.node.innerHTML		= 	null						;
			if ( _boxElem )
			{
				_boxElem.style.borderBottom = 'none'				;
				_boxElem = null										;
			}
			if ( _linkElem )
			{
				_linkElem.title		=	_elemTitle					;
				_linkElem			=	null						;
			}
		}

        return e.free()												;
	};

    this.setCapture = function ()
    {
        _dom.setCapture ()                                      	;
    };

    this.releaseCapture = function ()
    {
        _dom.releaseCapture()                                   	;
    };

	return this;
}

function printObj ( testObj )
{
    var szObj       =   ''                                      ;
    for ( var i in testObj )
        szObj       += 'obj[' + i + ']=' + testObj[i]           ;
    return szObj    ;
}

