/**
 * copyright	Copyright (C) 2010 Cédric KEIFLIN alias ced1870 & Ghazal
 * http://www.ck-web-creation-alsace.com
 * http://www.joomlack.fr.nf
 * license		GNU/GPL
 * version : 2.0
**/

//pour Moo 1.11, remplacer Morph par Style ou Styles, fx.cancel par fx.stop


	Element.extend({
		createFxTooltipgc: function() {
			// crée les fonctions mootools
			this.FxTooltipgc = new Fx.Style(this.span, 'width', {duration:this.dureemootools, wait : false});
			this.offsetTooltipgc = new Fx.Style(this.span, 'margin-top', {duration:this.dureemootools, wait : false});
			this.opacityTooltipgc = new Fx.Style(this.span, 'opacity', {duration:this.dureemootools, wait : false});
			
			// fixe les valeurs par défaut
			if (this.activationjs == 1) {
				this.FxTooltipgc.set(0);
				this.opacityTooltipgc.set(0);
			}
			this.span.setStyle('left','-999em');
			this.span.setStyle('margin-top',-this.spanheight);
			
			
			animComp = function(){
					if (this.status == 'hide')
					{
						this.span.setStyle('left', '-999em');
						this.hidding = 0;
					}
					this.showing = 0;
					this.span.setStyle('overflow', '');				
					
				}
			this.FxTooltipgc.addEvent ('onComplete', animComp.bind(this));
		},
		
		showTooltipgc: function() {
			this.status = 'show';
			this.addClass('sfhover');
			this.animTooltipgc();
		},
		
		removeClassTooltipgc: function() {
			this.removeClass('sfhover');
			this.animTooltipgc();
		},
		
		hideTooltipgc: function(timeout) {
			this.status = 'hide';
			
			clearTimeout (this.timeout);
			if (timeout) {	
				this.timeout = setTimeout (this.removeClassTooltipgc.bind(this), timeout);
			}else{
				this.removeClass('sfhover');
			}
		},
		
		animTooltipgc: function() {
			if ((this.status == 'hide' && this.span.style.left != 'auto') || (this.status == 'show' && this.span.style.left == 'auto' && !this.hidding) ) return;
					
				this.span.setStyle('overflow', 'hidden');
				if (this.status == 'show') {
					this.hidding = 0;
				}
				if (this.status == 'hide')
				{
					this.hidding = 1;
					this.showing = 0;
					if (this.activationjs == 1) {
						this.FxTooltipgc.stop();
						this.opacityTooltipgc.start(1,0);
					} else {
						this.opacityTooltipgc.set(0);
					}

				} else {
					
					this.showing = 1;
					this.span.setStyle('left', 'auto');
					if (this.activationjs == 1) {
						this.FxTooltipgc.stop();
						this.FxTooltipgc.start(0,this.spanwidth);
						this.opacityTooltipgc.start(0,1);
						this.offsetTooltipgc.start(0,-this.spanheight);
					} else {
						this.opacityTooltipgc.set(1);
					}
				}
		}
		
	});
	
	var tooltipClass = new Class({
        Implements: Options,
						
        options: {  
			largeur : '150px',
			dureemootools : 300,
			dureebulle : 500,
			activationjs : '1'
        },
		initialize: function(el,options) {
			this.setOptions(options); //enregistre les options utilisateur
			var largeur = this.options.largeur;
			el.dureemootools = this.options.dureemootools;
			el.dureebulle = this.options.dureebulle;
			el.activationjs = this.options.activationjs;
			
			el.span = el.getElement('span.tooltipgc_tooltip');
			
			if (el.span.clientWidth != 0) el.spanwidth = el.span.clientWidth;
			el.spanheight = el.span.clientHeight;
			
			el.createFxTooltipgc();
				
			el.addEvent('mouseover',function() {	
				this.showTooltipgc();
			});
				
			el.addEvent('mouseleave',function() {
				this.hideTooltipgc(this.dureebulle); 						
			});

		}
	});

tooltipClass.implement(new Options);


