if (typeof console === 'undefined') { console = { log: function() {}, warn: function() {}, error: function() {}, info: function() {} }; }
$('html').addClass('has_js');

var front = {

    init: function() {
        this.simpletabs();
        this.scrollable();
        this.specs_data();
        this.colorbox();
        this.submitForms();
        this.productComparison();
    },

    simpletabs: function() {

        $('#product_tech_info').simpletabs();

    },

    scrollable: function() {

        $(".js_slide_items").css({ 'height' : '450', 'position' : 'relative', 'overflow' : 'hidden' });
        //$(".js_slide_item").css({ 'position' : 'absolute' });
        $(".js_slide_item").css({ 'float' : 'left' });

        $('.js_slide_item').each(function(i, val) {
            $(this).addClass('js_slide_item_'+i);
        });

        $(".js_slide_thumbs a").click(function(e) {
    		if ($(this).hasClass('active')) { return false; }
            $('.js_slide_thumbs .active').removeClass('active');

            var url = $(this).find('img').attr('src').replace('listing_s', 'view_m');
    		$(this).addClass('active');
            $('.js_slide_item img').attr('src', url)
            e.preventDefault();
    	});

    },

    specs_data: function() {

    	$('.js_data span.has_info').click(function(e){
	    	var parent_el = $(this).closest('.js_specs_data_container');
	    	if ($(this).parent().hasClass('active')) { return false; }
	    	parent_el.find('li.active').removeClass('active').find('.js_data_info').hide(200);
	    	$(this).parent().toggleClass('active').find('.js_data_info').show(200);
    		e.preventDefault();
    	});

	},

    colorbox: function() {

    	$("a[rel='gallery']").colorbox({
    		current   : 'slika {current} od {total}',
    		close     : 'zatvori',
    		previous  : 'prethodna',
    		next      : 'sljedeća'
    	});

	},

    submitForms: function() {

        $('form#form_product_list').submit(function() {
            $(this).serialize();
        });

    },

    productComparison: function() {

        var check_status = function($checkbox) {
            var checkbox_nr = $('.js_group_parent').find('input:checked').length;

            if (checkbox_nr === 0) {
                $('.js_compare_submit').attr('disabled', 'disabled');
                notification($checkbox);
                $('.js_group_parent').find('.js_check').removeAttr('disabled');
            }
            else if ((checkbox_nr >= 1) && (checkbox_nr <= 2)) {
                $('.js_compare_submit').removeAttr('disabled');
                notification($checkbox);
                $('.js_group_parent').find('.js_check').removeAttr('disabled');
            }
            else if (checkbox_nr === 3) {
                $('.js_compare_submit').removeAttr('disabled');
                notification($checkbox);
                $('.js_group_parent').find('.js_check:not(:checked)').attr('disabled', 'disabled');
            }
        };

        var notification = function($checkbox) {
            if ($checkbox.is(':checked')) {
                $checkbox.closest('.js_group_parent').addClass('active');
            } else {
                $checkbox.closest('.js_group_parent').removeClass('active');
            }
        };

        $('input[type=checkbox].js_check').each(function(){
            var self = $(this);
            check_status(self);

        });

        $('input[type=checkbox].js_check').click(function(){
            var self = $(this);
            check_status(self);
        });

    }

};

$(document).ready(function() {
    front.init();
});
