﻿jQuery(function ($) {

    $('.gallery').addClass('gallery_EH'); // adds new class name to maintain degradability

    $('ul.gallery_EH').galleria({
        history: false, // deactivates the history object for bookmarking, back-button etc.
        clickNext: true, // helper for making the image clickable.
        insert: undefined, // the containing selector for our main image. If not found or undefined (like here), galleria will create a container before the ul with the class .galleria_container (see CSS)
        onImage: function () { },
        onThumb: function () { }
    });
});

// switch all tabs off
$(document).ready(function () {

    if ($("#tabNr").val() != "1") {
        var nr = '#tabbedContent_' + $("#tabNr").val();
        // switch all tabs off
        $(".tabActive").removeClass("tabActive");

        // switch this tab on
        $(nr).addClass("tabActive");

        // slide all elements with the class 'content' up
        $(".tabContent").hide();
        $(nr).slideDown();
    }
});

//
// this initializes the slider.
// the slider gets its initial values from two textboxes txtMin and txtMax.
// when it slides, it sets the values in the txtBoxes.
//
var formatNumber = function (number) {
    number += "";
    var parts = number.split('.');
    var integer = parts[0];
    var decimal = parts.length > 1 ? '.' + parts[1] : '';
    var regex = /(\d+)(\d{3})/;
    while (regex.test(integer)) {
        integer = integer.replace(regex, '$1' + '.' + '$2');
    }
    return integer + decimal;
};

$(document).ready(function () {
    var maximum = $("#absMax").val();
    maximum = parseInt(maximum);

    $("#slider").slider({
        range: true,
        min: 0,
        max: maximum,
        values: [$("#txtMin").val(), $("#txtMax").val()],
        step: 25000,
        slide: function (event, ui) {
            $("#txtMin").val('€' + formatNumber(ui.values[0]))
            $("#txtMax").val('€' + formatNumber(ui.values[1]));
        }
    });
    $("#txtMin").val('€' + formatNumber($("#txtMin").val())) + ' -' + $("#txtMax").val('€' + formatNumber($("#txtMax").val()));

    var maximumWO = $("#absMaxWO").val();
    maximumWO = parseInt(maximumWO);

    $("#slider2").slider({
        range: true,
        min: 0,
        max: maximumWO,
        values: [$("#txtMinWO").val(), $("#txtMaxWO").val()],
        step: 20,
        slide: function (event, ui) {
            $("#txtMinWO").val(ui.values[0] + 'm²')
            $("#txtMaxWO").val(ui.values[1] + 'm²');
        }
    });

    $("#txtMinWO").val($("#slider2").slider("values", 0) + 'm²') + ' -' + $("#txtMaxWO").val($("#slider2").slider("values", 1) + 'm²');

    var maximumAK = $("#absMaxAK").val();
    maximumAK = parseInt(maximumAK);

    $("#slider3").slider({
        range: true,
        min: 0,
        max: maximumAK,
        values: [$("#txtMinAK").val(), $("#txtMaxAK").val()],
        step: 1,
        slide: function (event, ui) {
            $("#txtMinAK").val(ui.values[0])
            $("#txtMaxAK").val(ui.values[1]);
        }
    });
}); 
