include("ajax.js");

var Contacts = function(caller){
    var progressBar = "#loadingbar";
    this.ajax = new Ajax("module", "Contacts", progressBar, caller);
}

Contacts.prototype.loadContacts = function(contactsId){
    this.ajax.appendVar("id", contactsId);

	return this.ajax.request("loadContacts",
        function(response){            
            if (response){
                $("#contacts").html(response);
                initContacts();
            }
            else {
                alert("Возникла ошибка при загрузке контактов.");
                initContacts();
            }
        }
    );
}

function initContacts(){
    $(".city_list li a").unbind();
    $(".city_list li a").click(function(){
        var contacts = new Contacts(this);
        contacts.loadContacts($(this).attr("rel"));
    });
    $(".curr1").unbind();
    $(".curr1").click(function () {
		$(this).find("span").toggleClass("closed");
		$(".city_list_wrap").toggle();
	});
}

$(document).ready(
    function(){        
        initContacts();
    }
);
