/**
#---------------------------------------------------------------------------
# Copyright   : rexx systems GmbH, 20097 Hamburg, Heidenkampsweg 101
#               Veraenderung oder Nutzung der Scripte/Anwendung ist nur mit
#               schriftlicher Genehmigung der rexx systems GmbH gestattet.
#---------------------------------------------------------------------------
*/

var shopCategories = (
    function() {

        function bindFoo(o,f) {
            return function () {
                return f.apply(o,Array.prototype.slice.call(arguments));
            };
        };

        return {
            countChangeFunction: "get_changed_count_data",
            sortChangeFunction:  "get_changed_sort_price",

            /*
             * Intialisierung von Event-Handlern, etc.
             */
            init: function (options) {
                options = options || {};
                if (options.countFunction) {
                    this.countChangeFunction = options.countFunction;
                }
                if (options.sortFunction) {
                    this.sortChangeFunction = options.sortFunction;
                }

                $('.categorySelect').change(bindFoo(this, this.changeArticleCount));
                $('.priceSelect').change(bindFoo(this, this.changeSortPrice));
                $('#tagSelect').change(bindFoo(this, this.changeTag));
                $('.pagesSelect').css('display','block');
                $('#pagesSelect').css('display','inline');
                $('.priceSort').css('display','block');
                $('#priceSort').css('display','inline');
            },

            // Initialisierung des Box-Inhaltes.
            initBoxContent: function(html) {
                if (html !== null) {
                    $("#category_articles_box").html(html);
                    $('.categorySelect').change(bindFoo(this, this.changeArticleCount));
                    $('.priceSelect').change(bindFoo(this, this.changeSortPrice));
                    $('#tagSelect').change(bindFoo(this, this.changeTag));
                    $('.pagesSelect,.priceSort').css('display','block');
                    $('#pagesSelect,#priceSort').css('display','inline');
                }
            },

            changeArticleCount: function() {

                var articleCount = $('.categorySelect').val();

                $("#category_articles_box").html('<div class="box-head-text">&nbsp;</div><img src="../images/loading.gif" alt="Laden..."/> Daten werden geladen...');

                $.ajax({
                        type: "GET",
                        url: "../inc/functions/xml_http_requests.php",
                        data: {
                            f : this.countChangeFunction,
                            p0: articleCount,
                            sid: mySession
                        },

                        success: bindFoo(this, this.initBoxContent)
                       });
            },


            changeSortPrice: function() {
                var sortPrice = $('.priceSelect').val();

                $("#category_articles_box").html('<div class="box-head-text">&nbsp;</div><img src="../images/loading.gif" alt="Laden..."/> Daten werden geladen...');

                $.ajax({
                        type: "GET",
                        url: "../inc/functions/xml_http_requests.php",
                        data: {
                            f : this.sortChangeFunction,
                            p0: sortPrice,
                            sid: mySession
                        },

                        success: bindFoo(this, this.initBoxContent)
                       });
            },

            changeTag: function() {
                var url = $('#tagSelect').val();
                document.location = document.location.protocol + '//' + document.location.host + '/' + url;
            }

        };
    }()
);
