
var searchTab = false;
 

function searchSelect( type ) {    

  if(!searchTab)
    searchTab = $('#searchType').val();
   
   if(!searchTab) searchTab="all";

   if(!sTabs[searchTab]) {
     zTab='all';
   } else zTab=searchTab;

    $( '#searchTab_' + searchTab ).removeClass('selected');
    $( '#searchTab_'+type ).addClass( 'selected' );
    
    $( '#searchType').val( type );

    var sel =  $( '#searchBox' );
    
    if(sTabs[type]) {
    
     sTabs[zTab]= sel.html() ;
     sel.html( sTabs[type] );
    
    } else {
     
     sTabs[zTab]=sel.html();

     sel.html( sTabs['all']);
    
    }
    
    switch(type) {
     case "address":
           currentCity = $("#searchCity").val();
           $("#sys_sStreet").autocomplete({url:'/mapd/load/loadStreet.php',delay:250,cacheLength:1,extraParams:{cityId:mapD.id},formatResult: function(data,position,number) { return "'"+position+"'"; } });
            $("#sys_sHouse").autocomplete({url:'/mapd/load/loadHouse.php',delay:250,minChars:0,cacheLength:1,formatResult: function(data,position,number) { return "'"+position+"'"; },extraParams:{cityId:function() { return mapD.id; },street:function() {return $('#sys_sStreet').val()}} });

            $("#sys_sStreet").autocomplete("result",function(event,data,formatted) { 

            $("#sys_sHouse").autocomplete("flushCache");

            } 
           );
     break;

    }

    searchTab = type;
}


    function baloon_get( obj )
    {
        if( !obj.baloon )
        {
            var html = obj.id && $( '#' + obj.id + '-baloon' ).html() ? $( '#' + obj.id + '-baloon' ).html() : '(нет описания)';
            var baloon = $('<div> ' + html + ' </div>').get();
            
            $( baloon ).addClass( 'baloon-window' );
            $( baloon ).css('position', 'absolute');
            $( baloon ).hide();
            $( baloon ).appendTo( $( document.body ) );
            
            obj.baloon = baloon;
        }

        return obj.baloon;
    }
    
    function test_mousemove( e )
    {
        
        var baloon = baloon_get( this );
               
        if( $( baloon ).css( 'display' ) != 'block' )
            $( baloon ).show();
        
        $( baloon ).css( 'left', ( e.pageX + 10 ) + 'px' );
        $( baloon ).css( 'top',  ( e.pageY + 10 ) + 'px');
        $( baloon ).css( 'zIndex',  60000);

    }
    
    
    function test_mouseout()
    {
        $( this.baloon ).hide();
        $( this ).unbind( 'mousemove', test_mousemove );
    }
    
    
    
    function test_mouseover()
    {
        $( this ).bind( 'mousemove', test_mousemove );
    }
    
