var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

document.observe("dom:loaded", function() { 
    //double carousel 
    //args: 
    //1 - width of the element of big products list
    //2 - width of the element of small products list
    //3 - number of visible elements of small products list
     // recuperation du navigateur en cours pour modification de l'ofset gauche
      
      doubleCarousel(104);
}); 


function doubleCarousel(bigElementWidth) {
    var NavName = navigator.userAgent;
    var Nav;
    var resultat = NavName.search(/MSIE 8/);
    if(resultat != -1) Nav="MSIE 8";
    var resultat7 = NavName.search(/MSIE 7/);
    if(resultat7 != -1) Nav="MSIE 7";
    var resultatF = NavName.search(/Firefox/);
    if(resultatF != -1) Nav="Firefox";
    var resultatC = NavName.search(/Chrome/);
    if(resultatC != -1) Nav="Chrome";
    var resultatS = NavName.search(/Safari/);
    if(resultatS != -1){if (Nav=="") {Nav="Safari"}}
    var resultatO = NavName.search(/Opera/);
    if(resultatO != -1) Nav="Opera";
    
    var carouselContainter = $index('products-carousel-container')
    if(carouselContainter) {
        var carouselContainerWidth = carouselContainter.getWidth(); 
        var trackContainer = $index('scrollh-track-container');
        carouselContainter.style.overflow = 'hidden';
        var bigCarousel = $$('.products-carousel')[0];
        var carouselLength = bigCarousel.childElements().length;
        var carouselLength2;
        if (carouselLength) carouselLength2 = (carouselLength*0.5);
        //if (carouselLength > 3) {
            trackContainer.show();   
            var trackWidth = $index('scrollh-track').getWidth(); 
            var scrollRight = $index('scrollh-track-right');
            
            var scrollLeft = $index('scrollh-track-left');
            /*var scrollRight = document.getElementById('scrollh-track-right');
            var scrollLeft = document.getElementById('scrollh-track-left');*/
            
            
            var bigCarouselWidth = carouselLength * bigElementWidth;
            var handle = $index('scrollh-handle');
            var handleWidth = handle.getWidth();
            var bigScrollingWidth = bigCarouselWidth - carouselContainerWidth;
            
            
            
            bigCarousel.style.width = bigCarouselWidth + 'px';
            
            var timer;
            var hSlider = new Control.Slider(handle, 'scrollh-track', {
                onSlide: function(val) {onSlideFunction(val)},
                onChange: function(val) {onSlideFunction(val)}
            });
            
            if(carouselLength <=10) 
                hSlider.setDisabled();
            
            onSlideFunction = function(val) {
                if(carouselLength > 10) {
                    bigCarousel.setStyle({left: (-1)*Math.floor(val*bigScrollingWidth) + 'px'});
                }
            
            }
            
            
            scrollLeft.observe('mousedown', function(event) {
                if (Event.isLeftClick(event))
                    if(carouselLength > 10) { 
                        timer = setInterval(function() {hSlider.setValueBy(-0.025);}, 25);
                        Event.stop(event);
                    }
                     
            });
            
            scrollLeft.observe('mouseup', function() {
                clearInterval(timer);
            });  
            
            scrollLeft.observe('mouseout', function() {
                clearInterval(timer);
            });  

            scrollRight.observe('mousedown', function(event) {
                if (Event.isLeftClick(event))
                    if(carouselLength > 10) { 
                        timer = setInterval(function() {hSlider.setValueBy(0.025);}, 25);
                        Event.stop(event);
                    }
            });
                   
            scrollRight.observe('mouseup', function() {
                clearInterval(timer);
            });         

            scrollRight.observe('mouseout', function() {
                clearInterval(timer);
            });  

        
        //}
    }   
}







