$(function() {

    window.citiesIsOpened=false;
    window.selectedCity='';

    $(".citySelector").click(function(){
        if(citiesIsOpened==false) {
            $(".citiesWindow").show(100, function(){
                $(".citySelector").removeClass("closed");
            });
            citiesIsOpened=true;
        } else {
            $(".citiesWindow").hide(100, function(){
                $(".citySelector").addClass("closed");
            });
            citiesIsOpened=false;
        }
    });

    $(".citiesList li").click(function(){
        selectedCity=$(this).html();
        
        $(".citiesList li").removeClass('selected');
        $(this).addClass('selected');
    })

    $(".selectBtn").click(function(){
        if(selectedCity!=''){
            $(".cityName").html(selectedCity);
            //В этом месте нужно отправлять на сервер значение переменной selectedCity
            $(".citiesWindow").hide(100, function(){
                $(".citySelector").addClass("closed");
            });
            citiesIsOpened=false;
        }
    });

    $(".closeBtn").click(function(){

            $(".citiesWindow").hide(100, function(){
                $(".citySelector").addClass("closed");
            });
            citiesIsOpened=false;

    });



    var winHeight = $(window).height();//Высота видимой области окна браузера
    var contentHeight = $(".bottom").offset().top + $(".bottom").height()+30;
    if (winHeight > contentHeight) {
        var neededOffset = winHeight - 30 - $(".bottom").height();
        $(".bottom").offset({top: neededOffset, left: 0});
    }

});
