
// Owl slider
$(document).ready(function(){


$('.oe_website_sale').each(function () {
    var oe_website_sale = this;


$(oe_website_sale).on("change", ".oe_cart input.js_quantity", function () {
		setTimeout("location.reload();", 1000);
});

$(oe_website_sale).on('click', 'a.js_add_cart_json_new', function (ev) {
        ev.preventDefault();
        var $link = $(ev.currentTarget);
        var $input = $link.parent().parent().find("input");        
        var value = parseInt(0, 10);
        var line_id = parseInt($input.data('line-id'),10);
        if (isNaN(value)) value = 0;
        openerp.jsonRpc("/shop/cart/update_json", 'call', {
            'line_id': line_id,
            'product_id': parseInt($input.data('product-id'),10),
            'set_qty': value})
	.then(function (data) {
                if (!data.quantity) {
                    location.reload();
                    return;
                }
	});
    });
});



  $('.owl-carousel').owlCarousel({
    loop:true,
    margin:30,
    responsiveClass:true,
    responsive:{
        0:{
            items:1,
            nav:false,
            dots:true
        },
        480:{
            items:2,
            nav:false,
            dots:true
        },
        768:{
            items:3,
            nav:false,
            dots:true
        },
        1000:{
            items:4,
            nav:true,
            loop:false,
            dots:false
        }
    }
})
// Mobile menu 
  $(".menu-toggle").click(function () {
         $('body').toggleClass( "menu-show" );
      });


// Cat
  $('.sub-cat-1').click(
    function(e) {
        e.preventDefault(); // prevent the default action
        e.stopPropagation(); // stop the click from bubbling
        $(this).parent().toggleClass('selected');
});


  $('.sub-cat-2').click(
    function(e) {
        e.preventDefault(); // prevent the default action
        e.stopPropagation(); // stop the click from bubbling
        $(this).parent().toggleClass('selected');
});

  $('.sub-cat-3').click(
    function(e) {
        e.preventDefault(); // prevent the default action
        e.stopPropagation(); // stop the click from bubbling
        $(this).parent().toggleClass('selected');
});

$('#products_grid_before .nav li.active').parent().parent().addClass('selected');
$('#products_grid_before .nav li.active').parent().parent().parent().parent().addClass('selected');
$('#products_grid_before .nav li.active').parent().parent().parent().parent().parent().addClass('selected');
$('#products_grid_before .nav li.active').parent().parent().parent().parent().parent().parent().addClass('selected');
$('#products_grid_before .nav li.active').parent().parent().parent().parent().parent().parent().parent().addClass('selected');
$('#products_grid_before .nav li.active').parent().parent().parent().parent().parent().parent().parent().parent().addClass('selected');
$('#products_grid_before .nav li.active').parent().parent().parent().parent().parent().parent().parent().parent().parent().addClass('selected');
$('#products_grid_before .nav li.active').parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().addClass('selected');

});

// header fix
$(window).scroll(function(){
    if ($(window).scrollTop() >= 110) {
       $('.nav-top').addClass('navbar-fixed-top');
    }
    else {
       $('.nav-top').removeClass('navbar-fixed-top');
    }
});


/*function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

$(document).ready(function() {
	equalHeight($(".product .title"));
	equalHeight($(".product-img"));
});

$(window).resize(function() {
    equalHeight($(".product .title"));
    equalHeight($(".product-img"));
});*/


$(document).ready(function() {
var images = Array();

jQuery(".product-img").each(function (index,ele) {
           images.push(ele.children[0].src);
        });
    

    jQuery.imgpreload(images,function()
            {
 function resetHeight() {
        var maxHeight = 0;
        jQuery(".product .title").height("auto").each(function () {
            maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
        }).height(maxHeight);
    }
    /*resetHeight();*/
   /* jQuery(window).resize(function () {
        resetHeight();
    });*/

    function resetHeight1() {
        var maxHeight = 0;
        jQuery(".product-img").height("auto").each(function () {
            maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
        }).height(maxHeight);
    }
    resetHeight1();
    jQuery(window).resize(function () {
          resetHeight();
        resetHeight1();
    });

    resetHeight();
        resetHeight1();

    });
    });


/*Added By BC 03-07-2015*/

$(document).ready(function() {
    $("<span class='mob_sub'><span data-icon-name='plus'></span></span>").insertBefore(".mega-menu");
    $("<span class='mob_sub'><span data-icon-name='plus'></span></span>").insertBefore(".navbar-nav ul.mega-menu > .column > .js_usermenu");
    $("<span class='mob_sub'><span data-icon-name='plus'></span></span>").insertBefore(".navbar-nav ul.mega-menu > .column ul > li > ul");

	/*spanelm=document.createElement('span');
	var att1 = document.createAttribute("class");
	att1.value='mob_sub';
	var att2 = document.createAttribute("data-icon-name");
	att2.value='plus';
	spanic=document.createElement('span');
	spanelm.setAttributeNode(att1);
	spanic.setAttributeNode(att2);
	spanelm.appendChild(spanic);
	$('.mega-menu').insertBefore(spanelm);*/
    $('.mob_sub').click(
        function(e) {
            e.preventDefault(); // prevent the default action
            e.stopPropagation(); // stop the click from bubbling
            $(this).parent().toggleClass('selected');
            $(this).toggleClass('mob_sub_open');
        });

});







/**
* jquery.imgpreload 1.6.2 <https://github.com/farinspace/jquery.imgpreload>
* Copyright 2009-2014 Dimas Begunoff <http://farinspace.com>
* License MIT <http://opensource.org/licenses/MIT>
*/
if ('undefined' != typeof jQuery)
{
    (function($){
        'use strict';

        // extend jquery (because i love jQuery)
        $.imgpreload = function (imgs,settings)
        {
            settings = $.extend({},$.fn.imgpreload.defaults,(settings instanceof Function)?{all:settings}:settings);

            // use of typeof required
            // https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Operators/Special_Operators/Instanceof_Operator#Description
            if ('string' == typeof imgs) { imgs = [imgs]; }

            var loaded = [];

            $.each(imgs,function(i,elem)
            {
                var img = new Image();

                var url = elem;

                var img_obj = img;

                if ('string' != typeof elem)
                {
                    url = $(elem).attr('src') || $(elem).css('background-image').replace(/^url\((?:"|')?(.*)(?:'|")?\)$/mg, "$1");

                    img_obj = elem;
                }

                $(img).bind('load error', function(e)
                {
                    loaded.push(img_obj);

                    $.data(img_obj, 'loaded', ('error'==e.type)?false:true);

                    // http://msdn.microsoft.com/en-us/library/ie/tkcsy6fe(v=vs.94).aspx
                    if (settings.each instanceof Function) { settings.each.call(img_obj, loaded.slice(0)); }

                    // http://jsperf.com/length-in-a-variable
                    if (loaded.length>=imgs.length && settings.all instanceof Function) { settings.all.call(loaded); }

                    $(this).unbind('load error');
                });

                img.src = url;
            });
        };

        $.fn.imgpreload = function(settings)
        {
            $.imgpreload(this,settings);

            return this;
        };

        $.fn.imgpreload.defaults =
        {
            each: null, // callback invoked when each image is loaded
            all: null // callback invoked when all images have loaded
        };

    })(jQuery);
}
