/*
*Copyright mtr 2008
*/
var _jfcBaloon = function()
{
    this.dElement        = new Object();
    this.forceShow    = 0;
    this.timeOut      = null;
    this.shiftPos     = {};
    
    this.alignStr     = 'bottom';
    this.setAlign           = function (_align)
    {
       this.alignStr = _align;
//       align();
    };
    this.align              =  function( _posObj )
    {
    if(!_posObj)return;
       var pos = {};
       this.dElement.prototype.style.display="block";

       var thisPos = GetPosition(this.dElement.prototype);
       if(typeof(this.alignStr)=='string')
       switch(this.alignStr)
       {
           case 'bottom':
                       pos={
                            top:_posObj.y+_posObj.height,
                            left:_posObj.x
                            }
           break;
           case 'top':
                       pos={
                            top:_posObj.y-thisPos.height,
                            left:_posObj.x
                           }
           break;
           case 'left':
                       pos ={
                            top:_posObj.y,
                            left:_posObj.x-thisPos.width
                       }
           break;
           case 'right':
           break;
           case 'static':
                      pos ={
                            top:this.shiftPos.top,
                            left:this.shiftPos.left
                       }
           break;
       }
       else
           {
               jfcBaloon.dElement.prototype.style.display="block";
               this.alignStr();
           }
     if(this.alignStr!='static' && typeof(this.alignStr)=='string')
     {
           {
            if(this.shiftPos.left) pos.left = pos.left+this.shiftPos.left+'px';
            if(this.shiftPos.top) pos.top = pos.top+this.shiftPos.top+'px';
           }
       this.dElement.prototype = ___prototype(this.dElement.prototype,{style:pos});
     }
    };
//     alert(dElement);   
      
       this.setShiftPos = function( _shiftPos )
       {
           this.shiftPos = _shiftPos;
       }
}

jfcBaloon = new _jfcBaloon();

function initBaloon( _timeOut )
{
    var baloonJSON = {
                            id:'_id_baloon',
                            innerHTML:'Baloon',
                            className:'jfcBaloon',
                            style:{
                                display:'none',
                                position:'absolute'
                            },
                            onclick:function(event){baloonClick(event);}
                };
    var d = document.getElementById('def');
    if(!d)
    {
       d = document.createElement('div');
       document.body.appendChild(d);
    }

    jfcBaloon.dElement            = new dEl(d,0,baloonJSON);
	jfcBaloon.___timeOut   = (_timeOut)?_timeOut:300;
}
function setBaloonTimeout( _timeOut )
{
 if(jfcBaloon)
 	jfcBaloon.___timeOut   = (_timeOut)?_timeOut:300;
}

function doBaloon( _object, _url, _innerHTML, _align, _shiftPos )
{
	if(!jfcBaloon) return;
	_hideBaloon();
        
	if(_align)
	   jfcBaloon.setAlign(_align);
	else 
	   jfcBaloon.setAlign('bottom');

        if(!_shiftPos)
            {
               _shiftPos={top:0,left:0} ;
            }
        jfcBaloon.setShiftPos( _shiftPos );
        
	if(jfcBaloon.dElement.prototype)
	   jfcBaloon.dElement.prototype.className="jfcBaloon";
	clearTimeout(jfcBaloon.timeOut);
	jfcBaloon.___object                 = getRawObject( _object );
		
	
	if(!jfcBaloon.forceShow)
	   jfcBaloon.___object.onmouseout   = hideBaloon;
	if( _url)
	{
		jfcBaloon.___url            = _url;
	}
	if( _innerHTML )
	{
		jfcBaloon.___innerHTML      = _innerHTML;
	} 	
        if(jfcBaloon.timeOut)
          jfcBaloon.timeOut                   = setTimeout("showBaloon()", jfcBaloon.___timeOut);        
        else
            {
               showBaloon();
            }
        
}
function showBaloon(  )
{
	var iH = '';
	if(typeof(jfcBaloon.___url)=='string'&&jfcBaloon.___url)
	{
		iH = '<div style="background-color:#fff;border:1px solid silver;"><img src="images/loading.gif" /></div>';
		jfcBaloon.dElement.prototype = ___prototype(DOMel(jfcBaloon.dElement), {innerHTML: iH,style:{display:'block'}} );
		rpcGet('rpc_dBaloonHandler','',jfcBaloon.___url,'');
                jfcBaloon.align( posObj );
                return;
	}
	if (typeof(jfcBaloon.___url)=='object')
	{
//		jfcBaloon.prototype = dEl( 0, 0, jfcBaloon.___url);
         if(jfcBaloon.___url.___align)
            jfcBaloon.setAlign(jfcBaloon.___url.___align);
		jfcBaloon.dElement.prototype.innerHTML = '';
		jfcBaloon.dElement.prototype = ___prototype(DOMel(jfcBaloon.dElement), jfcBaloon.___url );
	}
	if(jfcBaloon.___innerHTML)
	{
		var iH = jfcBaloon.___innerHTML;
		jfcBaloon.dElement.prototype = ___prototype(DOMel(jfcBaloon.dElement), {innerHTML: iH} );
	}

	var posObj 				= GetPosition(jfcBaloon.___object);
	if(!posObj)
	{
	 posObj             = GetPosition(document.body);
	}        

	showJSON = {style:{
							display:'block',					
							zIndex:100
					}
				};
	jfcBaloon.dElement.prototype = ___prototype(DOMel(jfcBaloon.dElement), showJSON );
	
    jfcBaloon.align( posObj );

    if( jfcBaloon.dElement.prototype.parentNode.className=='jfcContainer' )
    {
        jfcBaloon.dElement.prototype.parentNode.style.display = 'block';
    }
//    shadowIt( jfcBaloon.dElement.prototype );
 }

function rpc_dBaloonHandler( req )
{
    var posObj = 0;
	if(req.responseJS )
	if(req.responseJS.id)
	{
		posObj 		= GetPosition( req.responseJS.id );
		eval(req.responseJS.action);
	}
	if(!posObj) 
	{
		posObj = GetPosition( jfcBaloon.___object );
	}
	
	changeJSON = {	innerHTML:req.responseText,
					style:{
							display:'block'
					}
				};
    if( jfcBaloon.dElement.prototype.parentNode.className=='jfcContainer' )
    {
        jfcBaloon.dElement.prototype.parentNode.style.display = 'block';
    }
    {				
	   jfcBaloon.dElement.prototype = ___prototype(DOMel(jfcBaloon.dElement), changeJSON);
	}
	
    jfcBaloon.align(posObj);
//    shadowIt( jfcBaloon.dElement.prototype );
	
}
function hideBaloon( event )
{
if(jfcBaloon.forceShow) return 0;
	clearTimeout( jfcBaloon.timeOut );
	if(jfcBaloon.forceShow)return;
	if ( jfcBaloon.dElement.prototype )
	{
		jfcBaloon.dElement.prototype.onmouseover = _noH;
		jfcBaloon.dElement.prototype.onmouseout = hideBaloon;
	}
	jfcBaloon.timeOut = setTimeout("_hideBaloon()",500);
}
function _noH()
{
	clearTimeout(jfcBaloon.timeOut);
}
function _hideBaloon()
{
	changeJSON = {	style:{
							display:'none'
					}
				};
    if( jfcBaloon.dElement.prototype.parentNode.className=='jfcContainer' )
    {
        jfcBaloon.dElement.prototype.parentNode.style.display = 'none';
    }
    else
    { 
	   jfcBaloon.dElement.prototype = ___prototype(DOMel(jfcBaloon.dElement), changeJSON);
	}
	jfcBaloon.___innerHTML = '';
	jfcBaloon.___url = '';
}

function baloonClick(event)
{
//hide if href click //IE 7 Bug
    if ( !event )
    {
        event = window.event;
    }
    var target = event.target ? event.target : event.srcElement;
    if(target.tagName=='a' || target.tagName=='A')
        _hideBaloon();
}

