﻿/* INIT */
window.$bf = {};

$bf.Selection = {};
$bf.Selection.CityIds = [];
$bf.Selection.ProvinceIds = [];
$bf.Selection.PropertyTypeIds = [];
$bf.Selection.MinPrice = 0;
$bf.Selection.MaxPrice = 0;
$bf.Selection.ProjectName = '';
$bf.Selection.PageIndex = 0;
$bf.Selection.PageSize = 5;
$bf.Selection.SortField = '1A';
$bf.Selection.QueryString = '';
$bf.Scrolling = false;
$bf.SetZoom = false;
$bf.Map = null;
$bf.InfoWindow = null;

/* METHODS */
$bf.PostJson = function (url, data, callback) {
    jQuery.ajax({
        type: "POST",
        url: url,
        data: data,
        dataType: 'json',
        traditional: true,
        success: callback,
        error: function (xhr, status, error) {
            alert(error);
        }
    });
};

$bf.GetJson = function (url, data, callback) {
    jQuery.ajax({
        type: "GET",
        url: url,
        data: data,
        dataType: 'json',
        success: callback,
        error: function (xhr, status, error) {
            alert(error + ' ' + url);
        }
    });
};

$bf.InitFilters = function () {
    var citySelect = jQuery('#citySelect');
    citySelect.delegate('div.selectbox > span', 'click', $bf.CityClick);
    $bf.AttachScrollHandlers(citySelect, citySelect.find('div.selectbox'));

    var provinceSelect = jQuery('#provinceSelect');
    provinceSelect.delegate('div.selectbox > span', 'click', $bf.ProvinceClick);
    $bf.AttachScrollHandlers(provinceSelect, provinceSelect.find('div.selectbox'));

    var propertyTypeSelect = jQuery('#propertyTypeSelect');
    propertyTypeSelect.delegate('div.selectbox > span', 'click', $bf.PropertyTypeClick);
    $bf.AttachScrollHandlers(propertyTypeSelect, propertyTypeSelect.find('div.selectbox'));

    var minPriceSelect = jQuery('#minPriceSelect');
    minPriceSelect.delegate('div.selectbox > span', 'click', $bf.MinPriceClick);
    $bf.AttachScrollHandlers(minPriceSelect, minPriceSelect.find('div.selectbox'));

    var maxPriceSelect = jQuery('#maxPriceSelect');
    maxPriceSelect.delegate('div.selectbox > span', 'click', $bf.MaxPriceClick);
    $bf.AttachScrollHandlers(maxPriceSelect, maxPriceSelect.find('div.selectbox'));

    jQuery('input.search').autocomplete({
        source: function (request, response) {
            jQuery.ajax({
                url: '/Services/ProjectService.svc/ProjectNames',
                dataType: "json",
                data: {
                    currentNodeId: $bf.CurrentNodeId,
                    partialMatch: request.term
                },
                success: response
            });
        },
        minLength: 2,
        select: function (event, ui) {
            if (ui.item) {
                jQuery('#projectName').val(ui.item.label);
                $bf.SetProjectName(ui.item.label);
            }
        }
    });
};

$bf.FillList = function (listId, items) {
    var listItems = [];
    jQuery(items).each(function (index, value) {
        listItems.push('<span data="' + value.Id + '"' + (value.IsSelected ? ' class="selected"' : '') + '>' + value.Name + '</span>');
    });
    jQuery('#' + listId).find('div.selectbox').html(listItems.join(''));
};

$bf.CityClick = function (event) {
    var $span = jQuery(this);
    var id = $span.attr('data');

    if (id == 0) {
        $bf.Selection.CityIds.length = 0;
        jQuery('#citySelect div.selectbox > span').removeClass('selected');
        $span.addClass('selected');
    } else {
        $bf.ToggleInSet($bf.Selection.CityIds, id);
        $span.toggleClass('selected');
        var $zero = $span.parent().find('span[data="0"]');
        $zero.removeClass('selected');
        if ($bf.Selection.CityIds.length <= 0) $zero.addClass('selected');
    }

    $bf.GetJson('/Services/ProjectService.svc/Filters', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.FillList('provinceSelect', json.Provinces);
        $bf.FillList('propertyTypeSelect', json.PropertyTypes);
        jQuery('#propertyCount').html(json.PropertyCount);
        $bf.Selection.QueryString = json.QueryString;
    });
};

$bf.ProvinceClick = function (event) {
    var $span = jQuery(this);
    var id = $span.attr('data');

    if (id == 0) {
        $bf.Selection.ProvinceIds.length = 0;
        jQuery('#provinceSelect div.selectbox > span').removeClass('selected');
        $span.addClass('selected');
    } else {
        $bf.ToggleInSet($bf.Selection.ProvinceIds, id);
        $span.toggleClass('selected');
        var $zero = $span.parent().find('span[data="0"]');
        $zero.removeClass('selected');
        if ($bf.Selection.ProvinceIds.length <= 0) $zero.addClass('selected');
    }

    $bf.GetJson('/Services/ProjectService.svc/Filters', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.FillList('citySelect', json.Cities);
        $bf.FillList('propertyTypeSelect', json.PropertyTypes);
        jQuery('#propertyCount').html(json.PropertyCount);
        $bf.Selection.QueryString = json.QueryString;
    });
};

$bf.PropertyTypeClick = function (event) {
    var $span = jQuery(this);
    var id = $span.attr('data');

    if (id == 0) {
        $bf.Selection.PropertyTypeIds.length = 0;
        jQuery('#propertyTypeSelect div.selectbox > span').removeClass('selected');
        $span.addClass('selected');
    } else {
        $bf.ToggleInSet($bf.Selection.PropertyTypeIds, id);
        $span.toggleClass('selected');
        var $zero = $span.parent().find('span[data="0"]');
        $zero.removeClass('selected');
        if ($bf.Selection.PropertyTypeIds.length <= 0) $zero.addClass('selected');
    }

    $bf.GetJson('/Services/ProjectService.svc/Filters', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.FillList('citySelect', json.Cities);
        $bf.FillList('provinceSelect', json.Provinces);
        jQuery('#propertyCount').html(json.PropertyCount);
        $bf.Selection.QueryString = json.QueryString;
    });
};

$bf.MinPriceClick = function (event) {
    var $span = jQuery(this);
    $bf.Selection.MinPrice = $span.attr('data');

    jQuery('#minPriceSelect div.selectbox > span').removeClass('selected');
    $span.addClass('selected');

    $bf.GetJson('/Services/ProjectService.svc/Filters', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.FillList('citySelect', json.Cities);
        $bf.FillList('provinceSelect', json.Provinces);
        $bf.FillList('propertyTypeSelect', json.PropertyTypes);
        jQuery('#propertyCount').html(json.PropertyCount);
        $bf.Selection.QueryString = json.QueryString;
    });
};

$bf.MaxPriceClick = function (event) {
    var $span = jQuery(this);
    $bf.Selection.MaxPrice = $span.attr('data');

    jQuery('#maxPriceSelect div.selectbox > span').removeClass('selected');
    $span.addClass('selected');

    $bf.GetJson('/Services/ProjectService.svc/Filters', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.FillList('citySelect', json.Cities);
        $bf.FillList('provinceSelect', json.Provinces);
        $bf.FillList('propertyTypeSelect', json.PropertyTypes);
        jQuery('#propertyCount').html(json.PropertyCount);
        $bf.Selection.QueryString = json.QueryString;
    });
};

$bf.SelectProperty = function (link) {
    window.location.href = jQuery(link).attr('href') + '?query=' + $bf.Selection.QueryString;
};

$bf.LoadMap = function () {
    $bf.GetJson('/Services/ProjectService.svc/Locations', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, $bf.RenderMap);
};

$bf.RenderMap = function (locations) {
    $bf.InitMap('propertyMap');

    var bounds = new google.maps.LatLngBounds();
    jQuery(locations).each(function (index, value) {
        var latlng = new google.maps.LatLng(value.Latitude, value.Longitude);
        var marker = new google.maps.Marker({
            position: latlng,
            map: $bf.Map,
            title: value.Title,
            icon: '/images/woonproeven/icon_googlepin.png'
        });

        google.maps.event.addListener(marker, 'click', function () {
            $bf.InfoWindow.close();
            $bf.LoadInfoWindow(marker, value.Ids);
        });

        bounds.extend(latlng);
    });

    if (bounds.isEmpty()) {
        var centerMarker = new google.maps.Marker({
            position: new google.maps.LatLng(52.0, 5.0),
            map: $bf.Map
        });
        $bf.LoadEmptyInfoWindow(centerMarker);
        centerMarker.setMap(null);
    } else {
        google.maps.event.addListener($bf.Map, 'bounds_changed', function () {
            if ($bf.SetZoom && $bf.Map.getZoom() > 12) {
                $bf.Map.setZoom(12);
                $bf.SetZoom = false;
            }
        });

        $bf.Map.fitBounds(bounds);
    }
};

$bf.LoadInfoWindow = function (marker, idList) {
    var ids = [];
    jQuery(idList).each(function (index, value) { ids.push(value); });

    $bf.GetJson('/Services/ProjectService.svc/LocationProperties', { propertyIds: ids.join(','), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.RenderInfoWindow(json);
        $bf.InfoWindow.open($bf.Map, marker);
    });
};

$bf.LoadEmptyInfoWindow = function (marker) {
    $bf.InfoWindow = new InfoBubble({
        shadowStyle: 1,
        padding: 0,
        borderRadius: 0,
        arrowSize: 10,
        maxWidth: 300,
        borderWidth: 1,
        borderColor: '#908c83',
        disableAutoPan: true,
        hideCloseButton: false,
        arrowPosition: 30,
        backgroundClassName: 'info-popup',
        arrowStyle: 2
    });

    $bf.InfoWindow.setContent('Er zijn geen woningen gevonden die aan uw zoekcriteria voldoen. Wijzig uw zoekopdracht.');
    $bf.InfoWindow.setMinHeight(40);
    $bf.InfoWindow.open($bf.Map, marker);
};

$bf.RenderInfoWindow = function (json) {
    var html = [];

    var height = 11;
    jQuery(json).each(function (index, value) {
        var isPromo = promotionIds.indexOf(',' + (value.Url.split('/')[1]).substring(1) + ',') != -1;
        var itemHeight = isPromo ? 80 : 65;
        height += itemHeight;

        if (index > 0) {
            html.push('<div style="clear: both; padding-top: 2px; margin-bottom: 2px; border-bottom: solid 1px #999;"></div>');
            height += 5;
        }
        html.push('<div style="height: ', itemHeight, 'px;">');
        html.push('<a href="');
        html.push(value.Url);
        html.push('" onclick="$bf.SelectProperty(this); return false;"><img src="');
        html.push(value.ThumbnailUrl);
        html.push('" alt="" /></a><div class="details"><h2><a href="');
        html.push(value.Url);
        html.push('">');
        var name = value.Name;
        if (name.length > 30) name = name.substr(0, 28) + '...';
        html.push(name);
        html.push('</a></h2>');
        var projectName = value.ProjectName + ', ' + value.City;
        if (projectName.length > 42) projectName = projectName.substr(0, 40) + '...';
        html.push(projectName);
        html.push('<span>', value.Specs, '</span>');
        if (isPromo) html.push('<div style="margin-top: 4px; height: 18px;"><a href="', (promotionUrl != '' ? promotionUrl + '" target="_blank' : value.Url + '?p=1'), '" class="infoButton" style="background-color: ' + promotionColor + '">' + promotionTitle + '</a></div>');
        html.push('</div></div>');
    });

    $bf.InfoWindow.setContent(html.join(''));
    $bf.InfoWindow.setMaxHeight(height);
    $bf.InfoWindow.setMinHeight(height);
};

$bf.InitMap = function (elementId) {
    jQuery('#propertyMapContainer').html('<div id="' + elementId + '" style="width: 100%; height: 100%;"></div>');

    var myOptions = {
        zoom: 8,
        center: new google.maps.LatLng(52.1, 5.3),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    $bf.Map = new google.maps.Map(document.getElementById(elementId), myOptions);
    $bf.InfoWindow = new InfoBubble({
        shadowStyle: 1,
        padding: 0,
        borderRadius: 0,
        arrowSize: 10,
        minWidth: 350,
        maxWidth: 350,
        borderWidth: 1,
        borderColor: '#908c83',
        disableAutoPan: false,
        hideCloseButton: false,
        arrowPosition: 30,
        backgroundClassName: 'info-popup',
        arrowStyle: 2
    });
    $bf.SetZoom = true;
};

$bf.LoadList = function () {
    $bf.GetJson('/Services/ProjectService.svc/Properties', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId, pageIndex: $bf.Selection.PageIndex, pageSize: $bf.Selection.PageSize, sortField: $bf.Selection.SortField }, $bf.RenderList);
};

$bf.RenderList = function (json) {
    var from = $bf.Selection.PageIndex * $bf.Selection.PageSize + 1;
    var to = ($bf.Selection.PageIndex + 1) * $bf.Selection.PageSize;
    to = json.PropertyCount < to ? json.PropertyCount : to;
    jQuery('#numberSpan').text(from + '-' + to);
    jQuery('#countSpan').text(json.PropertyCount);

    var html = [];
    jQuery(json.Properties).each(function (index, value) {
        html.push('<li>');
        html.push('<a href="', value.Url, '" onclick="$bf.SelectProperty(this); return false;"><img src="', value.ImageUrl, '" alt="" style="width: 150px; height: 116px;" /></a>');
        html.push('<div class="details"><a href="', value.Url, '" onclick="$bf.SelectProperty(this); return false;"><h2>', value.Name, '</h2></a>');
        html.push(value.ProjectName, ', ', value.City);
        html.push('<span>', value.Specs, '</span>');
        if (promotionIds.indexOf(',' + (value.Url.split('/')[1]).substring(1) + ',') != -1) html.push('<div><a href="', (promotionUrl != '' ? promotionUrl + '" target="_blank' : value.Url + '?p=1'), '" class="infoButton" style="background-color: ' + promotionColor + '">' + promotionTitle + '</a></div>');
        html.push('</div>');
        html.push('<div class="price">', value.Price, '<a href="', value.Url, '" class="input-button" onclick="$bf.SelectProperty(this); return false;">Meer over deze woning</a></div>');
        html.push('</li>');
    });

    if (jQuery(json.Properties).size() <= 0) {
        jQuery('#propertyList').html('<li>Er zijn geen woningen gevonden die aan uw zoekcriteria voldoen. Wijzig uw zoekopdracht.</li>');
    } else {
        jQuery('#propertyList').html(html.join(''));
    }

    $bf.RenderPager('pagerTop', json.PropertyCount);
    $bf.RenderPager('pagerBottom', json.PropertyCount);
};

$bf.RenderPager = function (elementId, propertyCount) {
    var pageCount = Math.ceil(propertyCount / $bf.Selection.PageSize);
    var html = [];

    if (pageCount > 1) {
        html.push('<li class="first" onclick="$bf.ChangePage(0); return false;"><a title="eerste pagina"', $bf.Selection.PageIndex > 0 ? '' : ' disabled="disabled"', '>&nbsp;</a></li>');
        html.push('<li class="previous" onclick="$bf.ChangePage(', $bf.Selection.PageIndex - 1, '); return false;"><a title="vorige pagina"', $bf.Selection.PageIndex > 0 ? '' : ' disabled="disabled"', '>&nbsp;</a></li>');
        var start = pageCount > 7 ? Math.min(pageCount - 7, Math.max(0, $bf.Selection.PageIndex - 3)) : 0;
        for (var i = start; i < Math.min(pageCount, start + 7); i++) {
            if ($bf.Selection.PageIndex == i) {
                html.push('<li class="current">', i + 1, '</li>');
            } else {
                html.push('<li onclick="$bf.ChangePage(', i, '); return false;"><a href="#" title="pagina ', i + 1, '">', i + 1, '</a></li>');
            }
        }
        html.push('<li class="next" onclick="$bf.ChangePage(', $bf.Selection.PageIndex + 1, '); return false;"><a href="" title="volgende pagina"', $bf.Selection.PageIndex < pageCount - 1 ? '' : ' disabled="disabled"', '>&nbsp;</a></li>');
        html.push('<li class="last" onclick="$bf.ChangePage(', pageCount - 1, '); return false;"><a href="" title="laatste pagina"', $bf.Selection.PageIndex < pageCount - 1 ? '' : ' disabled="disabled"', '>&nbsp;</a></li>');
    }

    var pages = jQuery('#' + elementId + ' div.paging > ul');
    pages.html(html.join(''));
};

$bf.ChangeSortField = function (sortField) {
    $bf.Selection.SortField = sortField;
    $bf.LoadList();
};

$bf.SetPageSize = function (pageSize) {
    $bf.Selection.PageSize = pageSize;
    $bf.Selection.PageIndex = 0;

    var pagerTopFilter = jQuery('#pagerTop div.pfilter');
    pagerTopFilter.find('a.active').removeClass('active');
    pagerTopFilter.find('a.set' + pageSize).addClass('active');

    var pagerBottomFilter = jQuery('#pagerBottom div.pfilter');
    pagerBottomFilter.find('a.active').removeClass('active');
    pagerBottomFilter.find('a.set' + pageSize).addClass('active');

    $bf.LoadList();
};

$bf.ChangePage = function (pageIndex) {
    $bf.Selection.PageIndex = pageIndex;
    $bf.LoadList();
};

$bf.SetProjectName = function (projectName) {
    $bf.Selection.ProjectName = projectName;

    $bf.GetJson('/Services/ProjectService.svc/Filters', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.FillList('citySelect', json.Cities);
        $bf.FillList('provinceSelect', json.Provinces);
        $bf.FillList('propertyTypeSelect', json.PropertyTypes);
        jQuery('#propertyCount').html(json.PropertyCount);
    });
};

$bf.SerializeSelection = function () {
    var sel = $bf.Selection.CityIds.join(',');
    sel += '|' + $bf.Selection.ProvinceIds.join(',');
    sel += '|' + $bf.Selection.PropertyTypeIds.join(',');
    sel += '|' + $bf.Selection.MinPrice;
    sel += '|' + $bf.Selection.MaxPrice;
    sel += '|' + $bf.Selection.ProjectName;
    return sel;
};

$bf.SelectionFromElements = function () {
    $bf.Selection.CityIds = [];
    jQuery('#citySelect div.selectbox > span.selected').each(function (index, value) {
        $bf.Selection.CityIds.push(jQuery(value).attr('data'));
    });

    $bf.Selection.ProvinceIds = [];
    jQuery('#provinceSelect div.selectbox > span.selected').each(function (index, value) {
        $bf.Selection.ProvinceIds.push(jQuery(value).attr('data'));
    });

    $bf.Selection.PropertyTypeIds = [];
    jQuery('#propertyTypeSelect div.selectbox > span.selected').each(function (index, value) {
        $bf.Selection.PropertyTypeIds.push(jQuery(value).attr('data'));
    });

    var minSpan = jQuery('#minPriceSelect div.selectbox > span.selected');
    $bf.Selection.MinPrice = minSpan.length > 0 ? minSpan.first().attr('data') : 0;

    var maxSpan = jQuery('#maxPriceSelect div.selectbox > span.selected');
    $bf.Selection.MaxPrice = maxSpan.length > 0 ? maxSpan.first().attr('data') : 0;

    $bf.Selection.ProjectName = jQuery('#projectName').val();
};

$bf.ClearFilter = function () {
    $bf.Selection.CityIds = [];
    $bf.Selection.ProvinceIds = [];
    $bf.Selection.PropertyTypeIds = [];
    $bf.Selection.MinPrice = 0;
    $bf.Selection.MaxPrice = 0;
    $bf.Selection.ProjectName = '';
    $bf.Selection.PageIndex = 0;

    jQuery('#minPriceSelect div.selectbox > span').removeClass('selected');
    jQuery('#maxPriceSelect div.selectbox > span').removeClass('selected');
    jQuery('#projectName').val('');

    $bf.GetJson('/Services/ProjectService.svc/Filters', { serializedQuery: $bf.SerializeSelection(), currentNodeId: $bf.CurrentNodeId }, function (json) {
        $bf.FillList('citySelect', json.Cities);
        $bf.FillList('provinceSelect', json.Provinces);
        $bf.FillList('propertyTypeSelect', json.PropertyTypes);
        jQuery('#propertyCount').html(json.PropertyCount);
        $bf.Selection.QueryString = json.QueryString;
    });
};

$bf.LoadResult = function () {
    $bf.Selection.PageIndex = 0;
    if (jQuery('#mapView').is(':visible')) {
        $bf.LoadMap();
        $bf.LoadList();
    } else {
        $bf.LoadList();
        //$bf.LoadMap();
        $bf.Map == null;
    }
};

$bf.ShowList = function () {
    jQuery('#mapView').hide();
    jQuery('#listView').show();
    jQuery('#filterPanel a.button-card').removeClass('active');
    jQuery('#filterPanel a.button-list').addClass('active');
    jQuery('#sortSelector').css('visibility', 'visible');
};

$bf.ShowMap = function () {
    jQuery('#listView').hide();
    jQuery('#mapView').show();
    jQuery('#filterPanel a.button-list').removeClass('active');
    jQuery('#filterPanel a.button-card').addClass('active');
    jQuery('#sortSelector').css('visibility', 'hidden');
    if ($bf.Map == null) $bf.LoadMap();
};

$bf.AddToSet = function (set, val) {
    if (jQuery.inArray(val, set) <= -1) set.push(val);
};

$bf.RemoveFromSet = function (set, val) {
    if (jQuery.inArray(val, set) > -1) set.splice(jQuery.inArray(val, set), 1);
};

$bf.ToggleInSet = function (set, val) {
    if (jQuery.inArray(val, set) <= -1) set.push(val);
    else set.splice(jQuery.inArray(val, set), 1);
};

$bf.AttachScrollHandlers = function ($el, elSelectBox) {
    var elScrollUp = $el.find('a.scrollup');
    var elScrollDown = $el.find('a.scrolldown');

    jQuery(elScrollUp).click(function () {
        eMouseDown = false;
        return false;
    });
    jQuery(elScrollDown).click(function () {
        eMouseDown = false;
        return false;
    });

    jQuery(function ($) {
        jQuery(elScrollDown).mousedown(function () {
            $bf.Scrolling = true;
            $bf.ScrollUp(elScrollUp, elScrollDown, elSelectBox);
        }).mouseup(function () {
            $bf.Scrolling = false;
        });
    });

    jQuery(function ($) {
        jQuery(elScrollUp).mousedown(function () {
            $bf.Scrolling = true;
            $bf.ScrollDown(elScrollUp, elScrollDown, elSelectBox);
        }).mouseup(function () {
            $bf.Scrolling = false;
        });
    });
};

$bf.ScrollUp = function (elScrollUp, elScrollDown, elSelectBox) {
    var intMarginTop = parseInt(jQuery(elSelectBox).css('margin-top'));
    var intTotalHeight = parseInt(jQuery(elSelectBox).height());
    intMarginTop = intMarginTop - 12;

    if (intMarginTop > -(intTotalHeight - 60)) {
        if ($bf.Scrolling) {
            jQuery(elSelectBox).animate({
                'margin-top': intMarginTop
            }, 50, function () {
                $bf.ScrollUp(elScrollUp, elScrollDown, elSelectBox);
            });

        }

        jQuery(elScrollUp).removeClass('blocked');
        jQuery(elScrollDown).removeClass('blocked');
    } else {
        jQuery(elScrollUp).addClass('blocked');
        jQuery(elScrollDown).removeClass('blocked');
    }
};

$bf.ScrollDown = function (elScrollUp, elScrollDown, elSelectBox) {
    var intMarginTop = parseInt(jQuery(elSelectBox).css('margin-top'));
    var intTotalHeight = parseInt(jQuery(elSelectBox).height());
    intMarginTop = intMarginTop + 12;

    if (intMarginTop <= 0) {
        if ($bf.Scrolling) {
            jQuery(elSelectBox).animate({
                'margin-top': intMarginTop
            }, 50, function () {
                $bf.ScrollDown(elScrollUp, elScrollDown, elSelectBox);
            });
        }

        jQuery(elScrollDown).removeClass('blocked');
        jQuery(elScrollUp).removeClass('blocked');
    } else {
        jQuery(elScrollDown).addClass('blocked');
        jQuery(elScrollUp).removeClass('blocked');
    }
};


