/* effet fondu avant apres
 * pour MarieB decoration
 * categorie homestaging
 * realisation
 */

 
 
    var fadinghome = function ( container , options ){
    
    var t = this;
    
    this.settings = {
            'animationtype':    'fade',
            'speed':            2000,
            'timeout':          2000,
            'children':         null
        };
        
        //merge des options
        if (options)
            $.extend(this.settings, options);
 
    //si pas deja definie
    if (this.settings.children === null)
            this.elements = $(container).children('img');
        else
            this.elements = $(container).children(this.settings.children);
    
    //creation de deux liens
    this.afterHome =  $('<a href="#" title="apres" class="after" ><span>Apr&#232;s</span></a>');
    this.previousHome =  $('<a href="#" title="avant" class="previous" ><span>Avant</span></a>');
    
    
    $(container).append(this.previousHome);
    $(container).append(this.afterHome);
    
    
    $(container).append('<div id="left-c">&#160;</div>');
    $(container).append('<div id="right-c">&#160;</div>');
    
    this.is_moment = $('<p id="is_moment">Avant</p>');
    //this.is_moment.css({'font-size' : '25px'});
    
    $(container).append(this.is_moment);
    
    
    //passe a la deuxieme image
    this.after = function(){
    
    var p = t;
           
           var img2 = p.elements.get(1);
           
           if($(img2).css('display') == 'none' ){
               
               $(img2).fadeIn(p.settings.speed);
           
               
           
           }
           //masque les boutons
           $(p.afterHome).addClass('active');
           $(p.previousHome).removeClass('active');
           $(p.previousHome).css({ opacity : 1. });
           $(p.afterHome).css({ opacity : .6});
           $(p.is_moment).html('Apr&#232;s');
           
    return false;
    
    }
    
    
    //passe a la deuxieme image
    this.previous = function(){
    
    var p = t;
           
           var img2 = p.elements.get(1);
           
           $(p.elements.get(0)).show();
           
           if($(img2).css('display') == 'inline' ){
           
               $(img2).fadeOut(p.settings.speed);
               
               
           }
            //masque les boutons
           $(p.previousHome).addClass('active');
           $(p.afterHome).removeClass('active');
            $(p.afterHome).css({ opacity : 1. });
           $(p.previousHome).css({ opacity : .6 });
           $(p.is_moment).text('Avant');
    return false;
    
    }

    
    
    //event sur lien
    $(this.previousHome).click(this.previous);
    $(this.afterHome).click(this.after);
    
    //rend visible la premiere photo
    this.previous();
    
    
    }
    
/*INTRO HOME*/

 $(function(){
    
    $('#presentation_home li:first').each(function(){
    
        $(this).slideDown('slow',function(){
        
        
            $(this).next('li').slideDown('slow',function(){
            
            
                $(this).next('li').slideDown('slow',function(){
        
        
                }); 
        
            });       
        
        });
        
      });
      
    $('.img_presentation').each(function(){
    
         $(this).css('opacity' , .8);
    
         $(this).mouseover(function(){
         
             $(this).css('opacity' , 1.);
         
         });
         
         $(this).mouseout(function(){
         
             $(this).css('opacity' , .8);
         
         });
    
    });  
      
    
    });


    
    
/*EFFET BUBBLE CODA*/


/*$(function () {
        $('.bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 1.);
            var coo_popup = $('.popup').height();
            

            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: - (coo_popup),
                        //left: -33,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });    */
    
    
    
    $(function () {
    
        $('.bubbleInfo').each(function () {
            
            
            
            var time = 250;
            var hideDelay = 200;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var parent = $(this).parent();
            var info = $('.popup', parent);
            var imag = $('img.img_presentation' , parent);
            

            $(trigger).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        display: 'block'
                    });
                    
                    
                    info.animate({
                    opacity : 1
                    });
                    
                    imag.animate({
                        opacity: 0
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    
                    info.animate({
                    opacity : 0
                    });
                    
                    imag.animate({
                        
                        opacity: 0.8
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    }); 


