var iTempoCarrousel = 5000;
 var isIE = false;
    var manageIsIE = {
        init: function () {
            if (jQuery.browser.msie) {
                isIE = true;
                if(parseInt(jQuery.browser.version) == 6) {
                    isIE = 6;
                } else if (parseInt(jQuery.browser.version) == 7) {
                    isIE = 7;
                } else if (parseInt(jQuery.browser.version) == 8) {
                    isIE = 8;
                } else if (parseInt(jQuery.browser.version) == 9) {
                    isIE = 9;
                 }
            }
        }
    };
    
$(document).ready(function(){    
	
    manageIsIE.init();
	
    $('li.product_frame').hover(function(){
        //$(this).css({ background:"#E7E7E7" });
        $(this).find("a.btn_product").addClass('selected');
    }, function(){
        //$(this).css({ background:"#ffffff" });
        $(this).find("a.btn_product").removeClass('selected');
    });
    if(isIE == 6 ){
        $('#langSelect select').bind('change',function(){
            document.location.href = $(this).val();
        });
    } else if(isIE == 9 ){
        $('#langSelect select').bind('change',function(){
            document.location.href = $(this).val();
        });
    }
    else{	
        $('#langSelect select').sSelect().change(function(){
            window.top.location = $(this).val();
        });
    }	
    	
    $('#bigNav .tab').hide();
    //roll over sur onglets de navigation
    $('#bigNav li.navTab').hover(function(){
        var elmt = $(this);
        var index = elmt.index();
        if(!$('#bigNav .tab').eq(index).hasClass('empty')){
            if(isIE){
                $('#bigNav .tab').eq(index).show();
            //$('#tabsBG').show();
            }else{
                $('#bigNav .tab').eq(index).stop().fadeTo("fast", 1);
            //$('#tabsBG').fadeIn('fast');
            }
            $('#tabsBG').show()
            elmt.addClass('over');
        }
    }, function(){
        var elmt = $(this);
        var index = elmt.index();
        if(isIE){
            $('#bigNav .tab').eq(index).hide();
        //$('#tabsBG').hide();
        }else{
            $('#bigNav .tab').eq(index).stop().fadeTo("fast", 0, function () {
                $(this).hide();
            });

        //$('#tabsBG').fadeOut('fast');
        }
        $('#tabsBG').hide()
        elmt.removeClass('over');
    });
	
    //roll over sur boutons produits pour changer l'image dans l'onglet de navigation
    $('#bigNav .productBtn').hover(function(){
        var elmt = $(this);
        var index = elmt.index();
        $('#bigNav .image img').hide();
        $('#bigNav .image img').eq(index).css('display', 'block');
    });
	
    $('#bigNav .nav_product').hover(function(){
        var parentDiv = $(this).parents('.tab:first'); // div ".tab" parente
        $('.image img', parentDiv).css('display','none'); // masque toutes les images
        $('.image #img_'+$(this).attr('id'), parentDiv).css('display','block'); // affiche l'image correspondant au lien
    }, function(){
        var parentDiv = $(this).parents('.tab:first'); // div ".tab" parente
        $('.image img', parentDiv).css('display','none'); // masque toutes les images
        $('.image img.first', parentDiv).css('display','block'); // affiche celle avec la class first
    });

    //rool over images : SITE MAP
     $('#sub_content .nav_product').hover(function(){
        var parentDiv = $(this).parents('#sub_content'); // div ".tab" parente
        $('.image img', parentDiv).css('display','none'); // masque toutes les images
        $('.image #img_'+$(this).attr('id'), parentDiv).css('display','block'); // affiche l'image correspondant au lien
    }, function(){
        var parentDiv = $(this).parents('.tab:first'); // div ".tab" parente
        $('.image img', parentDiv).css('display','none'); // masque toutes les images
        $('.image img.first', parentDiv).css('display','block'); // affiche celle avec la class first
    });
	
    //click sur boutons carrousel produit en home
    $('#productSliderNav ul li').click(function(){
        var elmt = $(this);
        var index = elmt.index();
        if(isIE){
            $('.productSlide').filter('.selected').hide();
            $('.productSlide').eq(index).show();
            $('.productSlide').filter('.selected').removeClass('selected');
            $('.productSlide').eq(index).addClass('selected');
        }else{
            $('.productSlide').filter('.selected').fadeOut('fast', function () {
                $('.productSlide').eq(index).fadeIn('fast');
                $('.productSlide').filter('.selected').removeClass('selected');
                $('.productSlide').eq(index).addClass('selected');
            });
        }
		
        $('#productSliderNav ul li').removeClass('selected');
        elmt.addClass('selected');
    });
	
    //click sur fleches carrousel produit en home
   /* $('#productSliderNav .sliderArrow').click(function(){
        var elmt = $(this);
        var elmtSelect = $('.productSlide').filter('.selected');
        var indexSelect = elmtSelect.index() - 1;
        var indexNext = indexSelect;
        var nbElements =  $('.productSlide').length - 1;
        if(elmt.hasClass('first')){//si fleche precedent
            indexNext = indexSelect - 1;
            if(indexNext<0){
                indexNext = nbElements;
            }
        }else{//si fleche suivant
            indexNext = indexSelect + 1;
            if(indexNext>nbElements){
                indexNext = 0;
            }
        }
        if(isIE){
            $('.productSlide').eq(indexSelect).hide();
            $('.productSlide').eq(indexNext).show();
            $('.productSlide').eq(indexSelect).removeClass('selected');
            $('.productSlide').eq(indexNext).addClass('selected');
        }else{
            $('.productSlide').eq(indexSelect).fadeOut('fast', function () {
                $('.productSlide').eq(indexNext).fadeIn('fast');
                $('.productSlide').eq(indexSelect).removeClass('selected');
                $('.productSlide').eq(indexNext).addClass('selected');
            });
        }
		
        $('#productSliderNav ul li').eq(indexSelect).removeClass('selected');
        $('#productSliderNav ul li').eq(indexNext).addClass('selected');
    });*/
    var interval = initCarrousel();
    $('.sliderPause').show();
    $('.sliderPlay').hide();
    $('.sliderPause').bind('click',function(){
        clearInterval(interval);
        $(this).hide();
        $('.sliderPlay').show();
        return false;
    });
    $('.sliderPlay').bind('click',function(){
        interval = initCarrousel();
        $(this).hide();
        $('.sliderPause').show();
        return false;
    });
    

    //click sur boutons detail de produit en page produit
    $('#detailNav ul li').click(function(){
        var elmt = $(this);
        var index = elmt.index();
        if(isIE){
            $('.available_option').filter('.selected').hide();
            $('.available_option').eq(index).show();
            $('.available_option').filter('.selected').removeClass('selected');
            $('.available_option').eq(index).addClass('selected');
        }else{
            $('.available_option').filter('.selected').fadeOut('fast', function () {
                $('.available_option').eq(index).fadeIn('fast');
                $('.available_option').filter('.selected').removeClass('selected');
                $('.available_option').eq(index).addClass('selected');
            });
        }
		
        $('#detailNav ul li').removeClass('selected');
        elmt.addClass('selected');
    });
	
    //roll over sur boutons de la navigation en page produit
    $('#sub_nav li.navImgP').hover(function(){
        var elmt = $(this);
        var index = elmt.index();
        if(isIE){
            //$('#sub_nav .four_img').eq(index).show();
            elmt.find('.four_img').show();
        }else{
            //$('#sub_nav .four_img').eq(index).fadeIn('fast');
            elmt.find('.four_img').stop().fadeTo("fast", 1);

        }
        elmt.addClass('over');
    }, function(){
        var elmt = $(this);
        var index = elmt.index();
        if(isIE){
            //$('#sub_nav .four_img').eq(index).hide();
            elmt.find('.four_img').hide();
        }else{
            //$('#sub_nav .four_img').eq(index).fadeOut('fast');
            elmt.find('.four_img').stop().fadeTo("fast", 0, function () {
                $(this).hide();
            });
        }
        elmt.removeClass('over');
    });
	
    //roll over sur l'apercu de l'image du four en page produit
    $('#product-slider li.newImg').hover(function(){
        var elmt = $(this);
        var index = elmt.index();
        if(isIE){
            //$('#product-slider .zoom').eq(index).show();
            elmt.find('.zoom').show();
        }else{
            //$('#product-slider .zoom').eq(index).fadeIn('fast');
            elmt.find('.zoom').stop().fadeTo("fast", 1);
        }
        elmt.addClass('over');
    }, function(){
        var elmt = $(this);
        var index = elmt.index();
        if(isIE){
            //$('#product-slider .zoom').eq(index).hide();
            elmt.find('.zoom').hide();
        }else{
            //$('#product-slider .zoom').eq(index).fadeOut('fast');
            elmt.find('.zoom').stop().fadeTo("fast", 0, function () {
                $(this).hide();
            });
        }
        elmt.removeClass('over');
    });
	
    //fonctionnement slider
    $('#slider1').bxSlider({
        displaySlideQty: 2,
        moveSlideQty: 2
	
    });
	
    var optJqZoom = {
      
        zoomWidth: 440,
        zoomHeight: 370,
        xOffset: 10,
        yOffset: -39,
        showEffect: 'fadein',
        hideEffect: 'fadeout',
        fadeinSpeed: 'fast',
        fadeoutSpeed: 'medium', 
	position: 'left',
        title: false,
        zoomType: 'standard',
        lens:true,
            preloadImages: false,
            alwaysOn:false
    }
	
    // zoom sur image produit
    $('.jqzoom').jqzoom(optJqZoom);
	
    // click sur miniature du carousel : remplacement de l'image zoomable
    $('.zoom_link').live('click', function(){
		
        var liNode = $(this).parent();
	
        // recup url miniature en 200*200 et url image taille reelle
        //var url_small = $('input.zoom_link_small', liNode).val();
        var url_big = $('input.zoom_link_big', liNode).val();
		
        // stop si image zoomable actuelle = image cliquee
        if (url_big == $('#rangeProduct a.jqzoom').attr('href')) {
            //alert('here');
            return false;
        }
		
        // supprime l'image zoomable actuelle
        $('#rangeProduct a.jqzoom').remove();
        $('.jqZoomWindow').remove(); // supprime les div deja ajoutees pour ne pas surcharger la page
		
        // creation d'un lien avec la nouvelle image
        $('#rangeProduct .title_slider').after(
            $('<a href="'+url_big+'"></a>').html(
                $('img.miniature200', liNode).clone().show()
                ).addClass('jqzoom').jqzoom(optJqZoom)
            );		
              
        // mise a jour du titre du document
        $('#rangeProduct .legende h4').text($(this).attr('title'));
        // retourne faux pour arreter la propagation du click
        return false;
    });
	
	
    /**
	* Gestion du formulaire de devis
	*/
	
    // noeuds des lignes du formulaire
    var pVolume = $('form .vacuum_form p.select_5');
    var pDiametre = $('form .vacuum_form p.ligne_20');
    var pLargeur = $('form .vacuum_form p.ligne_11');
    var pHauteur = $('form .vacuum_form p.ligne_12');
    var pProfondeur = $('form .vacuum_form p.ligne_13');
    var pCharge = $('form .vacuum_form p.ligne_14');
    var pBMICRO = $('form .vacuum_form #input-1-select_5');
	
    // masque les lignes "volume utile" par defaut si visible
    if (pVolume) {
        pVolume.hide();
        pDiametre.hide();
        pLargeur.hide();
        pHauteur.hide();
        pProfondeur.hide();
        pCharge.hide();
        pBMICRO.hide();
    }
	
    // changement de valeur de la ligne "configuration du four"
    $('form #input-1-select_1').live('change', function(){
        //alert($(this).val());
		
        // selon nouvelle valeur
        switch ($(this).val()) {
		
            // choix 2 (four horizontal) : affiche largeur + hauteur + profondeur + charge
            case 'select_1_2':
                pVolume.show();
                pDiametre.hide();
                pLargeur.show();
                pHauteur.show();
                pProfondeur.show();
                pCharge.show();
                pBMICRO.hide();
                break;
		
            // choix 3 (four vertical) : affiche largeur + hauteur + profondeur + charge
            case 'select_1_3':
                pVolume.show();
                pDiametre.show();
                pLargeur.hide();
                pHauteur.show();
                pProfondeur.hide();
                pCharge.show();
                pBMICRO.hide();
                break;
		
            // choix 4 (four compact) : affiche liste bmicro
            case 'select_1_4':
                pVolume.show();
                pDiametre.hide();
                pLargeur.hide();
                pHauteur.hide();
                pProfondeur.hide();
                pCharge.hide();
                pBMICRO.show();
                break;
			
            // par defaut : masque tout
            case 'select_1_1':
            default:
                pVolume.hide();
                pDiametre.hide();
                pLargeur.hide();
                pHauteur.hide();
                pProfondeur.hide();
                pCharge.hide();
                pBMICRO.hide();
                break;
		
        }

    });
	

    // GESTION DES INFOBULLES MULTILINGUES POUR LES FORMULAIRES
    var lang = $('#lang-infobulle').html();
    var attrTitle = $('#texte-infobulle .'+lang).html();
    $('img#help').attr('title', attrTitle);

    //FORMS : DOWNLOAD FILES
    var nbInput = $('[type="file"]').length;
    $('[type="file"]').each(function(){
        if($(this).val() == '') $(this).parent('p').hide();
     });
     $('[type="file"][value=""]:first').parent('p').show();
     $('[type="file"]').bind('change',function(){
         $('[type="file"][value=""]:first').parent('p').show();
     });

     //COLORBOX
     $('a.colorbox').colorbox({transition: "elastic",maxWidth : '90%',maxHeight : '90%',innerWidth:500,innerHeight:400,iframe:true});

});/**/
//temporisation carrousel
function tempoCarrousel(isIE)
{
    var elmtSelect = $('.productSlide').filter('.selected');
    var indexSelect = elmtSelect.index() - 1;
    var indexNext = indexSelect;
    var nbElements =  $('.productSlide').length - 1;
    //si fleche suivant
    indexNext = indexSelect + 1;
    if(indexNext>nbElements){
        indexNext = 0;
    }

    $('#productSliderNav ul li').removeClass('selected');
    $('#productSliderNav ul li').eq(indexNext).addClass('selected');

    if(isIE){
        $('.productSlide').eq(indexSelect).hide();
        $('.productSlide').eq(indexNext).show();
        $('.productSlide').eq(indexSelect).removeClass('selected');
        $('.productSlide').eq(indexNext).addClass('selected');
    }else{
        $('.productSlide').eq(indexSelect).fadeOut('fast', function () {
            $('.productSlide').eq(indexNext).fadeIn('fast');
            $('.productSlide').eq(indexSelect).removeClass('selected');
            $('.productSlide').eq(indexNext).addClass('selected');
        });
    }    
}
function initCarrousel()
{
    return setInterval("tempoCarrousel("+isIE+")",iTempoCarrousel);
}
    
