function CheckSerialN(val) 
{
    if (val == 'Repair(RMA)' || val == 'Technical')
    {
        $('divSerialN').style.display = '';
    }
    else
    {
        $('divSerialN').style.display = 'none';
    }
}

var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
  
        

var enterFunction = function() {
    this.start('.header_menu_over');
}


var leaveFunction = function() {
    this.start('.header_menu');

}


function quad(id)
{

    var quadIn = $(id);


    quadIn = new Fx.Morph(quadIn, {
        link: 'cancel',
        duration : '160',
        transition: Fx.Transitions.Sine.easeIn,
        onStart: function(boo){
        },
        onComplete: function(boo){
        },
        onCancel: function(boo){
        }
        
    });



    //QUAD  
    $(id).addEvents({
        'mouseenter': enterFunction.bind(quadIn),
        'mouseleave': leaveFunction.bind(quadIn)
    });


}



/////////////////////////////////////////////

function touchMove(event) {

    // Prevent scrolling on this element

    event.preventDefault();


}

function dispDivLang(id_div,id_survol_in,id_survol_out)
{

    $(id_div).set('opacity', 0);

    $(id_survol_in).addEvent('mouseenter',function(){
        ;
        $(id_div).fade('in');
        $('survolLangImg').set('src','IHM/img/icon_lang_survol.png');
    });

    $(id_survol_out).addEvent('mouseleave',function(){
        $(id_div).fade('out');
        $('survolLangImg').set('src','IHM/img/icon_lang.png');
    });


    $('divSelectLang').addEvent('mouseleave',function(){
        $(id_div).fade('out');
        $('survolLangImg').set('src','IHM/img/icon_lang.png');
    });


    $(id_survol_out).addEvent('click',function(){
        $(id_div).fade('out');
        $('survolLangImg').set('src','IHM/img/icon_lang.png');
    });

}

// Requete ajax ssl
function disp_hide_SSL_brands(disp)
{
    if($('BrandSSL').style.display != "none" || disp=='resp')
    {
        $('BrandSSL').style.display = 'none';
        $('see_brand_SSL').style.display = 'inline';
        $('ResultsSSL').style.display = 'block';
    }
    else
    {
        $('BrandSSL').style.display = 'block';
        $('see_brand_SSL').style.display = 'none';
        $('ResultsSSL').style.display = 'none';
    }


}


function ShowResultSSL(id_search)
{

    var req = new Request(
    {
        url:'ajax_functions.php',
        method:'get',
        autoCancel:true,
        onRequest: function() {
        },
        onComplete: function(response) {
            $('ResSLL').innerHTML =  response;
            disp_hide_SSL_brands('resp');
        },
        onSuccess:function() {
        }
    }).send('id_search='+id_search);
}

// Requete ajax distributeurs!
function ShowResultDistri()
{
    var idZn = $('id_pays').value;
    var req = new Request(
    {
        url:'ajax_functions.php',
        method:'get',
        autoCancel:true,
        onComplete: function(response) {
            $('ResDistri').innerHTML =  response;
        }
    }).send('idZn='+idZn);
}


var mySlideShow_slides_slide_home;
var mySlideShow_slideshow_container;
var mySlideShow_slides_slide_left;
var mySlideShow_slides_slide_pub;
var mySlideShow_slides_slide_bigprod;
var mySlideShow_slides_slide_breakingnews;

var mySlideShow_banner;



window.addEvent('domready', function() {


    if (mobile) {


    (function() {
        try {
            document.createEvent("TouchEvent");
        } catch(e) {
            return;
        }

        ['touchstart', 'touchmove', 'touchend'].each(function(type){
            Element.NativeEvents[type] = 2;
        });

        var mapping = {
            'mousedown': 'touchstart',
            'mousemove': 'touchmove',
            'mouseup': 'touchend'
        };

        var condition = function(event) {
            var touch = event.event.changedTouches[0];
            event.page = {
                x: touch.pageX,
                y: touch.pageY
            };
            return true;
        };

        for (var e in mapping) {
            Element.Events[e] = {
                base: mapping[e],
                condition: condition
            };
        }
    })();

    }
    if($('productSlider'))
    {
        var myProducts = new ScrollBar($('productSlider'), $('productSliderBar'), $('productSliderCursor'), {
            steps: parseInt($('slider_prod_width').value) - 960,
            wheel: true,
            offset: -18
        });

        myProducts.set(0);
        myProducts.attach();


    }


    if($('divLangContent'))
    {
        dispDivLang('divLangContent','survolLang','divLangContent');
    }

    if($('id_menu_header_selected'))
    {

        if($('id_menu_header_selected').value!="main")
        {
            quad('divMain');
        }

        if($('id_menu_header_selected').value!="marine")
        {
            quad('divMarine');
        }

        if($('id_menu_header_selected').value!="blue")
        {
            quad('divBlue');
        }

        if($('id_menu_header_selected').value!="orange")
        {
            quad('divOrange');
        }

    }

    if($('slideshow-container'))
    {
        mySlideShow_slideshow_container = new SlideShow('slideshow-container',{
            delay: 5000,
            autoplay: true
        });
    }

    if($('slides_slide_bigprod'))
    {
        mySlideShow_slideshow_container = new SlideShow('slides_slide_bigprod',{
            delay: 6000,
            autoplay: true
        });
    }

    if($('slides_slide_home'))
    {
        mySlideShow_slides_slide_home = new SlideShow('slides_slide_home',{
            delay: 5000,
            autoplay: true
        });
        $('slide_control_play').style.backgroundPosition="0px 0px";
        $('slide_control_pause').style.backgroundPosition="0px -14px";


        $('slide_control_play').addEvent('click',function(){
            mySlideShow_slides_slide_home.play();
            $('slide_control_play').style.backgroundPosition="0px 0px";
            $('slide_control_pause').style.backgroundPosition="0px -14px";
        });

        $('slide_control_pause').addEvent('click',function(){
            mySlideShow_slides_slide_home.pause();
            $('slide_control_play').style.backgroundPosition="0px -14px";
            $('slide_control_pause').style.backgroundPosition="0px 0px";
        });

        $('slide_control_next').addEvent('click',function(){
            mySlideShow_slides_slide_home.showNext();
        //mySlideShow_slides_slide_home.show((mySlideShow_slides_slide_home.current()+1));
        });

        $('slide_control_previous').addEvent('click',function(){
            mySlideShow_slides_slide_home.showPrevious();
        //mySlideShow_slides_slide_home.show((mySlideShow_slides_slide_home.current()+1));
        });

        if($('pubImg'))
        {
            mySlideShow_slides_slide_home.pause();
            $('pubImg').set('opacity','0');
            $('pubDIV').style.height=document.body.scrollHeight+'px';

            var myFx2 = new Fx.Tween('pubImg', {
                    property: 'opacity',
                    duration: 1500,
                    transition: Fx.Transitions.Quart.easeInOut,
                    link: 'chain'
            });

            myFx2.start(0, 1);

            var myFunction3 = function(){$('pubDIV').style.display="none";};

             var myFunction2 = function(){ var myFx3 = new Fx.Tween('pubDIV', {
                    property: 'opacity',
                    duration: 3000,
                    transition: Fx.Transitions.Quart.easeInOut,
                    link: 'chain'
            });
             myFx3.start(1, 0);
             mySlideShow_slides_slide_home.play();
            };


           var myFunction = function(){

            /*    var myFx = new Fx.Morph('pubDIV', {
                    //property: 'margin-top',
                    duration: 2000,
                    transition: Fx.Transitions.Quart.easeInOut,
                    link: 'chain'

            });

             myFx.start('.pubImgMove');*/
            myFunction2();
            //myFunction2.delay(500);



            };


            myFunction2.delay(2000);
            myFunction3.delay(5000);

        }

    }

    if($('slides_slide_left'))
    {
        mySlideShow_slides_slide_left = new SlideShow('slides_slide_left',{
            delay: 5000,
            autoplay: true
        });
    }

    if($('slides_slide_breakingnews'))
    {
        mySlideShow_slides_slide_breakingnews = new SlideShow('slides_slide_breakingnews',{
            delay: 10000,
            autoplay: true
        });
    }

    if($('slides_slide_pub_side'))
    {
        mySlideShow_slides_slide_pub = new SlideShow('slides_slide_pub_side',{
            delay: 4500,
            autoplay: true
        });
    }

    if($('banner_wide'))
    {
        mySlideShow_banner = new SlideShow('banner_wide',{
            delay: 5500,
            autoplay: true
        });
    }
    
    if($('ResDistri'))
    {
        ShowResultDistri();
    }

    if($('id_contactObject'))
    {
        CheckSerialN($('id_contactObject').options[$('id_contactObject').selectedIndex].text);
    }

    var myAccordion = new Accordion($('accordion'), 'div.toggler', 'div.element', {
        opacity: true,
        display: 0,
        alwaysHide: true,
        onActive: function(toggler, element){
            toggler.setStyle('color', '#41464D');
        },
        onBackground: function(toggler, element){
            toggler.setStyle('color', '#528CE0');
        }
    });
      
});
