/************************************
 * CSS Document FYSIKI **************
 * Objets Tip ***********************
 ************************************
 * @création 26/11/2009
 * @modification 20/12/2009
 * @auteur: Julien Lavault
 *
 * @version 0.9
 *
 * L'objet Tips permet de créer des
 * infos bulles personnalisables.
 *
 * Le texte affiché prend en paramètre
 * la balise title de l'élément
 * sélectionné
 *
 ************************************/

    /**
     * Object Tips
     *
     * Cet objet permet d'afficher des Tips (infos bulles) au
	 * survol d'un élément suivant une class css
     *
     * Opérations effectuées
     *  - construct: créer la tips et affiche le texte de la
     *  balise title
     *
    **/

    var Tips = {
		
		 text : new String(),
		 title : new String(),

         contruct : function (element, pos) {
            // Ecouteur d'événement
            $(element).bind('mouseenter', function() {
                // Init de la tip (titre et contenu)
                Tips.text = $(this).attr('title');
                Tips.title = $(this).text();
				$(this).attr({'title':''});
                $('#livetip strong').html(Tips.title);
                $('#livetip span').html(Tips.text);
                $(this).after($('#livetip'));
                // Positionnement de la Tips
                var width = $(this).width();
                var height = $(this).height();
                var position = $(this).position();
                var x = position.left;
                var y = position.top;
                var tipWidth = $('#livetip').width();
                var tipHeight = $('#livetip').height();

                // On affiche la tip en fonction de Pos
                if(pos == 'left') {
                    var posX = x - tipWidth + 10;
                    var posY = y;
                } else if(pos == 'right') {
                    var posX = x + 10;
                    var posY = y;
                } else if(pos == 'top') {
                    var posX = x - 230;
                    var posY = y - tipHeight;
                } else if(pos == 'bottom') {
                    var posX = x;
                    var posY = y + height + 10;
                }
				var posX = x - 15;
				var posY = y - tipHeight;

                // On lance l'affichage de la tip
                $('#livetip').css({ 'top': posY, 'left': posX}).fadeIn(200);

            // On masque la tip
            }).bind('mouseleave', function(event) { $(this).attr({'title':Tips.text}); $('#livetip').fadeOut(200);});
		 }
    }
