﻿jQuery(document).ready(function () {

    function FormatNumber(number) {
        number += '';
        x = number.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ' ' + '$2');
        }
        return x1 + x2;
    }

    jQuery("#" + DropDownFilter_Data[0].countyClientID).change(function () {
        jQuery.ajax({
            type: "POST",
            url: DropDownFilter_Data[0].webServiceUrl,
            data: "{countyId: " + jQuery("#" + DropDownFilter_Data[0].countyClientID).val() + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                jQuery("#" + DropDownFilter_Data[0].municipalityClientID).find("option").remove();
                for (var i = 0; i < response.length; i++) {
                    jQuery("#" + DropDownFilter_Data[0].municipalityClientID).append('<option value="' + response[i].Id + '">' + response[i].Name + '</option>');
                }
            }
        });
    });

    // Reset the dropdowns
    if ($("#" + DropDownFilter_Data[0].countyClientID).val() != -1)
        $("#" + DropDownFilter_Data[0].countyClientID).val(-1);

    if ($("#" + DropDownFilter_Data[0].municipalityClientID).val() != -1)
        $("#" + DropDownFilter_Data[0].municipalityClientID).val(-1);

    
    // Prepare for slideshow
    $('#ObjectSpinner div.ListItem').show();
    $('#ObjectSpinner div.ListItem').equalHeight();
    $('#ObjectSpinner div.ListItem').hide();
    $('#ObjectSpinner .show').fadeIn();
    setTimeout(slideShow, 5000);

    function slideShow() {
        var current = $('#ObjectSpinner .show');
        var next = current.next().length ? current.next() : current.parent().children(':first');

        //current.hide().removeClass('show');
        //next.fadeIn('slow').addClass('show');

        current.fadeOut('fast', function () {
            next.fadeIn('slow').addClass('show');
        }).removeClass('show');

        setTimeout(slideShow, 5000);
    }

    //slideShow();


});
