(function($) {
    var W = this.window;
    
    $(document).ready(function () {
        
        /**
        * @section      catalogForm
        */ 
        if ($("#catalogForm").length) {
            
            /**
            * @description  Check and uncheck the appropriate checkbox when clicking on the catalog images 
            */ 
            $("#catalogForm .checkboxes li img").click(function(){
                var inputCheckbox = $(this).nextAll("input");
                inputCheckbox.click();
                if (inputCheckbox.is(':checked')) {
                    inputCheckbox.attr('checked', false);
                } else {
                    inputCheckbox.attr('checked', true);
                }
            });
            
            /**
            * @description  Check the appropriate catalog checkbox according to the possible parameter 'catalog'
            */
            var url = W.location.href;
            if (url.indexOf("?") > 0) {
                var urlArgs = url.split('?')[1];
                if (url.indexOf("&") > 0) {
                    urlArgs = urlArgs.split('&');
                }
                var catalogChecked = "";
                for (var i=0; i<urlArgs.length; i++){ 
                    if (urlArgs[i].split('=')[0] == 'catalog') {
                        catalogChecked = urlArgs[i].split('=')[1];
                    }
                }
                if (catalogChecked != "") {
                    var inputCheckbox = $("#" + catalogChecked);
                    inputCheckbox.click();
                    if (inputCheckbox.is(':checked')) {
                        inputCheckbox.attr('checked', false);
                    } else {
                        inputCheckbox.attr('checked', true);
                    }
                }
            }
            /**
            * @description  Specifies witdh to center the catalog choice
            * @todo         Use innerWidth
            */        
            var ulWidth = $("#catalogForm .checkboxes ul").children().size()
                        * (
                            parseInt($("#catalogForm .checkboxes ul li:first").width()) 
                          + parseInt($("#catalogForm .checkboxes ul li:first").css("paddingLeft").replace("px",""))
                          + parseInt($("#catalogForm .checkboxes ul li:first").css("paddingRight").replace("px",""))
                      );
            $("#catalogForm .checkboxes ul").width(ulWidth);
        };
        
        /**
        * @description Validates catalog form
        *
        */
        
        
        
    });
        
})(jQuery);
