$(function () {
    $(document).on('click', function (e) {
        if (e.target.className == "glyphicon glyphicon-search") {
            $(".search-form .form-control").addClass('active');
        } else {
            $(".search-form .form-control").removeClass('active');
        }
    });
    $(document).on('click','.decrease',function(){
            var idclick = $(this).attr('relid');
            var qty =  $('.itemcart_'+idclick).val();
            
            var qincrea = (parseInt(qty)-1)
            if(qincrea>1 && qincrea<=10){
                
                $('.itemcart_'+idclick).val((qincrea)); 
            }else{
                qincrea =1;
                $('.itemcart_'+idclick).val(qincrea);  
            }

            // $.ajax({
            //     url: url_site+'fajax/updateCart',
            //     type: 'POST',
            //     dataType: 'JSON',
            //     data: {'qty':qincrea,'rowid':idclick},
            //     beforeSend: REGISTER.startLoading,
            //     complete: REGISTER.topLoading
            // }).done(function(response) {
            //     $('#itemcart_'+idclick+' .subtotal').text(response.price);
            // });
            
            return false;

        });
         if($('.tab-content #home').length>0){
            $('.tab-content #home').find('img').each(function(){
                var width= $(this).attr("width");
                var height = $(this).removeAttr("height");
                   var div_width = $('.tab-content #home').width();
                   if(width === undefined){ 
                      $(this).attr('width',div_width)
                   }else if(width>div_width){
                        $(this).attr('width',div_width)
                        $(this).attr('height','auto')
                    }
                var imgSrc=$(this).attr('src'); 
                //getImgSize(imgSrc);
            });

        }
        $(document).on('click','.increase',function(){
            var idclick = $(this).attr('relid');
            var qty =  $('.itemcart_'+idclick).val(); 
           var qincrea=10;
            if(qty<10){
                var qincrea = (parseInt(qty)+1)
                $('.itemcart_'+idclick).val((qincrea));
            }else{
                $('.itemcart_'+idclick).val(qincrea);
            }
            // $.ajax({
            //     url: url_site+'fajax/updateCart',
            //     type: 'POST',
            //     dataType: 'JSON',
            //     data: {'qty':qincrea,'rowid':idclick},
            //     beforeSend: REGISTER.startLoading,
            //     complete: REGISTER.topLoading
            // }).done(function(response) {
            //    $('#itemcart_'+idclick+' .subtotal').text(response.price); 
            // });
            
            return false;

        });  
        
     $(document).on('click','#itemviewvideo',function(){
        var link    = $(this).attr('reldata');
        var title   = $(this).attr('reltitle');
        link = link.split('/');
        var code= link[(link.length)-1];
        $('#maintainvideo').html('<iframe width="100%" height="480" src="https://www.youtube.com/embed/'+code+'" frameborder="0" allowfullscreen></iframe>');
        $('#titlevideo').html(title);
        $('#popupvideo').modal('show');
        return false;

    });
    $('#popupvideo').on('hidden.bs.modal', function (e) {
        $('#maintainvideo').html('');
    })
    if($('#slide-banner').length>0){    
        $('#slide-banner').owlCarousel({
            autoplay: true,
            autoplayTimeout:2500,
            autoWidth: false,
            items: 1,
            dots: true,
            nav: false,
            loop: true,
            lazyLoad: true,
			responsive: {
				0: {items: 1},
				320: {
					items: 1
				},
				480: {
					items: 1
				},
				640: {
					items: 1
				},
				992: {
					items:1
				},
				1024: {
					items:1
				}
			}
        });
    } 
    if($('#slide-vsattp').length>0){
        $('#slide-vsattp').owlCarousel({
            autoplay: true,
            autoplayTimeout:2500,
            autoWidth: false,
            items: 1,
            dots: true,
            nav: false,
            loop: true,
            lazyLoad: true
        });
    } 
    if($('.slide_video').length>0){
        $('.slide_video').owlCarousel({
            autoplay: true,
            autoplayTimeout:2500,
            autoWidth: false,
            items: 1,
            dots: true,
            nav: false,
            loop: true,
            lazyLoad: true
        });
    } 
    if($('#ads-fullcenter').length>0){
        $('#ads-fullcenter').owlCarousel({
         //   autoplay: true,
            autoplayTimeout:2500,
            autoWidth: true,
            items: 2,
            dots: true,
            nav: false,
            loop: true,
            lazyLoad: true
        });
    } 
    if($('#boxes').length>0){
        var itemNav = (itemNav)?itemNav:9;
    $('#boxes').owlCarousel({
        items: itemNav,
        dots: false, 
        ///autoplay: true,
        nav: false,
        loop: true,
        lazyLoad: true,
        margin: 20,
        responsive: {
            0: {items: 1},
            320: {
                items: 2
            },
            480: {
                items: 3
            },
            640: {
                items: 4
            },
            992: {
                items: 5
            },
            1024: {
                items: itemNav
            }
        }
    });
    }
    $('#products.salse').owlCarousel({
        autoWidth: false,
        dots: false,
        nav: true,
        loop: true,
        // autoplay: true,
         autoplayTimeout:1500,
        lazyLoad: true,
        margin: 24,
        responsive: {
            0: {items: 1},
            360: {
                items: 2
            },
            640: {
                items: 3
            },
            768: {
                items: 3
            }
        }
    });
    $('#products.top').owlCarousel({
        autoWidth: false,
        dots: false,
        nav: true,
        loop: true, 
         //autoplay: true,
         autoplayTimeout:1500,
        lazyLoad: true,
        margin: 24,
        responsive: {
            0: {items: 1},
            360: {
                items: 2
            },
            640: {
                items: 2
            },
            768: {
                items: 3
            }
        }
    });
    $('.product-catalog-grid').owlCarousel({
        dots: false,
        nav: false,
        loop: true, 
        // autoplay: true,
         autoplayTimeout:1500,
        lazyLoad: true,
        margin: 24,
        responsive: {
            0: {items: 1},
            360: {
                items: 2
            },
            640: {
                items: 3
            },
            768: {
                items: 4
            }
        }
    });
    // $('#videos').owlCarousel({
    //     dots: false,
    //     nav: true,
    //     loop: true,
    //     lazyLoad: true,
    //     margin: 32,
    //     responsive: {
    //         0: {items: 1},
    //         560: {
    //             items: 2
    //         },
    //         768: {
    //             items: 3
    //         }
    //     }
    // });

    $('#partners').owlCarousel({
        autoWidth: true,
        dots: false,
        nav: false,
        loop: true,
        lazyLoad: true,
        margin: 32,
        responsive: {
            0: {items: 1},
            320: {
                items: 2
            },
            480: {
                items: 3
            },
            640: {
                items: 4
            },
            768: {
                items: 6
            }
        }
    });

    $('.side-left-product').owlCarousel({
        items: 1,
        autoWidth: false,
        dots: false,
        nav: true, autoplayTimeout:1500,
        loop: true,
        lazyLoad: true
    });

    $('.product-catalog-grid-2').owlCarousel({
        dots: false,
        nav: false,
        loop: true,
        lazyLoad: true,
        margin: 24,
        responsive: {
            0: {items: 1},
            360: {
                items: 2
            },
            480: {
                items: 3
            }
        }
    });
    
    // Product Detail
    CloudZoom.quickStart();
    $('#slider1').Thumbelina({
        $bwdBut: $('#slider1 .left'),
        $fwdBut: $('#slider1 .right')
    });
    var thumbW = $('.thumbelina li').size() * $('.thumbelina li').width();
    $('.thumbelina li').width(thumbW);
    

    // End Product detail
});

