/*
Autor: Cristian Esteban De la Hoz (cristandelahoz@gamingculture.net)
Version: 1.0
*/


window.onresize = resize;

$(document).ready(function () {


    resize();

    if ($('#content-oculto div.div-hidden').length == 0) {
        $('#agregar-mas').fadeOut(1);
    }
    //    var numeroli=$('.hdnCodigo').val();
    //    alert(numeroli);
    //    if(numeroli==null){
    //$('.carrousel-combinalo ol li:eq(0)').addClass('active');
    //    }
    //    else{
    //     $('.carrousel-combinalo ol li:eq('+numeroli+')').addClass('active');
    //    }
    /* css({'background':'url("images/bg-skinSelect-Dos.jpg") no-repeat scroll center bottom transparent'}); */

    $('.input-info input, .right input').focusin(function () {


        if (($(this).attr('id') != 'ctl00_ContentPlaceHolder1_Calculadora1_txtAncho') && ($(this).attr('id') != 'ctl00_ContentPlaceHolder1_Calculadora1_txtAlto'))
            if ($(this).val() == "Ej. casa, puerta, pared, etc.") {

                $(this).val('');
                $(this).removeClass('info-example');

            }

    }).focusout(function () {

        if (($(this).attr('id') != 'ctl00_ContentPlaceHolder1_Calculadora1_txtAncho') && ($(this).attr('id') != 'ctl00_ContentPlaceHolder1_Calculadora1_txtAlto'))
            if ($(this).val() == "") {

                $(this).val('Ej. casa, puerta, pared, etc.');
                $(this).addClass('info-example');

            }


    });

    if ($('#views-busqueda.content-cuadros').html()) {

        $('#views-busqueda.content-cuadros').masonry({
            itemSelector: 'article',
            columnWidth: 240,
            isFitWidth: true,
            isAnimated: !Modernizr.csstransitions
        });

    }

    $('#agregar-mas .product-vermas').html($('#content-oculto div.div-hidden:eq(0) h1').html());

    function cortarText() {

        if ($('#agregar-mas').html()) {

            var a = $('#content-oculto div.div-hidden:eq(0) p').html();
            if (a != null) {
                var b = a.indexOf(' ', 15);
                var c = a.substring(0, b);
                var d = a.indexOf(' ', b + 15);
                var e = a.substring(b, d);
                return a;
            }
        }
    }

    $('#agregar-mas .slogan-vermas').html(cortarText());

    $('#agregar-mas').click(function () {
        /* favillon */
        //alert('jajajaja');

        var $box = $($('#content-oculto div.div-hidden:eq(0)').html() + ' ' + $('#content-oculto div.div-hidden:eq(1)').html() + ' ' + $('#content-oculto div.div-hidden:eq(2)').html() + ' ' + $('#content-oculto div.div-hidden:eq(3)').html() + ' ' + $('#content-oculto div.div-hidden:eq(4)').html() + ' ' + $('#content-oculto div.div-hidden:eq(5)').html() + ' ' + $('#content-oculto div.div-hidden:eq(6)').html() + ' ' + $('#content-oculto div.div-hidden:eq(7)').html());


        var cantidad = $('#content-oculto div.div-hidden:eq(1)').html();

        $('#views-busqueda').append($box).masonry('appended', $box, true);

        for (i = 0; i < 8; i++) {

            $('#content-oculto div.div-hidden:eq(0)').remove();

        }

        if ($('#content-oculto div.div-hidden').length == 0) {
            //alert('que valor hay aca');
            $('#agregar-mas').fadeOut(350);

        } else {

            $('#agregar-mas .product-vermas').html($('#content-oculto div.div-hidden:eq(0) h1').html());
            $('#agregar-mas .slogan-vermas').html(cortarText());

        }

        return false;

    });

    $('.carrousel-home, .content-corrousel-calc').jCorrousel({
        arrowLeft: '.left-flecha',
        arrowRight: '.right-flecha',
        skin: true,
        skinCookie: true,
        transtition: true
    });

    $('.content-new-search, .content-combinalo').jCorrousel({
        hideArrow: true,
        numberItems: 5
    });

    //CAMBIO 5 POR 3
    $('.content-corrousel-promo').jCorrousel({
        hideArrow: true,
        numberItems: 10,
        arrowLeft: '.left-flecha',
        arrowRight: '.right-flecha',
        lineNumber: 2,
        velocity: 350
    });

    $('#page-carrousel').jPageCorrousel();

    $('.paleta-color').jColor();



    /*By Kelvin Luck ( http://www.kelvinluck.com/ )*/
    $.stylesheetSwitch = function (styleName) {

        $('link[@rel*=style][title]').each(function (i) {
            this.disabled = true;
            if (this.getAttribute('title') == styleName) {
                this.disabled = false;
                activeStylesheetIndex = i;
            }
        });
    };

    if ($.cookie('skin') != null) {

        $.stylesheetSwitch($.cookie('skin'));
        sessvars.skin = $.cookie('skin');

    }

});

function resize() {

    var altoDoc = $(window).height();
    if ($('#interno-search').html()) { var altoMain = $('#header-main').height() + $('#section-main').height() + $('#interno-search').height(); } else { var altoMain = $('#header-main').height() + $('#section-main').height(); }
    var altoSection = Math.round(altoDoc - ($('#header-main').height() + $('#footer-main').height()));
    var centrarAlto = Math.round($('#home').height() / 2);

    ////console.log('Alto Documento:' + altoDoc + ', Alto contenido:' + altoMain + ', alto section:' + altoSection);

    if (altoDoc > altoMain && !$('#views-busqueda').html() && altoMain < 800 && !$('#home').html()) {

        $('#footer-main').css({ 'position': 'fixed', 'bottom': '0', 'width': '100%' });

    } else if (altoDoc > altoMain && $('#home').html()) {

        $('#footer-main').css({ 'position': 'fixed', 'bottom': '0', 'width': '100%' });
        $('#section-main').css({ 'position': 'relative', 'height': altoSection + 'px' });
        $('#home').css({ 'position': 'absolute', 'top': '50%', 'left': '50%', 'margin': '-' + centrarAlto + 'px 0 0 -500px' });

    } else {

        $('#footer-main, #section-main, #home').removeAttr('style');

    }

};

(function ($) {

    $.fn.jCorrousel = function (options) {

        var defaults = {
            horizontal: true,
            increase: 1,
            lineNumber: 1,
            hideArrow: false,
            numberItems: 0,
            arrowLeft: '.arrowLeft',
            arrowRight: '.arrowRight',
            velocity: 500,
            typeEasing: 'linear',
            skin: false,
            skinCookie: false,
            transtition: false
        };
        var options = $.extend(defaults, options);

        this.each(function () 
        {


            //				a = numero items
            //				b = ancho Items
            //				c = ancho Total
            //				d = posicion Aumenta
            //				e = posicion Final
            //				f = Ultimo Item
            //				g = posicion Actual
            //            

            if ($(this).attr('class')) 
            {

                var $this = '.' + $(this).attr('class');

            } else if ($(this).attr('id')) 
            {

                var $this = '#' + $(this).attr('id');

            }

            if ($($this).find('ol').html()) 
            {

                if ($($this + ' ol').parent().attr('class')) 
                {
                    var parent = '.' + $($this + ' ol').parent().attr('class');
                } else if ($($this + ' ol').parent().attr('id')) 
                {
                    var parent = '#' + $($this + ' ol').parent().attr('id');
                }

                var list = $($this + ' ' + parent + ' ol');
                var li = $($this + ' ' + parent + ' ol li');
                var typeList = 'ol';


            } else if ($($this).find('ul').html()) 
            {

                if ($($this + ' ul').parent().attr('class')) 
                {
                    var parent = '.' + $($this + ' ul').parent().attr('class');
                } else if ($($this + ' ul').parent().attr('id')) 
                {
                    var parent = '#' + $($this + ' ul').parent().attr('id');
                }

                var list = $($this + ' ul');
                var li = $($this + ' ul li');
                var typeList = 'ul';
            }

            if (options.hideArrow == true && li.length <= Math.round(options.numberItems * options.lineNumber)) 
            {

                $($this + ' ' + options.arrowLeft + ', ' + $this + ' ' + options.arrowRight).fadeOut(350);

            }

            var cant = Math.round(options.increase * options.lineNumber);

            if (li.length % cant != 0)
             { // --- Ojo arreglar esta parte del código para que funcionen muy bien los carrousell. --- //

                for (i = 0; i < Math.round(cant - (li.length % cant)); i++) {

                    list.append('<li></li>');

                }

                var a = li.length + Math.round(cant - (li.length % cant));

            } else 
            {

                var a = li.length;

            }

            if (options.horizontal)
             {

                var b = li.outerWidth(true);

            } else 
            {

                var b = li.outerHeight(true);

            }

            if (options.numberItems != 0) 
            {                
                var c = Math.round(options.numberItems * b);

            } else 
            {

                var c = Math.round((a * b) / options.lineNumber);

            }
            
            var d = b * options.increase;
            var e = c - d;
            var f = c - b;
            
            		
            //console.log(options.increase);
            if (list.attr('id') == 'ctl00_ContentPlaceHolder1_fooCarrousel') 
            {
                c = c;                    
                e = c;
                f = c;                
                list.css({ 'width': c + 'px' });
            }else{
                
                if (options.horizontal) 
                {
                    list.css({ 'width': c + 'px', 'left': '0px' });

                } else 
                {            
                    list.css({ 'height': c + 'px', 'top': '0px' });
                }
            }

            //console.log('a = numero items: ' + a);
            //console.log('b = ancho Items: ' + b);
            //console.log('c = ancho Total: ' + c);
            //console.log('d = posicion Aumenta: ' + d);
            //console.log('e = posicion Final: ' + e);
            //console.log('f = Ultimo Item: ' + f);
            ////console.log('g = posicion Actual: ' + g);	



            if (options.skin) {

                if (options.skinCookie) {

                    if ($.cookie('skin') === null) {

                        var id = $($this + ' ol li:eq(0)').attr('id');

                        $('#' + id).addClass('skinActive');

                        $.cookie('skin', id);

                        var idProduct = $($this + ' ol li:eq(0) span').html();

                        $.cookie('idProducto', null);
                        $.cookie('idProducto', idProduct);

                        sessvars.skin = id;
                        $("#stylesheet").attr("href", "App_Themes/" + id + "/style-" + id + ".css");

                    } else {

                        // alert($.cookie('skin'));

                        $($this + ' ol li').removeClass('skinActive');
                        $('#' + $.cookie('skin')).addClass('skinActive');

                        $($this + ' ol').css('left', '-' + parseInt($('#' + $.cookie('skin')).offset().left - $($this + ' ol').offset().left) + 'px');

                        sessvars.skin = $.cookie('skin');

                        foo = sessvars.skin;
                        $("#stylesheet").attr("href", "App_Themes/" + foo + "/style-" + foo + ".css");
                    }
                }
            }

            $($this + ' ' + options.arrowLeft).click(function () {

                var g = parseInt(list.css('left'));

                if (options.transtition) {

                    if (g < 0) {

                        list.fadeOut(350, function () {

                            cambioPrevSkin();

                            $(this).css('left', g + d + 'px').fadeIn(250);

                        });

                    } else if (g == 0) {

                        list.fadeOut(350, function () {

                            cambioPrevSkin();

                            $(this).css('left', -f + 'px').fadeIn(250);

                        });

                    }

                } else {

                    if ($($this + ' ' + parent + ' ' + typeList + ':animated').html() != list.html()) {
                        if (g < 0) {
                            list.animate({
                                left: g + d
                            }, options.velocity, options.typeEasing);
                        } else if (g == 0) {
                            list.animate({
                                left: -f
                            }, Math.round((options.velocity * a) / 2), options.typeEasing);
                        }

                        cambioPrevSkin();

                    }

                }
                return false;

            });

            function cambioPrevSkin() {

                if (options.skin) {

                    if ($($this + ' ol li.skinActive').html() == $($this + ' ol li:eq(0)').html()) {

                        var nextSkin = $($this + ' ol li:last');

                    } else {

                        var nextSkin = $($this + ' ol li.skinActive').prev();

                    }

                    $($this + ' ol li').removeClass('skinActive');
                    nextSkin.addClass('skinActive');


                    var idProducto = nextSkin.find('span').html();
                    var id = nextSkin.attr('id');

                    $.stylesheetSwitch(id);

                    $.cookie('skin', null);
                    $.cookie('skin', id);

                    $.cookie('idProducto', null);
                    $.cookie('idProducto', idProducto);

                    sessvars.skin = id;
                    $("#stylesheet").attr("href", "App_Themes/" + id + "/style-" + id + ".css");
                }
            }

            $($this + ' ' + options.arrowRight).click(function () {

                var g = parseInt(list.css('left'));

                if (options.transtition) {

                    if (g > -e) {

                        list.fadeOut(350, function () {

                            cambioNextSkin();

                            $(this).css('left', g - d + 'px').fadeIn(250);

                        });

                    } else if (g == -f) {

                        list.fadeOut(350, function () {

                            cambioNextSkin();

                            $(this).css('left', '0px').fadeIn(250);

                        });

                    }

                } else {

                    if ($($this + ' ' + parent + ' ' + typeList + ':animated').html() != list.html()) {
                        if (g > -e) {
                            list.animate({
                                left: g - d
                            }, options.velocity, options.typeEasing);
                        } else if (g == -f) {
                            list.animate({
                                left: '0px'
                            }, Math.round((options.velocity * a) / 2), options.typeEasing);
                        }

                        cambioNextSkin();

                    }

                }
                return false;

            });

            function cambioNextSkin() {

                if (options.skin) {

                    if ($($this + ' ol li.skinActive').html() == $($this + ' ol li:last').html()) {

                        var nextSkin = $($this + ' ol li:eq(0)');

                    } else {

                        var nextSkin = $($this + ' ol li.skinActive').next();

                    }

                    $($this + ' ol li').removeClass('skinActive');
                    nextSkin.addClass('skinActive');

                    var idProducto = nextSkin.find('span').html();
                    var id = nextSkin.attr('id');

                    $.stylesheetSwitch(id);

                    $.cookie('skin', null);
                    $.cookie('skin', id);

                    $.cookie('idProducto', null);
                    $.cookie('idProducto', idProducto);

                    sessvars.skin = id;
                    $("#stylesheet").attr("href", "App_Themes/" + id + "/style-" + id + ".css");
                }
            }
        });
    }

    $.fn.jPageCorrousel = function (options) {

        var defaults = {
            easing: 'linear'
        };
        var options = $.extend(defaults, options);

        this.each(function () {

            if ($(this).attr('class')) {

                var $this = '.' + $(this).attr('class');

            } else if ($(this).attr('id')) {

                var $this = '#' + $(this).attr('id');

            }

            var ol = $($this + ' ol');
            var li = $($this + ' ol li');

            ol.width(li.length * 1000);

            $($this + ' ol li:eq(0)').addClass('activePage');

            for (i = 1; i <= li.length; i++) {

                $('.cicleSelect').append('<span></span>');

                if (i == 1) {

                    $('.cicleSelect span').addClass('actPage');

                }

            }

            if (li.length == 1) {
                $('.cicleSelect').fadeOut(350);
                $('.flechas-jPage').fadeOut(350);
            }

            $('.cicleSelect').each(function (i) {

                $('.cicleSelect:eq(' + i + ') span').click(function () {

                    var n = $('.cicleSelect:eq(' + i + ') span').index(this);

                    if ($('.cicleSelect:eq(' + i + ') span:eq(' + n + ')').attr('class') != 'actPage') {

                        $('.cicleSelect').each(function (o) {

                            $('.cicleSelect:eq(' + o + ') span').removeClass('actPage');
                            $('.cicleSelect:eq(' + o + ') span:eq(' + n + ')').addClass('actPage');

                        });

                        var actual = parseInt($($this + ' ol li:eq(' + n + ')').offset().left - $($this + ' ol').offset().left);

                        $($this + ' ol li').removeClass('activePage');
                        $($this + ' ol li:eq(' + n + ')').addClass('activePage');

                        $($this + ' ol').fadeOut(350, function () {

                            $($this + ' ol').css('left', -actual + 'px').fadeIn(350);

                        });

                    }

                });

            });

            $('.flechas-jPage .left-flecha').click(function () {

                var actual = parseInt($($this + ' ol').css('left'));


                if (actual < 0) {

                    $('.cicleSelect').each(function (o) {

                        var a = $('.cicleSelect:eq(' + o + ') span').index($('.actPage')) - 1;

                        $('.cicleSelect:eq(' + o + ') span').removeClass('actPage');
                        $('.cicleSelect:eq(' + o + ') span:eq(' + a + ')').addClass('actPage');

                    });

                    var selector = $($this + ' ol li.activePage').prev();


                    $($this + ' ol li').removeClass('activePage');
                    selector.addClass('activePage');

                    $($this + ' ol').fadeOut(350, function () {

                        $($this + ' ol').css('left', Math.round(actual + 1000) + 'px').fadeIn(350);

                    });

                } else if (actual == 0) {

                    $('.cicleSelect').each(function (o) {

                        $('.cicleSelect:eq(' + o + ') span').removeClass('actPage');
                        $('.cicleSelect:eq(' + o + ') span').last().addClass('actPage');

                    });

                    $($this + ' ol li').removeClass('activePage');
                    $($this + ' ol li').last().addClass('activePage');

                    $($this + ' ol').fadeOut(350, function () {

                        $($this + ' ol').css('left', Math.round(-(li.length * 1000) + 1000) + 'px').fadeIn(350);

                    });


                }

                return false;

            });

            $('.flechas-jPage .right-flecha').click(function () {

                var actual = parseInt($($this + ' ol').css('left'));

                if (actual > Math.round(-(li.length * 1000) + 1000)) {

                    $('.cicleSelect').each(function (o) {

                        var a = $('.cicleSelect:eq(' + o + ') span').index($('.actPage')) + 1;

                        $('.cicleSelect:eq(' + o + ') span').removeClass('actPage');
                        $('.cicleSelect:eq(' + o + ') span:eq(' + a + ')').addClass('actPage');

                    });

                    var selector = $($this + ' ol li.activePage').next();

                    $($this + ' ol li').removeClass('activePage');
                    selector.addClass('activePage');

                    $($this + ' ol').fadeOut(350, function () {

                        $($this + ' ol').css('left', Math.round(actual - 1000) + 'px').fadeIn(350);

                    });

                } else if (actual == Math.round(-(li.length * 1000) + 1000)) {

                    $('.cicleSelect').each(function (o) {

                        $('.cicleSelect:eq(' + o + ') span').removeClass('actPage');
                        $('.cicleSelect:eq(' + o + ') span:eq(0)').addClass('actPage');

                    });

                    $($this + ' ol li').removeClass('activePage');
                    $($this + ' ol li:eq(0)').addClass('activePage');

                    $($this + ' ol').fadeOut(350, function () {

                        $($this + ' ol').css('left', '0px').fadeIn(350);

                    });

                }

                return false;

            });

        });
    }

    $.fn.jColor = function (options) {

        var defaults = {
            easing: 'linear'
        };
        var options = $.extend(defaults, options);

        this.each(function () {
            /*
            .selec-color
            */

            var $this = '.' + $(this).attr('class');

            var cant = $('.datos-colores span.color-type').length;

            for (i = 0; i < 12; i = i + 1) {

                var a = $('.datos-colores span.color-type:eq(' + i + ') .hex-color').html();
                var b = $('.datos-colores span.color-type:eq(' + i + ') .img-color').html();


                if (a != '' && b == '') {

                    $('.selec-color .content-colors').append('<span style="background: ' + a + ';">' + i + '</span>');

                } else if (a == '' && b != '') {

                    $('.selec-color .content-colors').append('<span style="background: url(' + b + ') repeat scroll 0 0 transparent;">' + i + '</span>'); // Especificar bien la ruta

                } else if (a != '' && b != '') {

                    $('.selec-color .content-colors').append('<span style="background: url(' + b + ') repeat scroll 0 0 ' + a + ';">' + i + '</span>'); // Especificar bien la ruta

                }

            }

            $('.selec-color .mas-colors').click(function () {

                $('#zona-emergente').fadeIn(350);
                $('.color-emergente').css('margin', '-' + Math.round($('.color-emergente').height() / 2) + 'px 0 0 -287px');
                $('.color-emergente').fadeIn(350);
                $('.paleta-color-grande').css('display', 'none');

            });

            $('.color-emergente .cerrar-modal').click(function () {

                $('#zona-emergente').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });

                $('.color-emergente').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });

                $('.paleta-color-grande').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });

            });

            for (i = 0; i < cant; i++) {

                var a = $('.datos-colores span.color-type:eq(' + i + ') .hex-color').html();
                var b = $('.datos-colores span.color-type:eq(' + i + ') .img-color').html();
                var c = $('.datos-colores span.color-type:eq(' + i + ') .name-color').html();
                var d = $('.datos-colores span.color-type:eq(' + i + ') .num-color').html();


                //				if (a != '' && b == '') {
                //					
                //					$('.color-view').append('<span class="color-type"><span class="color-modal" style="background: '+a+';">'+i+'</span><span class="nom-color-modal">'+c+'</span><span class="num-color-modal">'+d+'</span></span>');
                //					
                //				} else if (a == '' && b != '' ){
                //					
                //					$('.color-view').append('<span class="color-type"><span class="color-modal" style="background: url('+b+') repeat scroll 0 0 transparent;">'+i+'</span><span class="nom-color-modal">'+c+'</span><span class="num-color-modal">'+d+'</span></span>');  // Especificar bien la ruta
                //					
                //				} else if (a != '' && b != '') {
                //					
                //					$('.color-view').append('<span class="color-type" style="background: url('+b+') repeat scroll 0 0 '+a+';"><span class="color-modal">'+i+'</span><span class="nom-color-modal">'+c+'</span><span class="num-color-modal">'+d+'</span></span>'); // Especificar bien la ruta
                //					
                //				}



                if (a != "" && b == '') {

                    $('.color-view').append('<span class="color-type"><span class="color-modal" style="background: ' + a + ';">' + i + '</span><span class="nom-color-modal">' + c + '</span><span class="num-color-modal">' + d + '</span></span>');
                    //$('.color-view').append('<span class="color-modal" style="background: '+a+';">'+i+'</span><span class="nom-color-modal">'+c+'</span><span class="num-color-modal">'+d+'</span>');
                } else if (a == "" && b != '') {

                    $('.color-view').append('<span class="color-type"><span class="color-modal" style="background: url(' + b + ') repeat scroll 0 0 transparent;">' + i + '</span><span class="nom-color-modal">' + c + '</span><span class="num-color-modal">' + d + '</span></span>');  // Especificar bien la ruta

                } else if (a != "" && b != '') {

                    //$('.color-view').append('<span class="color-type" style="background: url('+b+') repeat scroll 0 0 '+a+';"><span class="color-modal">'+i+'</span><span class="nom-color-modal">'+c+'</span><span class="num-color-modal">'+d+'</span></span>'); // Especificar bien la ruta
                    $('.color-view').append('<span class="color-type" ><span class="color-modal" style="background: url(' + b + ') repeat scroll 0 0 ' + a + ';">' + i + '</span><span class="nom-color-modal">' + c + '</span><span class="num-color-modal">' + d + '</span></span>'); // Especificar bien la ruta

                }



            }

            var x;
            var y;
            var n;

            $($this + ' span.selectColor').mousemove(function (e) {

                x = e.pageX;
                y = e.pageY;

            });

            $($this + ' span.selectColor').click(function (a) {

                n = $($this + ' span.selectColor').index(this);

                var $offset = $('.delate-color', this).offset();
                
                
                var xa = a.pageX;
                var ya = a.pageY;             


//                if($offset != null)
                    //console.log($offset); 
                //else 
                    //console.log('null');
                

                xa1 = xa2 = ya1 = ya2 = 0;

                if($offset != null){
                    xa1 = $offset.left;
                    xa2 = $offset.left + 20;
                    ya1 = $offset.top;
                    ya2 = $offset.top + 20;
                }                

//                //console.log(xa1);
//                //console.log(xa);                
//                //console.log(xa2);
//                //console.log('----');
//                //console.log(ya1);
//                //console.log(ya);
//                //console.log(ya2);

//                if ($(this).html() == '<small class="delate-color"></small>' && 
//                xa > Math.round($offset.left - 1) && 
//                xa > Math.round($offset.top - 1) && 
//                ya < Math.round($offset.left + 50) && 
//                ya < Math.round($offset.top + 50)) {

                //if ($(this).html() == '<small class="delate-color"></small>' && xa >= xa1 && xa <= xa2 && ya >= ya1 && ya <= ya2) 
                
                if (xa >= xa1 && xa <= xa2 && ya >= ya1 && ya <= ya2) 
                {
                
                    //console.log('eevnto ');
                    if ($('.selec-color').css('top') != '0px' && $('.selec-color').css('left') != '0px') 
                    {
                        $('.selec-color').fadeOut(350, function () 
                        {
                            $('.selec-color').css({ 'top': '0px', 'left': '0px' });
                        });
                    }

                    $($this + ' span.selectColor:eq(' + n + ')').attr('style', '').html('<span>HAZ CLIC PARA<br>SELECCIONAR UN COLOR</span>');
                    $('.paleta-color-modal span.selectColor-modal:eq(' + n + ')').attr('style', '').html('<span>SIN COLOR</span>');

                    $($this + ' .dateColor .infoColor:eq(' + n + ') .nameColor').html('');
                    $($this + ' .dateColor .infoColor:eq(' + n + ') .numColor').html('');

                    $('.dateColor-modal .infoColor-modal:eq(' + n + ') .nameColor-modal').html('');
                    $('.dateColor-modal .infoColor-modal:eq(' + n + ') .numColor-modal').html('');

                    if (n == 0) { $('.top-paleta').css('border-left', '1px solid #B5B5B5'); }

                    ////console.log('x: ' + xa + ', y: ' + ya);
                    ////console.log('small x: ' + Math.round($offset.left - 10) + ', small y: ' + Math.round($offset.top - 10));

                } else 
                {

                    if ($('.selec-color').css('top') == '0px' && $('.selec-color').css('left') == '0px') 
                    {

                        $('.selec-color').css({ 'top': y + 'px', 'left': x + 'px' });
                        $('.selec-color').fadeIn(350);

                    }

                    $('.selec-color').animate({
                        left: x + 'px',
                        top: y + 'px'
                    }, 500);
                }
                
            });

            $('.selec-color span').click(function () {

                var a = $(this).html();
                var b = $('.datos-colores span.color-type:eq(' + a + ') .hex-color').html();
                var c = $('.datos-colores span.color-type:eq(' + a + ') .img-color').html();

                if ($('.selec-color').css('top') != '0px' && $('.selec-color').css('left') != '0px') {

                    if ($($this + ' .dateColor').css('display') == 'none') {
                        $($this + ' .dateColor').fadeIn(350)
                    }

                    if (n == 0) { $('.top-paleta').css('border-left', '0 none'); }

                    if (b != '' && c == '') {

                        $($this + ' span.selectColor:eq(' + n + ')').css({ 'background': b, 'border': '0 none', 'width': '236px', 'height': '365px' }).html('<small class="delate-color"></small>');
                        $('.paleta-color-modal span.selectColor-modal:eq(' + n + ')').css({ 'background': b, 'border': '0 none', 'width': '284px', 'height': '437px' }).html('');

                    } else if (b == '' && c != '') {

                        $($this + ' span.selectColor:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 transparent', 'width': '236px', 'height': '365px' }).html('<small class="delate-color"></small>'); // Especificar bien la ruta
                        $('.paleta-color-modal span.selectColor-modal:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 transparent', 'width': '284px', 'height': '437px' }).html(''); // Especificar bien la ruta

                    } else if (b != '' && c != '') {

                        $($this + ' span.selectColor:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 ' + b, 'width': '236px', 'height': '365px' }).html('<small class="delate-color"></small>'); // Especificar bien la ruta
                        $('.paleta-color-modal span.selectColor-modal:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 ' + b, 'width': '284px', 'height': '437px' }).html(''); // Especificar bien la ruta

                    }

                    if ($.browser.msie && $.browser.version == 7 || $.browser.version == 8) { $('.delate-color').css('display', 'block'); }

                    $($this + ' .dateColor .infoColor:eq(' + n + ') .nameColor').html($('.datos-colores span.color-type:eq(' + a + ') .name-color').html());
                    $($this + ' .dateColor .infoColor:eq(' + n + ') .numColor').html($('.datos-colores span.color-type:eq(' + a + ') .num-color').html());

                    $('.dateColor-modal .infoColor-modal:eq(' + n + ') .nameColor-modal').html($('.datos-colores span.color-type:eq(' + a + ') .name-color').html());
                    $('.dateColor-modal .infoColor-modal:eq(' + n + ') .numColor-modal').html($('.datos-colores span.color-type:eq(' + a + ') .num-color').html());

                    $('.selec-color').fadeOut(200, function () {

                        $(this).css({ 'top': '0px', 'left': '0px' });

                    });

                }

            });

            $('nav.mas-colors').click(function () {

                if ($('.selec-color').css('top') != '0px' && $('.selec-color').css('left') != '0px') {

                    $('.selec-color').fadeOut(350, function () {

                        $('.selec-color').css({ 'top': '0px', 'left': '0px' });

                    });

                }

            });

            $('.color-type .color-modal').click(function () {

                var a = $(this).html();
                var b = $('.datos-colores span.color-type:eq(' + a + ') .hex-color').html();
                var c = $('.datos-colores span.color-type:eq(' + a + ') .img-color').html();

                if (n == 0) { $('.top-paleta').css('border-left', '0 none'); }

                if ($($this + ' .dateColor').css('display') == 'none') { $($this + ' .dateColor').fadeIn(350); }

                if (b != '' && c == '') {

                    $($this + ' span.selectColor:eq(' + n + ')').css({ 'background': b, 'border': '0 none', 'width': '236px', 'height': '365px' }).html('<small class="delate-color"></small>');
                    $('.paleta-color-modal span.selectColor-modal:eq(' + n + ')').css({ 'background': b, 'border': '0 none', 'width': '284px', 'height': '437px' }).html('');

                } else if (b == '' && c != '') {

                    $($this + ' span.selectColor:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 transparent', 'width': '236px', 'height': '365px' }).html('<small class="delate-color"></small>'); // Especificar bien la ruta
                    $('.paleta-color-modal span.selectColor-modal:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 transparent', 'width': '284px', 'height': '437px' }).html(''); // Especificar bien la ruta

                } else if (b != '' && c != '') {

                    $($this + ' span.selectColor:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 ' + b, 'width': '236px', 'height': '365px' }).html('<small class="delate-color"></small>'); // Especificar bien la ruta
                    $('.paleta-color-modal span.selectColor-modal:eq(' + n + ')').css({ 'background': 'url(' + c + ') repeat scroll 0 0 ' + b, 'width': '284px', 'height': '437px' }).html(''); // Especificar bien la ruta

                }

                if ($.browser.msie && $.browser.version == 7 || $.browser.version == 8) { $('.delate-color').css('display', 'block'); }

                $($this + ' .dateColor .infoColor:eq(' + n + ') .nameColor').html($('.datos-colores span.color-type:eq(' + a + ') .name-color').html());
                $($this + ' .dateColor .infoColor:eq(' + n + ') .numColor').html($('.datos-colores span.color-type:eq(' + a + ') .num-color').html());

                $('.dateColor-modal .infoColor-modal:eq(' + n + ') .nameColor-modal').html($('.datos-colores span.color-type:eq(' + a + ') .name-color').html());
                $('.dateColor-modal .infoColor-modal:eq(' + n + ') .numColor-modal').html($('.datos-colores span.color-type:eq(' + a + ') .num-color').html());

                $('#zona-emergente').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });
                $('.color-emergente').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });

            });

            $('.ampliarColores').click(function () {

                $('#zona-emergente').fadeIn(350);
                $('#zona-emergente .paleta-color-grande').fadeIn(350);
                $('#zona-emergente .color-emergente').css('display', 'none');

            });

            $('.paleta-color-grande .cerrar-modal').click(function () {

                $('#zona-emergente').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });

                $('#zona-emergente .paleta-color-grande').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });

                $('#zona-emergente .color-emergente').fadeOut(350, function () {
                    $(this).css('display', 'none');
                    $(this).removeAttr('style');
                });

            });

            $('.title-modal h1').html($('.text-combinalo h3').html());

        });
    }



})(jQuery);

; window.Modernizr = function (a, b, c) { function A(a, b) { var c = a.charAt(0).toUpperCase() + a.substr(1), d = (a + " " + n.join(c + " ") + c).split(" "); return z(d, b) } function z(a, b) { for (var d in a) if (k[a[d]] !== c) return b == "pfx" ? a[d] : !0; return !1 } function y(a, b) { return !! ~("" + a).indexOf(b) } function x(a, b) { return typeof a === b } function w(a, b) { return v(prefixes.join(a + ";") + (b || "")) } function v(a) { k.cssText = a } var d = "2.0.6", e = {}, f = !0, g = b.documentElement, h = b.head || b.getElementsByTagName("head")[0], i = "modernizr", j = b.createElement(i), k = j.style, l, m = Object.prototype.toString, n = "Webkit Moz O ms Khtml".split(" "), o = {}, p = {}, q = {}, r = [], s, t = {}.hasOwnProperty, u; !x(t, c) && !x(t.call, c) ? u = function (a, b) { return t.call(a, b) } : u = function (a, b) { return b in a && x(a.constructor.prototype[b], c) }, o.csstransitions = function () { return A("transitionProperty") }; for (var B in o) u(o, B) && (s = B.toLowerCase(), e[s] = o[B](), r.push((e[s] ? "" : "no-") + s)); v(""), j = l = null, e._version = d, e._domPrefixes = n, e.testProp = function (a) { return z([a]) }, e.testAllProps = A, g.className = g.className.replace(/\bno-js\b/, "") + (f ? " js " + r.join(" ") : ""); return e } (this, this.document), function (a, b, c) { function k(a) { return !a || a == "loaded" || a == "complete" } function j() { var a = 1, b = -1; while (p.length - ++b) if (p[b].s && !(a = p[b].r)) break; a && g() } function i(a) { var c = b.createElement("script"), d; c.src = a.s, c.onreadystatechange = c.onload = function () { !d && k(c.readyState) && (d = 1, j(), c.onload = c.onreadystatechange = null) }, m(function () { d || (d = 1, j()) }, H.errorTimeout), a.e ? c.onload() : n.parentNode.insertBefore(c, n) } function h(a) { var c = b.createElement("link"), d; c.href = a.s, c.rel = "stylesheet", c.type = "text/css"; if (!a.e && (w || r)) { var e = function (a) { m(function () { if (!d) try { a.sheet.cssRules.length ? (d = 1, j()) : e(a) } catch (b) { b.code == 1e3 || b.message == "security" || b.message == "denied" ? (d = 1, m(function () { j() }, 0)) : e(a) } }, 0) }; e(c) } else c.onload = function () { d || (d = 1, m(function () { j() }, 0)) }, a.e && c.onload(); m(function () { d || (d = 1, j()) }, H.errorTimeout), !a.e && n.parentNode.insertBefore(c, n) } function g() { var a = p.shift(); q = 1, a ? a.t ? m(function () { a.t == "c" ? h(a) : i(a) }, 0) : (a(), j()) : q = 0 } function f(a, c, d, e, f, h) { function i() { !o && k(l.readyState) && (r.r = o = 1, !q && j(), l.onload = l.onreadystatechange = null, m(function () { u.removeChild(l) }, 0)) } var l = b.createElement(a), o = 0, r = { t: d, s: c, e: h }; l.src = l.data = c, !s && (l.style.display = "none"), l.width = l.height = "0", a != "object" && (l.type = d), l.onload = l.onreadystatechange = i, a == "img" ? l.onerror = i : a == "script" && (l.onerror = function () { r.e = r.r = 1, g() }), p.splice(e, 0, r), u.insertBefore(l, s ? null : n), m(function () { o || (u.removeChild(l), r.r = r.e = o = 1, j()) }, H.errorTimeout) } function e(a, b, c) { var d = b == "c" ? z : y; q = 0, b = b || "j", C(a) ? f(d, a, b, this.i++, l, c) : (p.splice(this.i++, 0, a), p.length == 1 && g()); return this } function d() { var a = H; a.loader = { load: e, i: 0 }; return a } var l = b.documentElement, m = a.setTimeout, n = b.getElementsByTagName("script")[0], o = {}.toString, p = [], q = 0, r = "MozAppearance" in l.style, s = r && !!b.createRange().compareNode, t = r && !s, u = s ? l : n.parentNode, v = a.opera && o.call(a.opera) == "[object Opera]", w = "webkitAppearance" in l.style, x = w && "async" in b.createElement("script"), y = r ? "object" : v || x ? "img" : "script", z = w ? "img" : y, A = Array.isArray || function (a) { return o.call(a) == "[object Array]" }, B = function (a) { return Object(a) === a }, C = function (a) { return typeof a == "string" }, D = function (a) { return o.call(a) == "[object Function]" }, E = [], F = {}, G, H; H = function (a) { function f(a) { var b = a.split("!"), c = E.length, d = b.pop(), e = b.length, f = { url: d, origUrl: d, prefixes: b }, g, h; for (h = 0; h < e; h++) g = F[b[h]], g && (f = g(f)); for (h = 0; h < c; h++) f = E[h](f); return f } function e(a, b, e, g, h) { var i = f(a), j = i.autoCallback; if (!i.bypass) { b && (b = D(b) ? b : b[a] || b[g] || b[a.split("/").pop().split("?")[0]]); if (i.instead) return i.instead(a, b, e, g, h); e.load(i.url, i.forceCSS || !i.forceJS && /css$/.test(i.url) ? "c" : c, i.noexec), (D(b) || D(j)) && e.load(function () { d(), b && b(i.origUrl, h, g), j && j(i.origUrl, h, g) }) } } function b(a, b) { function c(a) { if (C(a)) e(a, h, b, 0, d); else if (B(a)) for (i in a) a.hasOwnProperty(i) && e(a[i], h, b, i, d) } var d = !!a.test, f = d ? a.yep : a.nope, g = a.load || a.both, h = a.callback, i; c(f), c(g), a.complete && b.load(a.complete) } var g, h, i = this.yepnope.loader; if (C(a)) e(a, 0, i, 0); else if (A(a)) for (g = 0; g < a.length; g++) h = a[g], C(h) ? e(h, 0, i, 0) : A(h) ? H(h) : B(h) && b(h, i); else B(a) && b(a, i) }, H.addPrefix = function (a, b) { F[a] = b }, H.addFilter = function (a) { E.push(a) }, H.errorTimeout = 1e4, b.readyState == null && b.addEventListener && (b.readyState = "loading", b.addEventListener("DOMContentLoaded", G = function () { b.removeEventListener("DOMContentLoaded", G, 0), b.readyState = "complete" }, 0)), a.yepnope = d() } (this, this.document), Modernizr.load = function () { yepnope.apply(window, [].slice.call(arguments, 0)) };
