// JavaScript Document
var det=0;
$(document).ready(function() {  
    doReady(); 
    doTabs();
    if(Sys){  
        var prm = Sys.WebForms.PageRequestManager.getInstance();  
        prm.add_endRequest(function(s, e) {                      
            if (det==0){
                doReady(); 
            }else{
                ReVinculaSliderDetalle();
            } 
            VinculaNice();
        }); 
    }        
});  
function VinculaNice(){ 
    $('.cont-checkbox, .form-select, .detalle .col-3 .select-detalles').jNice();
}
function VinculaAcordeon(){
    $(".accordion").accordion();
}
function ReVinculaSliderDetalle(){
    if($('.slider-detalle').length){
        $('.slider1').scrollIt({
            menuWidth: 800,
            itemWidth: 117,
            menuHeight: 107,
            itemHeight: 98,
            menuWidthAdd: 154,
            menuHeightAdd: 13,
            scrollDuration: 400
        });
        $('.slider2').scrollIt({
            menuHeight: 107,
            itemHeight: 98,
            menuWidth: 800,
            itemWidth: 117,
            scrollDuration: 400,
            menuWidthAdd: 154,
            menuHeightAdd: 13,
            scrollItwrapper: 'scrollItwrapper2'
        });
    }

}
function doReady(){
    // slider
    /*if($('.slider-imagenes').length){
        $('.slider-imagenes').scrollIt({
            menuWidth: 785,
            itemWidth: 220,
            menuHeight: 148,
            scrollDuration: 400,
            menuWidthAdd: 195
        });  
    }*/
    if($('.slider-detalle').length){
        $('.slider1').scrollIt({
            menuWidth: 800,
            itemWidth: 117,
            menuHeight: 107,
            itemHeight: 98,
            menuWidthAdd: 154,
            menuHeightAdd: 13,
            scrollDuration: 400
        });
        $('.slider2').scrollIt({
            menuHeight: 107,
            itemHeight: 98,
            menuWidth: 800,
            itemWidth: 117,
            scrollDuration: 400,
            menuWidthAdd: 154,
            menuHeightAdd: 13,
            scrollItwrapper: 'scrollItwrapper2'
        });
    }

    if($('.slider-detalle-chico').length){
        $('.slider1').scrollIt({
            menuWidth: 530,
            itemWidth: 110,
            menuHeight: 107,
            itemHeight: 98,
            menuWidthAdd: 154,
            menuHeightAdd: 13,
            scrollDuration: 400
        });
        $('.slider2').scrollIt({
            menuHeight: 107,
            itemHeight: 98,
            menuWidth: 530,
            itemWidth: 110,
            scrollDuration: 400,
            menuWidthAdd: 154,
            menuHeightAdd: 13,
            scrollItwrapper: 'scrollItwrapper2'
        });
        if($('.slider2 li').length <= 7){
            $('.scrollItwrapper2 .left-arrow, .scrollItwrapper2 .right-arrow').css('visibility','hidden');
        }
    }

    if($('.slider-vertical').length){
        $('.slider-vertical').scrollIt({
            menuHeight: 370,
            itemHeight: 95,
            menuWidth: 85,
            itemWidth: 85,
            scrollDuration: 400,
            scrollItwrapper: 'scrollItwrapper3',
            scrollItwrapperMargin: '0 0 0',
            menuHeightAdd: 30,
            vertical:true
        });
        if($('.slider-vertical li').length <= 4){
            $('.scrollItwrapper3 .left-arrow, .scrollItwrapper3 .right-arrow').css('display','none');
        }
    }

    if($('.slider-horizontal').length){
        $('.slider-horizontal').scrollIt({
            menuHeight: 85,
            itemHeight: 85,
            menuWidth: 374,
            itemWidth: 95,
            scrollDuration: 400,
            scrollItwrapper: 'scrollItwrapper4',
            scrollItwrapperMargin: '0',
            menuWidthAdd: 30
        });
        if($('.slider-horizontal li').length <= 4){
            $('.scrollItwrapper4 .left-arrow, .scrollItwrapper4 .right-arrow').css('display','none');
        }
    }

	if($('.slider-horizontal2').length){
        if (($('.tag-descuento').length) && ($('.tag-nuevo').length)){
            $('.slider-horizontal2').scrollIt({
                menuHeight: 77,
                itemHeight: 77,
                menuWidth: 246,
                itemWidth: 82,
                scrollDuration: 400,
                scrollItwrapper: 'scrollItwrapper4',
                scrollItwrapperMargin: '0',
                menuWidthAdd: 30
            });
            if($('.slider-horizontal2 li').length <= 3){
                $('.scrollItwrapper4 .left-arrow, .scrollItwrapper4 .right-arrow').css('display','none');
            }
        }else{

            $('.slider-horizontal2').scrollIt({
                menuHeight: 77,
                itemHeight: 77,
                menuWidth: 328,
                itemWidth: 82,
                scrollDuration: 400,
                scrollItwrapper: 'scrollItwrapper4',
                scrollItwrapperMargin: '0',
                menuWidthAdd: 30
            });
            if($('.slider-horizontal2 li').length <= 4){
                $('.scrollItwrapper4 .left-arrow, .scrollItwrapper4 .right-arrow').css('display','none');
            }
        }
    }

    if ( $('.radio-brand').length){
        var flag = false;
        if($('.radio-brand .jNiceRadio').hasClass('jNiceChecked')){
            $('.cont-slider-estatico').hide();
            $('.sliders').removeClass('slider-estatico');
            flag = true;
        }else{
            $('.scrollItwrapper').css('display','none');
            $('.scrollItwrapper').hide();
            $('.sliders').addClass('slider-estatico');
        }

        $('.radio-brand .jNiceRadio').click(function () {
            if($('.radio-brand .jNiceRadio').hasClass('jNiceChecked') && flag == false){
                $('.cont-slider-estatico').fadeOut("slow", function(){
                    $('.scrollItwrapper').fadeIn("slow")
                    $('.sliders').removeClass('slider-estatico');
                })
                flag = true;
            }
        })
        $('.label-brand').click(function () {
            if(!$('.radio-brand .jNiceRadio').hasClass('jNiceChecked') && flag == false){
                $('.cont-slider-estatico').fadeOut("slow", function(){
                    $('.scrollItwrapper').fadeIn("slow")
                    $('.sliders').removeClass('slider-estatico');
                })
                flag = true;
            }
        })
        $('.radio-product .jNiceRadio').click(function () {
            if($('.radio-product .jNiceRadio').hasClass('jNiceChecked') && flag == true){
                $('.scrollItwrapper').fadeOut("slow", function(){
                    $('.cont-slider-estatico').fadeIn("slow")
                    $('.sliders').addClass('slider-estatico');
                })
                flag = false;
            }
        })
        $('.label-product').click(function () {
            if(!$('.radio-product .jNiceRadio').hasClass('jNiceChecked') && flag == true){
                $('.scrollItwrapper').fadeOut("slow", function(){
                    $('.cont-slider-estatico').fadeIn("slow")
                    $('.sliders').addClass('slider-estatico');
                })
                flag = false;
            }
        })
    }
	
    //textboxs
    var textBoxs = $('.form-text-js');
    jQuery.each(textBoxs, function() {
        var theValue = $(this).attr('value');
        $(this).focus(function (){
            if($(this).attr('value') == theValue){
                $(this).attr('value','').addClass('nondefault');
            }
        }).blur(function () {
            if($(this).attr('value') == ''){
                $(this).attr('value',theValue).removeClass('nondefault');
            }
        });
      
    });

    /*resultados*/
    //if($('.resultados').length){
    if($('.cont-checkboxes').parents().hasClass('resultados')){
        //scroll filtros de resultados
        $('.cont-checkboxes').jScrollPane({
            scrollbarWidth:21
        });


        //plegables
        $('.cont-checkbox-plegables').css({
            height:'175px',
            overflow:'hidden',
            display:'none'
        });
        var plegables = $(".plegable .cont-checkbox-plegables");
        var btnPegable = $(".btn-pegable");
        var goForIt;
        btnPegable.addClass('closed');
        function changeOverflow(){
            $(".plegable .cont-checkboxes").toggleClass('changeOverflow');
            $(".col-checkboxes").toggleClass('changeOverflow2');
            goForIt = true;
        }
        btnPegable.click(function () {
            $(this).toggleClass('closed');
            $('.cont-checkboxes').toggleClass('paraIE')
    	
            if(!goForIt){
                changeOverflow();
            }
            plegables.slideToggle("slow", function(){
                changeOverflow();
                goForIt = false;
            });
        });

    }

    /*votacion feedback*/
    if($('.feedback .rating-2').length){
        var rating = $('.estrellas');
        jQuery.each(rating, function() {
            var clickeado = false;
            var laClase;
            var botones = $(this).children();
            var ratingTxt = $(this).next();
            jQuery.each(botones, function(i) {
                $(this).hover(
                    function () {
                        $(this).parent().removeClass();
                        $(this).parent().addClass('estrellas index-' + i);
                        ratingTxt.children(':eq('+ (i + 1) +')').addClass('visible');
                        if(clickeado == false){
                            ratingTxt.children(':eq(0)').removeClass('visible');
                        }else if(elTexto != (i + 1)){
                            ratingTxt.children(':eq('+ elTexto +')').removeClass('visible')
                        }
                    },
                    function () {
                        if(clickeado == false){
                            $(this).parent().removeClass().addClass('estrellas');
                            ratingTxt.children(':eq('+ (i + 1) +')').removeClass('visible');
                            ratingTxt.children(':eq(0)').addClass('visible');
                        }else{
                            $(this).parent().removeClass().addClass('estrellas ' + laClase);
                            if(elTexto != (i + 1)){
                                ratingTxt.children(':eq('+ elTexto +')').addClass('visible');
                                ratingTxt.children(':eq('+ (i + 1) +')').removeClass('visible');
                            }
                        }
                    }
                    );
                $(this).click(function() {
                    clickeado = true;
                    laClase = 'index-' + i;
                    elTexto = i + 1;
                });
            });
        });
    }
    
    /*Acomodar la altura de los listados sitemap*/
    if($('.sitemap-prod').length){
        function setHeight(elemento){
            var cuadrado = $("" + elemento + "");
            var elArray = new Array;
            jQuery.each(cuadrado, function() {
                var laAltura = $(this).height();
                elArray.push(laAltura);
            })
            function ordenacionDesc(x,y){
                return ( x > y ) ? -1 : ( x < y ) ? 1 : 0;
            }
            elArray.sort(ordenacionDesc);
            BiggestNumber = elArray[0];
            cuadrado.height(BiggestNumber);
        }
        setHeight('.block');
    }
	
    if ( $('#slider').length){
        $('#slider').nivoSlider({
            effect:'sliceDown',
            slices:15,
            animSpeed:500,
            pauseTime:5000,
            directionNav:true, //Next & Prev
            controlNav:true, //1,2,3...
            keyboardNav:true, //Use left & right arrows
            pauseOnHover:true, //Stop animation while hovering
            manualAdvance:false, //Force manual transitions
            beforeChange: function(){},
            afterChange: function(){},
            slideshowEnd: function(){} //Triggers after all slides have been shown
        });
        $('.nivo-controlNav').slideToggle();
        $('#slider').hover(
            function () {
                $('.nivo-controlNav').slideToggle();
            },
            function () {
                $('.nivo-controlNav').slideToggle();
            }
            )
    }
	
    //Minihelps
    if ( $('.mini-help').length){
        if(!$('body').hasClass('mini-help-on')){
            var panelesMiniHelp = $('.mini-help');

            jQuery.each(panelesMiniHelp, function(){
                $(this).css({
                    'opacity':0,
                    'z-index':0
                }).removeClass('helpinvisible');
                if($(this).hasClass('help-activo')){
                    actual = $(this);
                    $('.cont-mini-help').animate({
                        height: 181,
                        marginBottom: -16
                    }, 1000, function() {
                        actual.animate({
                            opacity: 1
                        }, 1000, function() {
                            });
                    }).addClass('panelAbierto')
                }
            })
            $('.btn-listadop').bind('click', function(){
                if(!$(this).parent().hasClass('activo')){
                    if(!($('.cont-mini-help').hasClass('panelAbierto'))){
                        $('.cont-mini-help').animate({
                            height: 181,
                            marginBottom: -16
                        }, 300, function() {
                            $('.search-bar li').removeClass('activo')
                            $('.mini-help').animate({
                                opacity: 0
                            }, 300, function() {
                                $(this).css('z-index',0)
                            });
                            $('.sliders').animate({
                                opacity: 1
                            }, 300, function() {
                                $(this).removeAttr('style').css('z-index',100)
                            });
                            $('.btn-listadop').parent().addClass('activo')
                        });
                    }else{
                        $('.search-bar li').removeClass('activo')
                        $('.mini-help').animate({
                            opacity: 0
                        }, 300, function() {
                            $(this).css('z-index',0)
                        });
                        $('.sliders').animate({
                            opacity:  1
                        }, 300, function() {
                            $(this).removeAttr('style').css('z-index',100)
                        });
                        $('.btn-listadop').parent().addClass('activo');
                    }
                }

            })

            $('.btn-envio').bind('click', function(){
                if(!$(this).parent().hasClass('activo')){
                    if(!($('.cont-mini-help').hasClass('panelAbierto'))){
                        $('.cont-mini-help').animate({
                            height: 181,
                            marginBottom: -16
                        }, 300, function() {
                            $('.search-bar li').removeClass('activo')
                            $('.mini-help').animate({
                                opacity: 0
                            }, 300, function() {
                                $(this).css('z-index',0)
                            });
                            $('.help-envio').animate({
                                opacity:  1
                            }, 300, function() {
                                $(this).css('z-index',100)
                            });
                            $('.btn-envio').parent().addClass('activo')
                        });
                    }else{
                        $('.search-bar li').removeClass('activo')
                        $('.mini-help').animate({
                            opacity: 0
                        }, 300, function() {
                            $(this).css('z-index',0)
                        });
                        $('.help-envio').animate({
                            opacity:  1
                        }, 300, function() {
                            $(this).css('z-index',100)
                        });
                        $('.btn-envio').parent().addClass('activo')
                    }
                }
            })
            $('.btn-devolu').bind('click', function(){
                if(!$(this).parent().hasClass('activo')){
                    if(!($('.cont-mini-help').hasClass('panelAbierto'))){
                        $('.cont-mini-help').animate({
                            height: 181,
                            marginBottom: -16
                        }, 300, function() {
                            $('.search-bar li').removeClass('activo')
                            $('.mini-help').animate({
                                opacity: 0
                            }, 300, function() {
                                $(this).css('z-index',0)
                            });
                            $('.help-devolucion').animate({
                                opacity: 1
                            }, 300, function() {
                                $(this).css('z-index',100)
                            });
                            $('.btn-devolu').parent().addClass('activo')
                        });
                    }else{
                        $('.search-bar li').removeClass('activo')
                        $('.mini-help').animate({
                            opacity: 0
                        }, 300, function() {
                            $(this).css('z-index',0)
                        });
                        $('.help-devolucion').animate({
                            opacity:  1
                        }, 300, function() {
                            $(this).css('z-index',100)
                        });
                        $('.btn-devolu').parent().addClass('activo')
                    }
                }
            })

            $('.cerrar-help').bind('click', function(){
                $('.search-bar li').removeClass('activo');
                $('.mini-help').animate({
                    opacity: 0
                }, 300, function() {
                    $('.cont-mini-help').animate({
                        height: 1,
                        marginBottom: 0
                    }, 300, function() {
                        });

                });
                $('.cont-mini-help').removeClass('panelAbierto')
            })
            $('body').addClass('mini-help-on');
        }
    }
    //para el acordeon de la seccion detalle
    if ($('.accordion').length){
        $(".accordion").accordion();
    }

    //para los tooltip de la seccion detalle
    if ($(".bloque-comentario p .linkMas").length) {
        $(".bloque-comentario p .linkMas").dreamyTip({ insertCSS: false, sumatop: 0 });               
    }

    if ($(".bloque-comentario .rating-3 .linkMas").length) {
        $(".bloque-comentario .rating-3 .linkMas").dreamyTip({ insertCSS: false, sumatop: 0 });
    }

}



function doTabs(){
    //Tabs selector de productos home
    if($('.scrollable-prod').length){
        // custom easing called "custom"
        $.easing.custom = function (x, t, b, c, d) {
                var s = 1.0; 
                return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
        }
        $('.scrollable-prod').scrollable({easing:'custom', speed: 1000, onBeforeSeek: function(event, tabIndex) {
                $('.arrow-selector').animate({left: (tabIndex)?691:223});	
            }}).navigator();
    }
    
    
    //Tabs selector de productos home
    if($('.scrollable-brand').length){
        // custom easing called "custom"
        $.easing.custom = function (x, t, b, c, d) {
                var s = 1.0; 
                return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
        }
        $('.scrollable-brand').scrollable({easing:'custom', speed: 1000, onBeforeSeek: function(event, tabIndex) {                
            }}).navigator();
    }	
}
                         
