/************************
Script by Mamed Mamedov.
Desc: GenieSpace.GenieTip
      A sticky tooltip script
      An object-based version
Date: 26.10.2007 23:21
************************/
genieSpace.genieTip = {

    o: null,
    g: false,
    t: false,
    attrList: [ 'title', 'alt' ],
    attrName: 'genieTip',
    delay: 200,
    nl2br: '  ', //new line entity



    defineObject: function( searchString ){
        if( ! searchSting )
        {
            return false;
        }
        this.o = $( searchString );
        return true;
    }, //defineObject

    attrAdd: function( stringName ){
        if( ! stringName )
        {
            return false;
        }
        this.attrList.push( stringName );
        return true;
    }, //attrAdd

    attrClearAll: function( ){
        this.attrList = [ ];
    }, //attrRm

	_: function( s ){
		s = s.replace( /\&/g, "&amp;" );
		s = s.replace( /\</g, "&lt;" );
		s = s.replace( /\>/g, "&gt;" );
		return s;
	},

    s: function( tip, x, y ){
        x = ( x + 10 ) + 'px';
        y = ( y + 10 ) + 'px';
        $( this.o ).css( {
            left: x
          , top:  y
        } );

        if( ! this. g )
        {
            var self = this;
            this.t = setTimeout( function( ){
//                tip = self._( tip );
                if( self.nl2br )
                {
                    tip = tip.replace( eval( '/' + self.nl2br + '/gi' ), '<br />' );
                }
                $( self.o ).html( tip ).show( );
            }, self.delay );
            this.g = true;
        }
    }, //s (showTip)

    h: function( ){
        if( this.g )
        {
            var self = this;
            $( this.o ).hide( );
            clearTimeout( self.t );
            this.g = false;
        }
    }, //h (hideTip)

    setCss: function( hashCss ){
        jQuery( this.o ).css( hashCss );
    }, //addCss

    reTip: function( ){
        var self = this;
        jQuery.each( this.attrList, function( i, a ){
        	$('*[@' + a + ']')
                .attr( self.attrName, function( ){ return $( this ).attr( a ); } )
        		.mousemove( function( e ) {
                    self.s( $( this ).attr( self.attrName ), e.pageX, e.pageY );
                } )
        		.mouseout( function( ) { self.h( ); } )
        		.click(function( ) { self.h( ) } )
                .removeAttr( a )
                ;
        } );
    }, //reTip

    init: function( ){
        this.o = $( '<div id="genieTip" class="tooltip" />' ).appendTo( 'body' );
        this.reTip( );
    } //init
}

jQuery( document ).ready( function( ){
    with( genieSpace.genieTip )
    {
        init( );
    }
} );