
    var paymentBlockElements = ['placeholder', 'cc', 'sofortueberweisungredirect', 'moneyorder' , 'paypal'];


String.prototype.reverseHTMLEntities = function () {
    strText = this;
    strText = strText.replace( new RegExp('&uuml;', "g"), 'ü');
    strText = strText.replace( new RegExp('&ouml;', "g"), 'ö');
    strText = strText.replace( new RegExp('&auml;', "g"), 'ä');
    strText = strText.replace( new RegExp('&Uuml;', "g"), 'Ü');
    strText = strText.replace( new RegExp('&Ouml;', "g"), 'Ö');
    strText = strText.replace( new RegExp('&Auml;', "g"), 'Ä');
    strText = strText.replace( new RegExp('&szlih;', "g"), 'ß');
    return strText;
}

$(
    function ()
    {
        // hide payment blocks
        $(".paymentblock td[class^='paymentblock_content-']").hide();

        // animate payment blocks
        $(this).find("input:radio[name='payment']").click(
            function()
            {
                animatePaymentBlocks();
            }
        );
            
        animatePaymentBlocks();


        // language choose on top
        var initialValue = $('#languages select option:selected').val();

        $('#languages select option').click(
            function () {
                var newSearch;
                var oldSearch = window.location.search;
                var newDestination = $(this).parent().find(':selected').val();

                if (newDestination == initialValue) {
                    return;
                }

                if (oldSearch.length > 0) {
                    if (-1 != oldSearch.indexOf('language=')) {
                        newSearch = oldSearch.replace(/language=\w\w?/i,"language=" + newDestination);
                    }
                    else {
                        newSearch = oldSearch + '&language=' + newDestination;
                    }
                    
                }
                else {
                    newSearch = '?language=' + newDestination;
                }

                newSearch = newSearch.replace("??", "?");

                window.location.search = newSearch;
                var sanitizedHref = window.location.href.replace(window.location.search, "");
                window.location = sanitizedHref + newSearch;
            }
        );

        $('#languages select').change(
            function () {
                $('option', this).trigger('click');
            }
        );


        // Content Handler
        var contentPageHandler = new ContentPage();

    }
);

    function animatePaymentBlocks ()
    {
        var currentValue = $("input:radio:checked[name='payment']").val();
        var currentId = getPaymentBlockId( currentValue );

        for (var i = 1; i < paymentBlockElements.length; i++)
        {
            if (i == currentId)
            {
                $('.paymentblock .paymentblock_content-'+i).fadeIn();
            }
            else
            {
                $('.paymentblock .paymentblock_content-'+i).fadeOut();
            }
        }
    }


    function getPaymentBlockId ( textContent )
    {
        for (var i = 1; i < paymentBlockElements.length; i++)
        {
            if (paymentBlockElements[i] == textContent)
            {
                return i;
            }
        }
        
        return 0;
    }


    function ContentPage () {
        this.contentID;
        this.pageIdentifierID = "page-identifier-content";
        this.$pageIdentifier = $("#" + this.pageIdentifierID);
        
        this.init();
    }

    ContentPage.prototype.init = function () {
        
        if (1 > this.$pageIdentifier.length) {
            return false;
        }
        else {
            try {
                this.contentID = parseInt( this.$pageIdentifier.attr("rel") );
                return this.handleContentPage();
            }
            catch (e) {
                return false;
            }
            
        }
    }


    ContentPage.prototype.handleContentPage = function () {

        if (1 > this.$pageIdentifier.length) {
            return false;
        }
        
        switch (this.contentID)
        {
            case 9:
                return this.handleSizePage();
                break;

            default:
                return false;
                break;
        }
    }


    ContentPage.prototype.handleSizePage = function () {
        if ((typeof(currentGender) != "undefined") && ("men" == currentGender)) {
            
            $("html").scrollTop(Math.round($('#size-chart-men').offset().top));
        }
    }