$(function () {
    var app = Sammy(function () {
        var self = this;
        var addFeaturedModule = function () {
            $("#featured").load("Templates/Featured.html");
        }
                    
        self.get("#/", function () {
            addFeaturedModule();

            $(".nav.navbar-nav li").removeClass("active");
            $("#home").addClass("active");
            $(".navbar-collapse.collapse.in").removeClass("in");

            $("#main-content").load("Templates/Catalog.html", function () {
                ko.cleanNode($("#main-content")[0]);
                var propertyViewModel = new PropertyViewModel();
                propertyViewModel.intilialize();
                ko.applyBindings(propertyViewModel, $("#main-content")[0]);
            });
        });

        this.get("#detail/:id", function (sender) {

            var id = sender.params["id"];
            $("#featured").empty();
            $("#main-content").load("Templates/Detail.html", function () {
                ko.cleanNode($("#main-content")[0]);
                var propertyViewModel = new PropertyViewModel();
                propertyViewModel.loadCurrentProperty(id);
                ko.applyBindings(propertyViewModel, $("#main-content")[0]);
            });
        });

        this.get("#about", function () {

            $(".nav.navbar-nav li").removeClass("active");
            $("#about").addClass("active");
            $(".navbar-collapse.collapse.in").removeClass("in");

            $("#featured").empty();
            ko.cleanNode($("#main-content")[0]);
            $("#main-content").load("Templates/About.html");
        });

        this.get("#contact", function () {

            $(".nav.navbar-nav li").removeClass("active");
            $("#contact").addClass("active");
            $(".navbar-collapse.collapse.in").removeClass("in");

            $("#featured").empty();
            $("#main-content").load("Templates/Contact.html", function () {
                ko.cleanNode($("#main-content")[0]);
                var contactUsViewModel = new ContactUsViewModel();
                contactUsViewModel.intilialize();
                ko.applyBindings(contactUsViewModel, $("#main-content")[0]);
            });
        });
    });
    app.run("#/");
});