﻿var hts = function() {
    var settings = {};

    //  Perform any initialization required for the site.
    var init = function(options) {
        $.extend(settings, options);

        //Setup site navigation
        $("#site-navigation>li").mouseover(function() {
            $(this).toggleClass("site-navigation-active");
        });

        $("#site-navigation>li").mouseout(function() {
            $(this).toggleClass("site-navigation-active");
        });

        $("#navigation-locations>a").click(function(e) {
            $("#navigation-locations>ul>li").slideToggle();
            e.preventDefault();
        });

        $("#navigation-locations>ul>li>a").click(function(e) {
            $(".location-active").slideToggle();
            $(".location-active").removeClass("location-active");
            $(".navigation-hotel", $(this).parent()).addClass("location-active");
            $(".location-active").slideToggle();

            e.preventDefault();
        });


        $("#site-navigation-locations>ul>li a").click(function(e) {
            $(".location-active").slideToggle();
            $(".location-active").removeClass("location-active");
            $(".navigation-hotel", $(this).parent()).addClass("location-active");
            $(".location-active").slideToggle();
        });

        //  Set active menu
        var selected = $("#navigation a[href='" + window.location.pathname + "']");
        
        //   Hide all the locations, menu is expanded by default in case user does not have javascript.
        $("#navigation-locations li").hide();
        
        //  Check if this is a hotel (location) page, if so set the correct sub menu
        if (selected.parent().hasClass("navigation-hotel")) {            
            $("#navigation-location").click();
            $("#navigation-location").parent().addClass('site-navigation-active');
            $("#" + selected.attr("class") + "-top").click();
            selected.addClass("navigation-hotel-active");
        } else {
            selected.parent().addClass('site-navigation-active');
        }

        //  Email subscribe button
        $("#subscription-form button").click(function(e) {
            e.preventDefault();

            var emailField = $('#email');
            var nameField = $('#name');

            $.post(settings.subscribeAction, {
                email: emailField.val(),
                name: nameField.val()
            }, function(response) {
                alert(response);
                if (response.indexOf('success') !== -1) {
                    emailField.val('');
                    nameField.val('');
                }
            });
        });

        //hts.resizeNav();
    }

    var resizeNav = function() {
        var minSize = new Number($("#content-right-container").css("min-height").substring(0, 3));
        var newSize = $("#content-left-container").height();

        newSize = (newSize > minSize) ? newSize : minSize;

        $("#content-right-container").height(newSize);
    }
    return {
        init: init,
        resizeNav: resizeNav
    }
} ();
