﻿/*
**  Utilisation de la librairie jQuery
**  http://docs.jquery.com/Downloading_jQuery#Download_jQuery
*/

jQuery.noConflict();
jQuery(function($) {

   
    // BEGIN Carousel
    if($('#carousel').length) {
    
        var $list       = $('#carousel ul');
        var $nbItems    = $list.find('li').length;
        var $transition = false;
        var $delay      = 10000;
        var $speed      = 2000;
        var $index      = 0;
        var $i          = 0;
    
        // Passe a l'element precedent
        function prev() {
            if($index <= 0) {
                $index = $nbItems-1;
            } else {
                $index--;
            }
            showPicture($index);
        }
        
        // Passe a l'element suivant
        function next() {
            if($index >= $nbItems-1) {
                $index = 0;
            } else {
                $index++;
            }
            showPicture($index);
        }
             
        // Affiche l'element passe en parametre
        function showPicture($index) {
            $transition = true;
            $list.find('li.active').removeClass('active').addClass('oldActive').css('z-index', 3);
            $list.find('li:eq('+$index+')').addClass('active').css('z-index', 4).fadeIn($speed, function() {
                $list.find('li.oldActive').removeClass('oldActive').hide();
                $transition = false;
            });
        }
        
        // Changement automatique
        function makeInterval() {
            $carouselInterval = setInterval(function() {
                if($transition == false) {
                    next();
                }
            }, $delay);
        }
        
        // Changement manuel
        $('#carousel nav').find('a').click(function(e) {
            e.preventDefault();

            if($transition == false) {
                if($(this).hasClass('prev')) {
                    prev();
                } else if($(this).hasClass('next')) {
                    next();
                }
            }
        });
        
        // Arret du changement automatique a l'entree du carousel
        $('#carousel').bind('mouseenter focus', function() {
            clearInterval($carouselInterval);
        });
        
        // Redemarrage du changement automatique a la sortie du carousel
        $('#carousel').bind('mouseleave blur', function() {
            clearInterval($carouselInterval);
            makeInterval();
        }); 
        
        // Cree le texte en fonction du alt de l'image
        $('#carousel').find('li img').each(function() {
            $(this).after('<span>' + $(this).attr('alt') + '</span>');
        }); 
        
        $list.find('li:first-child').addClass('active');
        makeInterval();
        
    }
    // END Carousel
    
    
    // BEGIN Projets
    if($('#projets').length) {
    
        function showProjectInfos() {
            $(this).find('.infos').fadeIn(400);
        }
        
        function hideProjectInfos() {
            $(this).find('.infos').fadeOut(400);
        }
    
        $('#projets').find('li').hoverIntent({    
            over: showProjectInfos,
            timeout: 100,
            out: hideProjectInfos
        });    

    }    
    // END Projets
    
    
    // BEGIN Clients-List
    if($('#clients-list').length) {
    
        $('#clients-list').find('.list span').click(function(e) {
            var $item = $(this).parents('li').find('ul:hidden');
            $('#clients-list').find('.list ul').slideUp();
            $item.slideDown();
        });
        
        $('#clients-list').find('.list a').click(function(e) {
            e.preventDefault();
            window.open(this.href);
        });
        
    }    
    // END Clients-List
        
        
    // BEGIN Contact
    if($('#file').length) {
        $('#file').inputfile();
    }	
    // END Contact
    
    
    // BEGIN IE6
    if($('html.ie6').length) {
        $('html.ie6').find('body').prepend('<div class="warning-obsolete">Attention, votre navigateur est obsolète, des problèmes d\'affichage peuvent survenir sur cette page. Pour y remédier, nous vous conseillons de <a href="http://windows.microsoft.com/fr-FR/internet-explorer/products/ie/home">le mettre à jour</a>.</div>');
    }    
    // END IE6    

}); /* jQuery end */
