$(document).ready(function() {
    $(window).bind('scroll', function() {
        if ($(window).scrollTop() > 50) {
            $('#menu').addClass('navbar-fixed-top');
        }
        else {
            $('#menu').removeClass('navbar-fixed-top');
        }
    });
    function flyToElement(flyer, flyingTo, callBack /*callback is optional*/) {
        var $func = $(this);

        var divider = 3;

        var flyerClone = $(flyer).clone();
        $(flyerClone).css({
            position: 'absolute',
            top: $(flyer).offset().top + "px",
            left: $(flyer).offset().left + "px",
            opacity: 1,
            'z-index': 1000
        });
        $('body').append($(flyerClone));

        var gotoX = $(flyingTo).offset().left + ($(flyingTo).width() / 2) - ($(flyer).width() / divider) / 2;
        var gotoY = $(flyingTo).offset().top + ($(flyingTo).height() / 2) - ($(flyer).height() / divider) / 2;

        $(flyerClone).animate({
            opacity: 0.4,
            left: gotoX,
            top: gotoY,
            width: $(flyer).width() / divider,
            height: $(flyer).height() / divider
        }, 700,
                function() {
                    $(flyingTo).fadeOut('fast', function() {
                        $(flyingTo).fadeIn('fast', function() {
                            $(flyerClone).fadeOut('fast', function() {
                                $(flyerClone).remove();
                                if (callBack != null) {
                                    callBack.apply($func);
                                }
                            });
                        });
                    });
                });
    }
    function Ini_Display_Cart() {
        $.ajax({
            type: 'GET',
            url: global_url + "index.php/yourcart/cart_json",
            dataType: "json",
            success: function(data, status) {
                var result = "";
                var header = "<table id='cart' class='table table-hover table-condensed'>\n\
                                 <thead>\n\
                                     <tr>\n\
                                        <th style='width:50%'>Product</th>\n\
                                        <th style='width:10%'>Price</th>\n\
                                        <th style='width:8%'>Quantity</th>\n\
                                        <th style='width:22%' class='text-center'>Subtotal</th>\n\
                                        <th style='width:10%'></th>\n\
                                    </tr>\n\
                                 </thead>";
                var body = " <tbody>";
                $.each(data.cart, function(i, item) {
//  console.log(i + item);
// result += "<li>" + item.id + item.name + "</li>";
                    body += "<tr id='" + item.id + "'>\n\
                            <td data-th='Product'>\n\
                                <div class='row'>\n\
                                    <div class='col-sm-9'>\n\
                                        <h4 class='nomargin'> " + item.id + "</h4>\n\
                                        <p>" + item.name + "</p>\n\
                                    </div>\n\
                                </div>\n\
                            </td>\n\
                            <td data-th='Price'>" + item.price + " VNĐ</td>\n\
                            <td data-th='Quantity'>\n\
                                <input type='number' min='1' class='form-control text-center qty' value='" + item.qty + "'>\n\
                            </td>\n\
                            <td data-th='Subtotal' class='text-center'>" + (item.qty * item.price) + "VNĐ</td>\n\
                            <td class='actions' data-th=''>\n\
                                <button class='btn btn-info btn-sm btn-update'><i class='fa fa-refresh'></i></button>\n\
                                <button class='btn btn-danger btn-sm btn-delete'><i class='fa fa-trash-o'></i></button>								\n\
                            </td>\n\
                        </tr>";
                });
                body += "</tbody>\n\
                <tfoot>\n\
                    <tr class='visible-xs'>\n\
                        <td class='text-center'><strong>Total " + "</strong></td>\n\
                    </tr>\n\
                    <tr>\n\
                        <td><a href='#' class='btn btn-primary'><i class='fa fa-arrow-left'></i> Continue Shopping</a></td>\n\
                        <td colspan='2' class='hidden-xs'></td>\n\
                        <td class='hidden-xs text-center'><strong>Total " + " VNĐ </strong></td>\n\
                        <td><a href='#' class='btn btn-danger btn-block '>Checkout <i class='fa  fa-arrow-right'></i></a></td>\n\
                    </tr>\n\
                </tfoot>\n\
            </table>";
                $("#cart-content").html(header + body);
                console.log(header + body);
                //console.log(JSON.stringify(data.cart, null, 4));

            }, error: function(data, status) {
                alert(status);
            }
        });
    }
//    validate
    $(document).on("keyup change", ".input-group input[required], .input-group textarea[required], .input-group select[required]", function(e) {
        var $form = $(this).closest('form'),
                $group = $(this).closest('.input-group'),
                $addon = $group.find('.input-group-addon'),
                $icon = $addon.find('span'),
                state = false;

        if (!$group.data('validate')) {

            state = $(this).val() ? true : false;
        } else if ($group.data('validate') == "email") {
            state = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})/.test($(this).val());
            state = state && $(this).val().length < 51;
        } else if ($group.data('validate') == 'phone') {
            state = /^[0-9]{7,12}$/.test($(this).val())
        } else if ($group.data('validate') == "length") {
            state = $(this).val().length >= $group.data('length') ? true : false;
        } else if ($group.data('validate') == "password") {
            state = $(this).val().length > 7 ? true : false;
        }
        else if ($group.data('validate') == "repassword") {

            state = $(this).val() == $("input[name=matkhau]", $(this).parents("form")).val() ? true : false;
        }
        else if ($group.data('validate') == "diachi") {

            state = $(this).val().length > 10 ? true : false;
        }
        else if ($group.data('validate') == "number") {
            state = !isNaN(parseFloat($(this).val())) && isFinite($(this).val());
        }
        else if ($group.data('validate') == "matk") {
            if (/\s/.test($(this).val()))
                state = false;
            else
                state = /^([a-zA-Z0-9_\.\-])/.test($(this).val());
        }
        else if ($group.data('validate') == "date") {
            state = true;
//            state =$(this).val()<new Date()?true:false;
//            alert(new Date());
//            alert($(this).val()<new Date());
        }


        if (state) {
            $addon.removeClass('danger');
            $addon.addClass('success');
            $icon.attr('class', 'glyphicon glyphicon-ok');
        } else {
            $addon.removeClass('success');
            $addon.addClass('danger');
            $icon.attr('class', 'glyphicon glyphicon-remove');
        }

        if ($form.find('.input-group-addon.danger').length == 0) {
            $form.find('[type="submit"]').prop('disabled', false);
        } else {
            $form.find('[type="submit"]').prop('disabled', true);
        }

    });
    $('.input-group input[required], .input-group textarea[required], .input-group select[required]').trigger('change');
    //Ini_Display_Cart();
    /* $(".nav .dropdown").hover(function() {
     $(".nav .dropdown").removeClass('open');
     $(this).addClass('open');
     
     
     
     });
     $(".nav .dropdown").mouseover(function() {
     $(".nav .dropdown").removeClass('open');
     });*/
//menu
//    $('li').has('ul').mouseover(function() {
//        $(this).children('ul').show().animate({opacity: 1});// .animate() .toggle();//.css({'visibility': 'visible','display':'block'});
//    }).mouseout(function() {
//        $(this).children('ul').hide();// .css({'display':'block','visibility': 'hidden'});
//    });

    $('#tiles').imagesLoaded(function() {
// Prepare layout options.
        var options = {
            itemWidth: '300', // Optional min width of a grid item
            autoResize: true, // This will auto-update the layout when the browser window is resized.
            container: $('#tiles'), // Optional, used for some extra CSS styling
            offset: 0, // Optional, the distance between grid items
            outerOffset: 0, // Optional the distance from grid to parent
            flexibleWidth: '25%' // Optional, the maximum width of a grid item
        };
        // Get a reference to your grid items.
        var handler = $('#tiles > div');
        var $window = $(window);
        $window.resize(function() {
            var windowWidth = $window.width(),
                    newOptions = {flexibleWidth: '25%'};
            // Breakpoint
            if (windowWidth < 1024) {
                newOptions.flexibleWidth = '25%';
            }

            handler.wookmark(newOptions);
        });
        // Call the layout function.
        handler.wookmark(options);
        //alert('x');
    });
    var g_id;
    //ajax loading
    function my_ajax_loading(text) {
        $("#ajax_loading label").stop().removeAttr('class').addClass('label label-primary').html("<span class='fa fa-refresh glyphicon-refresh-animate'></span>" + text);
        $("#ajax_loading").css({
            height: $('body').height()
        });
        $("#ajax_loading").show();
    }
    function my_ajax_success(text) {

        $("#ajax_loading label").stop().removeAttr('class').addClass('label label-success').html("<span class='fa fa-check '></span>" + text);
        $("#ajax_loading").css({
            height: $('body').height()
        });
        $("#ajax_loading").show().fadeOut();
    }
    function my_ajax_success(text) {

        $("#ajax_loading label").stop().removeAttr('class').addClass('label label-success').html("<span class='fa fa-check '></span>" + text);
        $("#ajax_loading").css({
            height: $('body').height()
        });
        $("#ajax_loading").show().fadeOut();
    }
    function my_ajax_error(text) {

        $("#ajax_loading label").stop().removeAttr('class').addClass('label label-warning').html("<span class='fa fa-exclamation-triangle '></span>" + text);
        $("#ajax_loading").css({
            height: $('body').height()
        });
        $("#ajax_loading").show().fadeOut();
    }
    function my_ajax_hide(text) {


        $("#ajax_loading").hide();
    }


//ajax loading 
    function add_to_cart(id, qty) {
        my_ajax_loading('Đang xử lý');
        $.ajax({
            type: "GET",
            url: global_url + 'index.php/yourcart/add',
            dataType: "Json",
            data: {
                id: id,
                qty: qty
            },
            success: function(data, status)
            {

                if (data.result == true)
                {
                    my_ajax_hide();
                    flyToElement($(g_img), $('#giohang'));
                }
                else {
                    my_ajax_error(data.error);
                    // alert(data.error) ;
                }
                //my_ajax_error(data.error);

            }, complete: function(data, s)
            {

            }, error: function(data, status)
            {
                my_ajax_error("Có lỗi xảy ra " + status);
            }
        });
    }
    var g_img;
    $(".detail_product .btn-add").click(function(e) {
        e.preventDefault();
        var id = $(this).attr("name");
        var qty = $('.detail_product .qty').val();
        g_img = $(this).parents('.detail_product').find("img:first");
        add_to_cart(id, qty);
    });
    $(".sanpham .btn-add, .sanphammoi .btn-add,.sanphamnoibat .btn-add").click(function(e) {
        e.preventDefault();
        var id = $(this).attr("name");
        var qty = 1;
        g_img = $(this).parents(".col-md-3");
  
        add_to_cart(id, qty);
    });
    $(".detail_cart tbody tr").hover(function() {
        g_id = this.id;
    });
    $(".detail_cart .btn-delete").click(function() {

        bootbox.dialog({
            message: "Bạn có chắc chắn muốn xóa hay không?",
            title: "Thông báo!",
            buttons: {
                success: {
                    label: "Có",
                    className: "btn-danger",
                    callback: function() {
                        my_ajax_loading('Đang xử lý...');
                        $.ajax({
                            type: 'GET',
                            url: global_url + 'index.php/yourcart/delete',
                            data: {
                                id: g_id
                            }, success: function(data, status) {

                                if (data.delete1)
                                {
                                    my_ajax_success("Xóa thành công");
//                                       ajaxLoading('Xóa thành công');

                                    $(".detail_cart table #" + g_id).delay(500).remove();
                                }
                                else
                                    alert(data.delete1);
                            }, error: function(data, status)
                            {
                                my_ajax_error("Lỗi " + status);
                            },
                            dataType: "json"

                        });
                    }
                },
                danger: {
                    label: "Không",
                    className: "btn-success",
                    callback: function() {
                        Example.show("uh oh, look out!");
                    }
                }

            }
        });
    });
    var g_new_qty = 1;
    $("td .qty").change(function() {
        g_new_qty = ($(this).val());
        alert(g_new_qty);
    });
    $('.spinner .btn:first-of-type').on('click', function() {
        var selector = $(this).parents(".spinner").find("input");
        $(selector).val(parseInt($(selector).val(), 10) + 1);
        //  $('.spinner input').val(parseInt($('.spinner input').val(), 10) + 1);
    });
    $('.spinner .btn:last-of-type').on('click', function() {
        // $('.spinner input').val(parseInt($('.spinner input').val(), 10) - 1);
        var selector = $(this).parents(".spinner").find("input");
        $(selector).val(parseInt($(selector).val(), 10) - 1);
    });
    $(".detail_cart .btn-update").click(function() {
        var qty = $("#" + g_id + " .qty").val();
        // console.log($("#" + g_id + " .qty").val());
//        var old_qty = $("#" + g_id + " .qty").val();
//         alert(old_qty);
        //alert("old"+old_qty+"new "+g_new_qty);
        my_ajax_loading("Đang xử lý...");
        $.ajax({
            type: 'GET',
            url: global_url + 'index.php/yourcart/update',
            dataType: "Json",
            data: {
                id: g_id,
                qty: qty
            },
            success: function(data, status) {
                if (data.result == true) {
                    my_ajax_success("Cập nhật thành công");
                    $("#" + g_id + " .qty").val(qty);
                    // $("#" + g_id + " .qty").text(g_new_qty);
                } else {

                    my_ajax_error(data.error);
                    //  console.log(("#"+ g_id +" td[data-th='Quantity']" ));

                    // $("#"+ g_id +" td[data-th='Quantity']" ).html("<input type='number' min='1' class='form-control text-center qty' value='"+2+"'>");
//                    alert(old_qty);
//                    $("#" + g_id + " .qty").val(2);
//                    alert(("#" + g_id + " .qty"));
                    // $("#" + g_id + " .qty").text(old_qty);
                    //  console.log( $("#" + g_id + " .qty"));
                    //$("#" + g_id + " .qty").attr("value",old_qty);
                    $("#" + g_id + " .qty").val(data.qty);
//                    
                }


            },
            error: function(status) {
                my_ajax_error("Có lỗi xảy ra");
                $("#" + g_id + " .qty").val(old_qty);
                $("#" + g_id + " .qty").text(old_qty);
            }
        });
    });
    /* mybox*/
    var demos = {};
    $(document).on("click", "a[data-bb]", function(e) {
        e.preventDefault();
        var type = $(this).data("bb");
        if (typeof demos[type] === 'function') {
            demos[type]();
        }
    });
    demos.alert = function() {
        bootbox.alert("Hello world!");
    };
    /*mybox*/

    function updateYourCart(id, qty, $selection) {
        $.ajax({
            type: 'GET',
            url: globalurl + 'index.php/yourcart/update',
            data: {
                id: g_id,
                qty: qty_yourcart2
            },
            success: function(data, status) {
                $selection.val(qty_yourcart2);
                qty_yourcart1 = qty_yourcart2;
                console.log(g_id + qty_yourcart1 + qty_yourcart2);
            },
            error: function(status) {
                alert(status);
                selection.val(qty_yourcart1);
            }
        });
    }
    $(document).on('click', '.login', function(e) {
        e.preventDefault();
        if ($("#loginDiv").html() == "")
        {
//               alert("xx");
            $.ajax({
                url: global_url + 'index.php/home/v_login',
                type: 'POST',
                success: function(data, status) {

                    $("#loginDiv").html(data);
                    $("#loginDiv").modal();
                },
                error: function(data, status) {

                }

            });
        }

        else
            $("#loginDiv").modal();
    });
    $(document).on('submit', '#signupform', function(e) {
        e.preventDefault();

        $.ajax({
            url: global_url + 'index.php/user/register',
            type: 'POST',
            dataType: "Json",
            data: {
                matk: $("input[name=matk]", this).val(),
                tenkh: $("input[name=tenkh]", this).val(),
                diachi: $("input[name=diachi]", this).val(),
                email: $("input[name=email]", this).val(),
                matkhau: $("input[name=matkhau]", this).val(),
                ngaysinh: $("input[name=ngaysinh]", this).val(),
                gioitinh: $("select[name=gioitinh]", this).val(),
                sodt: $("input[name=sodt]", this).val()
            },
            success: function(data, status) {
                if (data.result == true) {
                    $("#nav_user").html(data.html);
                    $("#registerDiv").modal('hide');
                    my_ajax_success("Đăng nhập thành công!");
                    if ($("body").attr("class").indexOf("yourcart") > -1) {
                        $(".btn-breadcrumb > a[href='#step-2'").addClass('disabled');
                        $(".btn-breadcrumb > a[href='#step-3'").removeClass('disabled');
                        $(".btn-breadcrumb > a[href='#step-3'").addClass('acitve');
                        $("#step-2").hide();
                        $("#step-3").show();
                    }
                }
                else
                    alert("Lỗi" + status);

            },
            error: function(data, status) {
                alert(status);
            }

        });
    });
    $(document).on('click', '.signin', function(e) {
        e.preventDefault();
        if ($("#registerDiv").html() == "")
            $.ajax({
                url: global_url + 'index.php/home/v_register',
                type: 'POST',
                success: function(data, status) {
                    $("#registerDiv").html(data);
                    $("#registerDiv").modal();
                },
                error: function(data, status) {

                }

            });
        else
            $("#registerDiv").modal();
    });
    function IniOrderWizard() {
//        $.each(".btn-breadcrumb > a",function (index,value){
//            alert(index);
//        });
        $(".btn-breadcrumb >a").each(function(index, value) {
            //  alert(index+$(value).html());
            var step = $(value).attr("href");
            var is_disable = $(value).attr("class");
            if ($(value).attr("class").indexOf("disabled") > -1)
            {
                $(step).hide();
            }

        });
    }
    IniOrderWizard();
    $(".btn-breadcrumb > a[href='#step-1']").click(function(e) {
        e.preventDefault();
        $("#thongtinhd").hide();
        if ($(this).attr("class").indexOf("active") < 0) {
            $(".btn-breadcrumb > a").each(function(index, item) {
                $(this).removeClass('active');
                var a = $(this).attr("href");
                $(a).hide();
            });
            $(this).addClass("active");
            $($(this).attr("href")).show();
        }
        // if($(".btn-breadcrumb > a[href='#step-2']").attr("class").indexOf("disabled")) 
    });
    $(".btn-breadcrumb > a[href='#step-2']").click(function(e) {
        e.preventDefault();
        $("#thongtinhd:hidden").show();
        if ($(this).attr("class").indexOf("active") < 0) {
            $(".btn-breadcrumb > a").each(function(index, item) {
                $(this).removeClass('active');
                var a = $(this).attr("href");
                $(a).hide();
            });
            $(this).addClass("active");
            $($(this).attr("href")).show();
        }
        // if($(".btn-breadcrumb > a[href='#step-2']").attr("class").indexOf("disabled")) 
    });
    $(".btn-breadcrumb > a[href='#step-3']").click(function(e) {
        e.preventDefault();
        $("#thongtinhd:hidden").show();
        if ($(this).attr("class").indexOf("active") < 0) {
            $(".btn-breadcrumb > a").each(function(index, item) {
                $(this).removeClass('active');
                var a = $(this).attr("href");
                $(a).hide();
            });
            $(this).addClass("active");
            $($(this).attr("href")).show();
        }
        // if($(".btn-breadcrumb > a[href='#step-2']").attr("class").indexOf("disabled")) 
    });
//$(".btn-breadcrumb > a").click(function (e){
//   e.preventDefault();
//   //alert($(this).attr("href"));
//   var step=$(this).attr("href");
//   if($(this).attr("class").indexOf("active")<0  )//nếu chưa phải là hiện tại
//       {
//           $(".btn-breadcrumb > a").removeClass('active');
//           $(step).show();           
//       }
//   
//});
    $(".next-step-1").click(function(e) {
        e.preventDefault();
        $("#thongtinhd:hidden").show();
        $(".btn-breadcrumb > a[href='#step-1']").removeClass('active');
        $("#step-1").hide();
        if ($(".btn-breadcrumb > a[href='#step-2']").attr("class").indexOf("disabled") > -1)
        {
            $(".btn-breadcrumb > a[href='#step-3']").removeClass("disabled");
            $("#step-3").show();
        }
        else {
            $("#step-2").show();
        }
        /// else {$("#step-2").removeClass('disabled');
        //}
    });
    $(document).on('submit', '#loginform', function(e) {
        my_ajax_loading("Đang xử lý...");
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: global_url + "index.php/user/index",
            dataType: 'Json',
            data: {
                username_login: $("#login-username").val(),
                pass_login: $('#login-password').val()
            },
            success: function(data, status) {

                if (data.result == true) {
                    $("#nav_user").html(data.html);
                    $("#loginDiv").modal('hide');
                    my_ajax_success("Đăng nhập thành công!");
                    if ($("body").attr("class").indexOf("yourcart") > -1) {
                        $(".btn-breadcrumb > a[href='#step-2'").addClass('disabled');
                        $(".btn-breadcrumb > a[href='#step-3'").removeClass('disabled');
                        $(".btn-breadcrumb > a[href='#step-3'").addClass('acitve');
                        $("#step-2").hide();
                        $("#step-3").show();
                    }
                }
                else {
                    my_ajax_error("Đăng nhập thất bại!");
                    //alert("Đăng nhập thất bại! Vui lòng kiểm tra lại thông tin!");
                }
            }, error: function(data, status) {
                alert("Lỗi: " + status);
            }
        });
    });
    $("input[name=laytt]", "#thanhtoanform").click(function() {
        if (this.checked) {
            $.ajax({
                type: 'POST',
                url: global_url + "index.php/user/laytt",
                dataType: 'Json',
                data: {
                },
                success: function(data, status) {

                    $("input[name=hoten]", "#thanhtoanform").val(data.tenkh);
                    $("input[name=diachi]", "#thanhtoanform").val(data.diachi);
                    $("input[name=sodt]", "#thanhtoanform").val(data.sodt);
                }, error: function(data, status) {
                    alert("Lỗi: " + status);
                }
            });
        }

    });
    //$("input[name=hinhthuctt]:checked", this).val();thanhtoanform
    function loadthongtintk() {
        $.ajax({
            type: 'POST',
            url: global_url + "index.php/user/index",
            dataType: 'Json',
            data: {
                username_login: $("#login-username").val(),
                pass_login: $('#login-password').val()
            },
            success: function(data, status) {

                if (data.result == true) {
                    $("#nav_user").html(data.html);
                    $("#login_register").modal('hide');
                    my_ajax_success("Đăng nhập thành công!");
                    if ($("body").attr("class").indexOf("yourcart") > -1) {
                        $("#step-1").hide();
                    }
                }
                else {
                    my_ajax_error("Đăng nhập thất bại!");
                    //alert("Đăng nhập thất bại! Vui lòng kiểm tra lại thông tin!");
                }
            }, error: function(data, status) {
                alert("Lỗi: " + status);
            }
        });
    }
    $(document).on('submit', '#thanhtoanform', function(e) {
        var hinhthuctt = $("input[name=hinhthuctt]:checked", this).val();
//        alert(hinhthuctt);
//        if (hinhthuctt == 1)
//            alert('a');
        my_ajax_loading("Đang xử lý...");
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: global_url + "index.php/yourcart/thanhtoan",
            dataType: 'Json',
            data: {
                diachi: $("input[name=diachi]", this).val(),
                tennn: $('input[name=hoten]', this).val(),
                sodt: $('input[name=sodt]', this).val(),
                hinhthuctt: hinhthuctt
            },
            success: function(data, status) {
                alert(data);
                console.log(data);
                if (data.result == true)
                {
                    my_ajax_success("Đặt hàng thành công!");
//                    var msg = confirm("Bạn có muốn in hóa đơn này không?");
//                    if (msg == true) {
//
//                        window.location = data.link;
//                    }
                   // if (hinhthuctt == 2)
                        window.location = data.link;
                }
                else {
                    alert(data.error);
                    my_ajax_error(data.error);
                }

            }, error: function(data, status) {
                alert("Lỗi: " + status);
            }
        });
    });
    $(document).on('click', '#btn-logout', function(e) {
        if (confirm("Bạn có chắc chắn muốn thoát hay không?"))
        {
            $.ajax({
                type: 'POST',
                url: global_url + "index.php/user/logout",
                dataType: 'Json',
                success: function(data, status) {
                    if (data.result == true)
                    {
                        location.reload();
//                    $("#nav_user").html(data.html);
//                    $("#login_register").modal('hide');
                    }

                }, error: function(data, status) {
                    alert("error:" + status);
                }
            });
        }

    });
});
$(document).on('click', '.number-spinner button', function(e) {
    e.preventDefault();
    var btn = $(this),
            oldValue = btn.closest('.number-spinner').find('input').val().trim(),
            newVal = 0;
    if (btn.attr('data-dir') == 'up') {
        newVal = parseInt(oldValue) + 1;
    } else {
        if (oldValue > 1) {
            newVal = parseInt(oldValue) - 1;
        } else {
            newVal = 1;
        }
    }
    console.log(newVal);
    btn.closest('.number-spinner').find('input').val(newVal);
});
var Example = (function() {
    "use strict";
    var elem,
            hideHandler,
            that = {};
    that.init = function(options) {
        elem = $(options.selector);
    };
    that.show = function(text) {
        clearTimeout(hideHandler);
        elem.find("span").html(text);
        elem.delay(200).fadeIn().delay(4000).fadeOut();
    };
    return that;
}());
$(function() {
    Example.init({
        "selector": ".bb-alert"
    });
});
//$('.carousel').carousel({
//    interval: 3000
//});

