if(jQuery.browser.safari )       {jQuery('body').addClass('safari-browser');}
if(jQuery.browser.mozilla )    {jQuery('body').addClass('mozilla-browser');}
if(jQuery.browser.msie )        {jQuery('body').addClass('msie-browser');}

/*
 * Conversion de chaine en slug
 *
 */

function string_to_slug(str) {
    str = str.replace(/^\s+|\s+$/g, ''); // trim
    str = str.toLowerCase();

    // remove accents, swap ñ for n, etc
    var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
    var to   = "aaaaeeeeiiiioooouuuunc------";
    for (var i=0, l=from.length ; i<l ; i++) {
        str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
    }

    str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
    .replace(/\s+/g, '-') // collapse whitespace and replace by -
    .replace(/-+/g, '-'); // collapse dashes

    return str;
}

/** ******************************************************************** **/
/*                                                                                                                       */
/*                      CHARGEMENT DES DESTINATIONS                                     */
/*                                                                                                                      */
/*                       S'il n'y a pas de pays défini il faut charger                      */
/*                        l'ID du pays par défaut  souhaité                                     */
/*                        ICI LA FRANCE = "1"                                                           */
/ *                                                                                                                       */
/*                                                                                                                        */
/** ********************************************************************* **/


function loadDestinations (json_url, item_actif )
{


    //Valeurs par défaut :
    var defaultValue = '1066';
    var json = ( typeof(json_url) != 'undefined') ? json_url : './data/destinations_fr.json';
    var inputValue = $('form:visible').find('.fields input[type="hidden"]').val();

    $.getJSON(json, function(data)
    {
        //Tableau qui va être parser pour chercher les id passés en variable
        var partsActif ='';
        var setActive ='';

        //Création de l'objet accueillant les valeurs récupérées :
        var selectedItem = new Object();
        var getItem = new Object();

        if( (typeof(item_actif) == 'undefined') && (inputValue !== '' || inputValue !== 'undefined'))
            {
                item_actif = $('form:visible .fields input[type="hidden"]').val();
            }

        // Cas où il y a un pays/une région préselectionnée:
        if(typeof(item_actif) != 'undefined' && item_actif !== '')
        {
            partsActif = item_actif.split('-');          // Dissociation du pays et de la région

            //Si l'id du pays existe dans le json
            if(typeof(data[partsActif[0]])!= 'undefined')
                {
                        // Affectation de l'id et du nom du pays
                        getItem.c_id = partsActif[0];
                        getItem.c_name = data[getItem.c_id].country_name;

                        //Affectation de l'id et du nom de la région si elle existe en tant que paramètre et dans le json
                        if ( ( typeof(partsActif[1] ) != 'undefined') && (typeof(data[getItem.c_id].regions[partsActif[1]]) != 'undefined' ) )
                        {
                                 getItem.r_id = partsActif[1];
                                 getItem.r_name = data[partsActif[0]].regions[partsActif[1]].name;

                                 selectedItem.id = getItem.c_id+"-"+getItem.r_id;
                                 selectedItem.name = getItem.r_name;
                        }
                        else
                       {
                           selectedItem.id =getItem.c_id;
                           selectedItem.name =getItem.c_name;
                       }

                }
                else
                {
                    selectedItem.id = defaultValue;
                    selectedItem.name = data[defaultValue].country_name
                }

                //Affiche des valeurs :
                $('form:visible .select-box .selector span').html(selectedItem.name);
                $('form:visible .fields input[type="hidden"]').val( selectedItem.id );
        }
        else
        {
            getItem.c_id = defaultValue;
        }

        //var data = data[0];
        var countries = [];
        var regions = [];
        var markers = [];

        var $home = $('body').is('#home');

        $.each(data, function(country_id, items)
        {
            var setActive = (country_id == getItem.c_id)? 'active' : '';
            var countrySlug = string_to_slug(items.country_name);

            regions = [];

            countries.push('<li class="'+setActive+'"><a rel="'+countrySlug+'" data="'+country_id+'" title="'+items.country_name+'"><span>-</span> ' + items.country_name + '</a></li>');
            regions.push('<li class="title"><a rel="'+countrySlug+'" data="'+country_id+'"  title="'+items.country_name+'"><span>-</span> ' + items.country_name + '</a></li>');

            $.each(data[country_id].regions, function(region_id, item)
            {
                // Liste des régions -> select
                regions.push('<li><a rel="'+string_to_slug(item.name)+'" data="'+country_id+'-'+region_id+'"  title="'+item.name+'"><span>&rsaquo;</span> ' + item.name + '</a></li>');
                // Liste des régions -> map
                if($home)
                    markers.push('<a rel="'+string_to_slug(item.name)+'" title="'+item.name+'" href="'+item.url+'"style="top: '+item.coordy+'px; left:'+item.coordx+'px;"></a>');
            });
            $('<ul/>', {
                'id': countrySlug,
                'class': 'regions '+setActive,
                html: regions.join('')
            }).appendTo('.regions-container');
        });

        $('<ul/>', {
            'class': 'countries',
            html: countries.join('')
        }).appendTo('.countries-container');

        if($home)
        {
            // CONSTRUCTION DE LA MAP
            $('<div/>', {
                'class': 'markers',
                html: markers.join('')
            }).appendTo('#dynamic-map .content');

            // AFFICHAGE DES MARKERS
            $('.markers a').each(function(index){
                var time = index*100;
                $(this).delay(time).fadeIn();
            });
            $('.markers a[title]').tooltip({
                tipClass: 'tooltip-map',
                delay: 10,
                effect: 'fade',
                layout: '<div><span/></div>',
                offset: [0, 0]
            });
        }

    }).error(function() {
        console.log("erreur au chargement du fichier");
    });

}


/*************************************************************/
/*
 *  Pagination auto sur les blocs ayant la structure
 *
 *  container class=paginate
 *     |->fils class=panes
 *     |->pagination class=pagination > ul
 *
 **************************************************************/
 function paginate ()
 {
    $(".paginate").each(function(index){
        ;
        $(".paginate:eq("+index+") .pagination ul").tabs(".paginate:eq("+index+") .panes > article", {
            autoplay: false,
            effect: 'fade',
            fadeOutSpeed: "slow",
            rotate: false
        }).slideshow({clickable : false});
    });
 }



/*************************************************************/
/*
 *  ASIDE ESPACE PERSO
 *
 **************************************************************/

function sidebar(openClose)
{
    if(openClose == 'close')
        {
           var _x = ($('aside#espace-perso-kawan').hasClass('smallscreen')) ? '-945px':'-900px';
            $('aside#espace-perso-kawan').animate({
                left: _x
            }, {
                duration: 500,
                specialEasing: {
                    left: 'easeInQuart'
                },
                complete: function() {
                    $('aside#espace-perso-kawan').removeClass('deployed');
                }
            });
        }
    else
        {
            var _x = ($('aside#espace-perso-kawan').hasClass('smallscreen')) ? '-200px':'0';
            $('aside#espace-perso-kawan').animate({
                left: _x
            }, {
                duration: 800,
                specialEasing: {
                    left: 'easeOutQuart'
                },
                complete: function() {
                    $('aside#espace-perso-kawan').addClass('deployed');
                    asidescroll();
                }
            });
        }
}

function asidescroll()
{
    var $items = $('aside#espace-perso-kawan .items');
    var $item   = $('aside#espace-perso-kawan .items a');

    var $prev = $('aside#espace-perso-kawan .actions a.prev');
    var $next = $('aside#espace-perso-kawan .actions a.next');

    $items.css({'top':0});
    $next.removeClass('disabled');
    $prev.addClass('disabled');

$('aside#espace-perso-kawan .actions a').live('click', function(event){
     event.preventDefault();
    $direction = ($(this).hasClass('next')) ? '-=' : '+=';

    $height = $item.outerHeight();
    $boxHeight = $item.length * $height;

    if( $(this).hasClass('disabled') == false)
        {
            $('aside#espace-perso-kawan .items').animate({
                        top: $direction+($height*2)
                    }, {
                        duration: 400,
                         queue: false,
                        specialEasing: {
                            top: 'easeInCubic'
                        },
                        complete: function() {
                            if($items.position().top >= 0)
                                {
                                    $prev.addClass('disabled');
                                }
                             else
                                {
                                     $prev.removeClass('disabled');
                                }

                            if( -($items.position().top - $height - 2) >=   $boxHeight)
                                 {
                                     $next.addClass('disabled');
                                 }
                            else
                                {
                                    $next.removeClass('disabled');
                                }
                        }
                    });
                }
        });
}

/*************************************************************/
/*
 *  TUNEL D'ACHAT
 *
 **************************************************************/
var loadForms = function(form)
{
    var $rel = (typeof form.rel != 'undefined') ? form.rel : '';
    var $form = (typeof form.ref != 'undefined') ? form.ref : alert("le formulaire de référence n'est pas initialisé");
    var  $loading = '<div id="loading"><div></div></div>';

    $($form).live('submit', function(event)
    {
        event.preventDefault();
        $url = $(this).attr('action');
        $(this).css({'opacity':'0.5'});

        $formData = $(this).serialize();
        if($('#cart-forms').find('#loading') > 0)
            $('#loading').fadeIn();
        else
            $($loading).prependTo('#cart-forms').fadeIn();

                $.post($url+$rel , $formData)
                    .success(function() {
                        $('#content-cart').fadeOut().empty();
                    })
                    .error(function() {alert("error");})
                    .complete(function()
                    {
                        getForm(form, $formData);
                    });
      });
}

var animateStep = function($stepNumber)
{

    $nextStep = $('#body-cart ul.tabs').find('li[rel="'+$stepNumber+'"]');
    $left = $nextStep.position().left;

    $('.step-arrow').animate({
        'left':$left
    },
    {
        duration: 600,
        specialEasing:
        {
            left: 'easeOutQuart'
        },
        complete: function()
        {
            $('#body-cart ul.tabs').find('.current').addClass('do').removeClass('current');
            $nextStep.addClass('current');
        }
    });
}


var getForm = function(form, $formData)
{
    var $rel = (typeof form.rel != 'undefined') ? form.rel : '';
    if (typeof form.url != 'undefined') $url = form.url ;
    var $form = (typeof form.ref != 'undefined') ? form.ref : console.log("le formulaire de référence n'est pas initialisé");

    var $stepNumber = 0;

    if($form == '#panier_options') $stepNumber = 0;
    if($form == '#step-identification') $stepNumber = 4;
    if($form == '#step-accompanying') $stepNumber = 3;
    if($form == '#step-end') $stepNumber = 5;

    $.get($url+$rel , $formData, function(data)
    {
        $('#content-cart').empty().html(data).fadeIn('fast', function(){
            $('#loading').fadeOut();
        });

        if($('#step-accompanying input[name^="firstName"]').length > 0)
            {
                $('#content-cart input[name^="firstName"]').parent().removeClass('c50l').addClass('c50r');
            }

        $("select,  input:radio, input:checkbox").uniform();
        animateStep($stepNumber);
    });

}

/*************************************************************/
/*
 *  MENU PRINCIPAL
 *  Création de bloc alignés à gauche
 *  Quand le 3 niveau contient plus d'éléments que
 *  $breakNumber
 *
 **************************************************************/

function create_break($number, $referrer)
{
    $breakNumber = $number;
    $c=0;
    $g = 1;

    $($referrer).each(function(index){
        $length = $('li',$(this)).length;
        $(this).addClass('third-level');
        if($length > $breakNumber)
        {
            $('li',$(this)).each(function(i)
            {
                $(this).addClass('group-'+$g)
                if($c == $breakNumber || $length == (i+1))
                {
                    $first = ($g == 1)? 'first' : '';
                    $last = ( $length == (i+1))? 'last' : '';
                    $('.group-'+$g).wrapAll('<li class="left '+$first+' '+$last+' "><ul></ul></li>');
                    $c = 0;
                    $g = $g+1;
                }
                $c++;
            });
        }
    });
}

/*******************************************************************************************************************************************************/
/*
 *  GESTION DES DATES & MOTEUR DES BLOCS
 *  Création d'un fonction pour les dates afin de passer
 *  des paramètres sur les dates de départs et d'arrivée
 *  ainsi que la gestion de l'initilisation des champs pour les
 *  formulaires visibles/invisibles
 *  cf http://flowplayer.org/tools/dateinput/index.html
 *
 *  @DEPENDS : Library : jquerytools
 *
 *
 *  params =
 *  {
 *      date_start : date de départ
 *      date_end : date de retour
 *      lang : langue du calendrier
 *      index : tabs à afficher
 *  }
 *
 *
 **************************************************************/
  //

function initDate (params)
{
     var o = (typeof params == 'undefined') ? { } : params;
     var start = (typeof o.date_start == 'undefined') ? null : dateConvert(o.date_start);
     var end = (typeof o.date_end == 'undefined') ?  null  : dateConvert(o.date_end);
     var lang =  (typeof o.localize == 'undefined') ? 'fr' : o.lang;
     //var form = (typeof o.index  == 'undefined') ? '#'+$('.panes form').eq(0).attr('id') : '#'+$('.panes form').eq(o.index).attr('id');
     var form ='';
     if (typeof o.index  == 'undefined' && typeof o.form == 'undefined')
         {
             form = "#"+$("form").has('input.date').attr('id');
         }
     else
         {
             if ( typeof o.form != 'undefined')
                 {
                     form = o.form;
                 }
             else
                 {
                    form = (typeof o.index  == 'undefined') ? '#'+$('.panes form').eq(0).attr('id') : '#'+$('.panes form').eq(o.index).attr('id');
                 }

         }
         /***Regionalisation des langues pour le calendrier*/

    $.tools.dateinput.localize("en", {
        months: 'January,February,March,April,May,June,July,August,September,October,November,December',
        shortMonths:  'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec',
        days:         'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday',
        shortDays:    'Sun,Mon,Tue,Wed,Thu,Fri,Sat'
    });

    $.tools.dateinput.localize("fr",  {
        months:      'janvier,f&eacute;vrier,mars,avril,mai,juin,juillet,ao&ucirc;t,septembre,octobre,novembre,d&eacute;cembre',
        shortMonths: 'jan,f&eacute;v,mar,avr,mai,jun,jul,ao&ucirc;,sep,oct,nov,d&eacute;c',
        days:        'dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi',
        shortDays:   'dim,lun,mar,mer,jeu,ven,sam'
    });

    /*** Initialisation des champs dates visible ***/
     $(form+" input.date").dateinput({
            format: 'dd/mm/yy',
            lang:lang,
            offset: [0, 0],
            trigger: true,
            min: +1,
            max: +360
        });

        $(form +" input.depart").data("dateinput").setValue(start);
        $(form +" input.arrivee").data("dateinput").setValue(end);


    $(form +" input.depart").data("dateinput").change(function() {
            $(form +" input.date.arrivee").data("dateinput").setMin(this.getValue(), true);
    });

    if($(form).hasClass('panes') || $(form).parent().hasClass('panes') )
        {
            tabsDate(params);
        }
}

/*** Initialisation des champs dates du formulaire masqué ***/

function tabsDate(params)
{
     var api = $("nav.tabs").data('tabs');
     var o = (typeof params == 'undefined') ? { } : params;
     api.onClick(function()
     {
         $dom_elt = this.getIndex();
         o.index = $dom_elt;
         initDate(o);
     });
}

function dateConvert (date)
{
    d = date.split('/');
    return '20'+d[2]+'-'+d[1]+'-'+d[0];
}

/*************************************************************/
/*
/*  GESTION DES BLOCS MOTEURS DE RÉSA
/*  Afin d'automatiser le fonctionnement des blocs moteurs
/*  de résa avec onglet
/ * mise en place d'un fonction tabs contentant le initDate
/*
/*************************************************************/

function formTabs(tabs, panes, params)
{
     var o = (typeof params == 'undefined') ? { } : params;

     if (typeof o.index == 'undefined')
         {
             $(tabs).tabs(panes);
         }
     else
         {
             $(tabs).tabs(panes, {initialIndex: o.index});
         }

     initDate(params);
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

jQuery(document).ready(function(){
    /** ********************************************************************* **/
    /*                                                                                                                        */
    /*                                               ALL PAGES                                                      */
    /*                                                                                                                        */
    /** ********************************************************************* **/

    if($(window).width() < 1060)
    {
        $('aside#espace-perso-kawan').animate({
            left: '-945px'
        }, 1000).addClass('smallscreen');

        $('aside#espace-perso-kawan').hover(
            function()
            {
                $(this).not('.deployed').stop(true, true).animate({
                    left: '+=45px'
                },
                {
                    duration: 200,
                    specialEasing: {
                        left: 'easeInQuart'
                    }
                })
            },
            function()
            {
                $(this).not('.deployed').stop(true, true).animate({
                    left: '-=45px'
                },
                {
                    duration: 200,
                    specialEasing: {
                        left: 'easeInQuart'
                    }
                });
            });
    }


    //------------  BARRE ESPACE PERSO KAWAN ------------//

$('aside#espace-perso-kawan h1').hover(function () {
        $(this).toggleClass('hover');
});


$('aside#espace-perso-kawan h1').live("click", function() {
        if($(this).parent().hasClass('deployed'))
        {
            sidebar('close');
        }
        else
        {
             sidebar();
        }
    });

    // TOOLTIP PICTOS

    $(" aside#espace-perso-kawan a.cart[title]").tooltip({
        tipClass: 'infos-pictos-tooltip cart',
        offset: [5, 0],
        effect: 'slide'
    }).dynamic({
        bottom: {
            direction: 'down',
            bounce: true
        }
    });

$("aside#espace-perso-kawan a.heart[title]").tooltip({
    tipClass: 'infos-pictos-tooltip heart',
    offset: [5, 0],
    effect: 'slide'
}).dynamic({
    bottom: {
        direction: 'down',
        bounce: true
    }
});
/*
$('aside#espace-perso-kawan .scrollable').scrollable({
    vertical: true,
    mousewheel: true
});*/

//------------  MENU ------------//

create_break(7, $('nav.multi-level ul > li ul'));

$('nav#nav-main .multi-level > ul > li > a').addClass('title');

$('nav#nav-main > ul').children('li').not('.last').hover(
    function () {
        $(this).addClass('hover').css({'z-index' : 100});
        if($(this).has("nav").length == 1 )
        {
            $('nav',this).stop(true, true).css('display','block').animate({
                top: '54px',
                opacity:1
            }, {
                duration: 500,
                specialEasing: {
                    top: 'easeOutQuint',
                    opacity: 'easeOutCubic'
                },
                queue: false,
                complete: function(){
                    if($(this).is(".multi-level"))
                         {
                             if($('.multi-level > ul li').hasClass('active') == false)
                                 {
                                    $('.multi-level > ul li').first().addClass('active').children('.third-level').stop(true, true).fadeIn();
                                 }

                             $('.title').live(
                             {
                                    mouseover: function()
                                        {
                                                    $('.multi-level li.active .third-level').stop(true, true).fadeOut();
                                                    $('.multi-level li').removeClass('active');
                                                    $(this).parent().addClass('active');
                                                    $(this).next('.third-level').stop(true, true).fadeIn();
                                        },
                                   mouseout: function()
                                        {

                                        }
                         });
                     }
                }
            }).end();
        }
    },
    function () {
        $(this).removeClass('hover').css({'z-index' : 2});
        if($(this).has("nav").length == 1 )
        {
            $('nav',this).stop(true, false).animate({
                top: '-180px',
                opacity:0
            }, {
                duration: 700,
                specialEasing: {
                    top: 'easeInQuint',
                    opacity: 'easeInCubic'
                },
                queue: false,
                complete: function(){
                    $(this).css('display','none');
                }
            }).delay(800).end();
        }
    }
);


//------------ BARRE DE LANGUE ------------//

$('#languages li.bt').click(function(){
    if($(this).parent().hasClass('deployed'))
    {
        $(this).nextAll().not('.current').slideUp();
        $(this).parent().removeClass('deployed');
    }
    else
    {
        $(this).nextAll().slideDown();
        $(this).parent().addClass('deployed');
    }
});

$('#languages').mouseout(function(){
    if($(this).hasClass('deployed'))
    {
        $(this).children().not('.current').not('.bt').delay(1100).slideUp();
        $(this).delay(1100).removeClass('deployed');
    }
});

//------------ RETOUR HAUT DE PAGE ------------//

$('a.top-of-page').click(function(){
    var targetOffset = $('body').offset().top;
    $('html,body').animate({
        scrollTop: targetOffset
    }, 1000);
});

//------------ LISTES OL SURCHARGEES ------------//


if($('body').find('ol.ol').length > 0)
{
        $('ol.ol').each( function(  ) {
            $('li', this).each( function( index ) {
                var i = index+1;
                if($(this).has('span.disc-number').length == 0 )
                    $(this).prepend('<span class="disc-number">'+i+'</span>');
            });
        });
    }

if($('body#search-results').length > 0)
    {
        $('body#search-results').ajaxSuccess(function() {
                    if($('body').find('ol.ol').length > 0)
                    {
                        $('ol.ol').each( function(  ) {
                            $('li', this).each( function( index ) {
                                var i = index+1;
                                if($(this).has('span.disc-number').length == 0 )
                                    $(this).prepend('<span class="disc-number">'+i+'</span>');
                            });
                        });
                    }
                });
    }





//------------ RIBBON ------------//

$('.kawan-selection').prepend('<div class="ribbon"></div>');


    //------------ WIDGET CONTACT ------------//

    $('#widget-contact h1').click(function(){
        $(this).toggleClass('active');
        //Not the shorter way because pie.htc change DOM and $(this).next('section') doesn't work.
        $('#widget-contact section').fadeToggle();
    });

    /*
$('#widget-contact section').mouseleave(function(){
    $(this).delay(500).fadeOut();
})
*/

    //------------ SLIDESHOW PRODUCT ------------//
    $slideWidth = 0;
    $('.slidetabs a').each(function() {
        $slideWidth += $(this).outerWidth(true);
    });
    $paddingLeft = Math.round( ($('.slidetabs').width() - $slideWidth) / 2)-6;
    $('.slidetabs a:first-child').css({
        marginLeft : $paddingLeft
    }).parent().fadeIn();

    //........................ END COMMUN ....................... .//


    /** ********************************************************************* **/
    /*                                                                                                                        */
    /*                                               HOME                                                              */
    /*                                                                                                                        */
    /** ********************************************************************* **/

    //------------ EFFET FOCUS ARTICLES ------------//

    $('.link-light article').hover(
        function () {
            $(this).siblings('article').stop(true, false).fadeTo("fast", 0.4);
        },
        function () {
            $(this).siblings('article').stop(true, false).fadeTo("fast", 1);
        }
        );

    //------------ FORMS TABS ------------//

    $("nav.tabs").tabs("div.panes > form");


    /** ********************************************************************* **/
    /*                                                                                                                        */
    /*                              TITRES BULLES                                                                */
    /*                                                                                                                        */
    /** ********************************************************************* **/

    /*--------------------------------------------------------------
 *
 * @CSS AND JQUERY GAME : auto-make bubbles title
 *
 * @DÉPENDANCES :
 *                          FILE : snippets.css
 *                          Class :  .cznbubble (snippets.css)
 *                          USE : Add Class 'cznbubble' on a selected element

 *
 *@TODO : create a real plugin
 *
 --------------------------------------------------------------*/

 $('.cznbubble').each( function() {
        $width = $(this).width()+10;
        $(this).css('width',$width).append('<sub class="czn-bubble">'
            +'<span class="cznBox"><span class="box" style="width:'+$width +'px"></span><span class="arrow" ></span></span>'
            +'<span class="cznShadow"><span class="box" style="width:'+$width +'px"></span><span class="arrow" ></span></span>'
            +'</sub>');
    });


    /** ********************************************************************* **/
    /*                                                                                                                        */
    /*                              FORMULAIRES                                                                 */
    /*                                                                                                                        */
    /** ********************************************************************* **/


    /******** Custum select *******/


    $('.selector').live('click', function()
    {
        $tPosition = ($.browser.msie)?$(this).position().top+$(this).outerHeight() +10 : $(this).position().top+$(this).outerHeight();
        $(this).toggleClass('active').parent().find('.fields')
        .css({
            'zIndex': '500',
            'top': $tPosition
        }).fadeToggle().toggleClass('enable');

    });

    $('form:visible .enable .countries-container a').live('click',function()
    {
        $('form:visible .select-box .selector span').html( $(this).text() );
        $('form:visible .fields input[type="hidden"]').val( $(this).attr('data') );

        /*
        * Fonctionnement avec switch dans la colonne de gauche des listes
        */
        var $getCountry = "#"+$(this).attr('rel');
        $('.select-box .countries').find('li.active').removeClass('active').fadeIn();
        $(this).parent().addClass('active').fadeOut();

        $('.select-box .regions-container').find('.active').stop(true, true).animate({
            left : "-100%"
        }, 200, function()
        {
            $(this).removeClass('active').css("left","100%");
            $('.select-box .enable').find($getCountry).stop(true, true).animate({
                'left': 0,
                'opacity': 1
            }).addClass('active');
        })
    });

    $('form:visible .regions-container a').live('click',function()
    {
        $('form:visible .select-box .selector span').html( $(this).text() );
        $('form:visible .fields input[type="hidden"]').val( $(this).attr('data') );
        $('form:visible .enable .select-box .enable').stop(true, true).delay(100).toggleClass('enable').fadeToggle().parent().find('.fields').toggleClass('active');
    });

    $('.select-box').find('.enable').stop(true, true).live('mouseleave', function(){
        $(this).delay(300).toggleClass('enable').fadeToggle().parent().find('.fields').toggleClass('active');
    }).end();

    /*--------------------------------------------------------------
 *
 * @DEPENDS : Library : jquery.uniform.min.js
 *
 --------------------------------------------------------------*/

    $("select, input:checkbox, input:radio").uniform();
    $("textarea").prev('label').addClass('textarea');

/*--------------------------------------------------------------
 *
 * @DEPENDS : Library : jquerytools
 *
 --------------------------------------------------------------*/

    // RANGE FORM > Module désactivé
    /*
    $(".range").rangeinput({
        css:{
            slider:'input-slider'
        }
    });
  */


 /*--------------------------------------------------------------
 *
 * @DÉPENDANCES :
 *                          FILE : snippets.css
 *                          Class :  .jq-number
 *                                        input.number.activate
 *
 --------------------------------------------------------------*/

    $('form input.number').bind({
        click : function()
        {
            //Masquage des boutons existants
            $('.form').find('div.show').toggleClass('show').stop().fadeOut('fast');

            //Création des éléments et affichage
            $(this).not('.activate').addClass('activate').after('<div class="jq-number"><a class="bt less" /><a class="bt more" /></div>').parent().addClass('onWork');
            $(this).next('.jq-number').toggleClass('show').stop('true', 'true').fadeIn();

            //Positionnement de la box

            $w = $(this).outerWidth(true);
            $h = $(this).outerHeight();
            $jqWidth = $(this).next('.jq-number').outerWidth() + $w;
            $jqHeight = $h + 8; // Afin d'avoir un peu de padding en haut et en bas'

            $x = $(this).position().left;
            $y = $(this).position().top;

            $(this).next('.jq-number').not('.created').css({
                width: $jqWidth+1,
                height: $jqHeight,
                top: Math.round( $y - ( ($jqHeight/2) - ($h/2) ) ),
                left: - Math.round(  ($jqWidth/2) - ($w/2)  )
            }).addClass('created');

        },
        focusout : function(event) {

            /* $(this).parent().focusout(function(event){
               $(this).find('div.show').toggleClass('show').fadeOut('slow');
               $(this).prev('input.number').blur();
        })*/
            //Récupération des variables, si absentes on les assigne
            var $value = ($(this).val() != '') ? parseInt($(this).val()): 0;
            var $max  = ($(this).attr('max') != 'undefined') ? parseInt($(this).attr('max')) : '1000000';
            var $min   = ($(this).attr('min') != 'undefined') ? parseInt($(this).attr('min')) : '-1000000';
            var $step  = ($(this).attr('step') != 'undefined') ? parseInt($(this).attr('step')) : '1';

            //Incrémentation :
            $('.jq-number.show a.bt').live('click', function(event){
                if($(event.target).is('.less') && $(event.target).not('.disabled') && ($value > $min) )
                {
                    $value -= $step;
                    if($value == $min) $(this).addClass('disabled');
                }

                if($(event.target).is('.more') && $(event.target).not('.disabled') && ($value < $max) )
                {
                    $value += $step;
                    if($value == $max) $(this).addClass('disabled');
                }

                if($value < $max)  $('a.bt.more').removeClass('disabled');
                if($value > $min )  $('a.bt.less').removeClass('disabled');

                $(this).parent().siblings('input.number.activate').val($value);
            });

            $(this).change( function() {
                if($(this).val() > $max) $(this).val($max);
                if($(this).val() < $min) $(this).val($min);
            });

        }
    });

    $(".form").has('input.number').mouseleave(function(){
        $(this).find('.jq-number.show').toggleClass('show').stop('true', 'true').delay('1000').fadeOut('fast');
    });

    /*
$('form .input-slider').each(function(){

        $inputRef = $(this).next('input[data-orig-type="range"]');

        //var $value = ($inputRef.val() != '') ? parseInt($inputRef.val()): 0;
        var $max  = ($inputRef.attr('max') != 'undefined') ? $inputRef.attr('max') : '1000000';
        var $min   = ($inputRef.attr('min') != 'undefined') ? $inputRef.attr('min') : '-1000000';
        var $step  = ($inputRef.attr('step') != 'undefined') ? $inputRef.attr('step') : '1';
        var $medmin = String(Math.round(($max/2) - ($step*2)));
        var $medmax = String(Math.round(($max/2) + ($step*2)));


        $(this).append('<span class="input-slider-delimiter left"></span><span class="input-slider-delimiter right"></span>');
        $(this).siblings('label').children('.input-slider-min').children('b').replaceWith($min);
        $(this).siblings('label').children('.input-slider-max').children('b').replaceWith($max);
        $(this).siblings('label').children('.input-slider-middle').children('b:first-child').replaceWith($medmin);
        $(this).siblings('label').children('.input-slider-middle').children('b:last-child').replaceWith($medmax);
});
*/

    /** ********************************************************************* **/
    /*                                                                                                                        */
    /*                              PARTNER SLIDER                                                           */
    /*                                                                                                                        */
    /** ********************************************************************* **/

    /*--------------------------------------------------------------
 *
 * @DÉPENDANCES :
 *                          FILE : snippets.css
 *                                 - jquery.ui.core.min.js
 *                                 - jquery.ui.widget.min.js
 *                                 - jquery.ui.mouse.min.js
 *                                 - jquery.ui.slider.min.js
 *
 --------------------------------------------------------------*/

   //scrollpane parts
    var scrollPane = $( "aside#partner" ),
           scrollContent = $(".scroll-content"),
           containerLength = $(".scroll-content .container").length;

    var productWidth = $('div.mask article').outerWidth(true)*$('div.mask article').length;

if(containerLength > 3)
{
    //build slider
    $( ".slide-bar" ).slider({
        animate: true,
        min: 0,
        max: 92,
        create: function( event, ui ) {
            scrollContent.css({
                'width': productWidth
            });
        },
        slide: function( event, ui )
        {
            if ( scrollContent.width() > scrollPane.width() ) {
                scrollContent.css( "margin-left", Math.round(
                    ui.value / 100 * ( scrollPane.width() - scrollContent.width() )
                    ) + "px" );
            } else {
                scrollContent.css( "margin-left", 0 );
            }
        },
        stop: function (event, ui)
        {
            scrollContent.animate({
                'left' : '-' + Math.round(ui.value) + 'px'
                }, 500, 'linear');
        }
    });
}
else
{
    $('.slide-bar').hide();
}
    /** ********************************************************************* **/
    /*                                                                                                                        */
    /*                              SEARCH RESULTS                                                           */
    /*                                                                                                                        */
    /** ********************************************************************* **/

    //------------ PAGE TITLE CUSTUM WITH ICO ------------//

    $('h1.page-title.ico').wrapInner('<span></span>').prepend('<sup>');


    //------------ SLIDEUP/DOWN ADVANCED SEARCH ------------//
    // déplacé dans la page de recherche
    /*$('#search-form-engine a.button').click(function() {
        if($('.sub-form').hasClass('deployed'))
        {
            $('.sub-form fieldset').slideUp().parent().toggleClass('deployed');
            $('.sub-form a.button').html('&rsaquo;&nbsp;Plus de critères')
        }
        else
        {
            $('.sub-form fieldset').slideDown().parent().toggleClass('deployed');
            $('.sub-form a.button').html('&lsaquo;&nbsp;Fermer')
        }

    });*/

/** ********************************************************************* **/
/*                                                                                                                        */
/*   CSS CLASS TOOLS                                                                                    */
/*   -> Ajout de classes spécifiques odd even et last first                      */
/*                                                                                                                        */
/** ********************************************************************* **/

$('.oddeven >:odd').addClass('odd');
$('.oddeven >:even').addClass('even');
$('.lastfirst >:first-child').addClass('first');
$('.lastfirst >:last-child').addClass('last');

});
