




	











	        
	



	
		



	
		







	








	
		



	
		
		
		/**
 * Some common js, including the js for the global navigation
 */
(function($) {

    // Main navigation drop down menus
    $(document).ready(function() {
        $("#main-nav li").hover(
            function() {
                var img = $(this).find("a img:not(.rollover)");
                var rollover = $(this).find("a img.rollover");
                if (rollover.size() > 0) {
                    img.css("display", "none");
                    rollover.css("display", "block");
                    $(this).find(".main-nav-menu").css("display", "block");
                }
            },
            function() {
                var img = $(this).find("a img:not(.rollover)");
                var rollover = $(this).find("a img.rollover");
                if (rollover.size() > 0) {
                    img.css("display", "block");
                    rollover.css("display", "none");
                    $(this).find(".main-nav-menu").css("display", "none");
                }
            }
        );

        $("#main-nav li .main-nav-menu .top").click(function(e) {
            if (!$(e.target).is("a")) {
                var anchor = $(this).parent("div").siblings("a");
                var href = anchor.attr("href");
                var target = anchor.attr("target");
                if (target == "_blank") {
                    window.open(href);
                } else {
                    window.location.href = href;
                }
                return false;
            }
        });
    });

    // Search box and site selector dropdown
    $(document).ready(function() {

        var defaultSearchBoxValue = "Enter Search Term";
        $("#searchform #searchbox").focus(function() {
            if ($(this).val() == defaultSearchBoxValue) {
                $(this).val("");
            }
        });
        $("#searchform #searchbox").blur(function() {
            if ($.trim($(this).val()).length == 0) {
                $(this).val(defaultSearchBoxValue);
            }
        });
        $("#searchform #search-submit").click(function() {
            if ($.trim($("#searchform #searchbox").val()).length == 0 || $("#searchform #searchbox").val() ==  defaultSearchBoxValue) {
                return false;
            }
        });

        $("#site-selector select option:first").attr("selected", true);

        $("#site-selector select").change(function() {
            window.location.href = $(this).find("option:selected").val();
        });

        /*
        $("#site-selector div").click(function() {
            var dropdown = $(this).next("ul");
            dropdown.slideDown("fast", function() {
                $(document).one("click", function() {
                    dropdown.slideUp("fast");
                });
            });
        });
        */
    });


    // Right nav widget "accordian" behavior
    $(document).ready(function() {
        var navWidgetTimer;
        $(".right-nav-widget").hover(
            function(e) {
                // Datepicker jquery widget triggers mouseover events. Ignore them.
                if ($(e.target).parents("#bookonline-calendar-container").size() > 0) {
                    return;
                }
                if (!$(this).is("#widget-bookOnline")) {
                    $("#bookonline-calendar").css("left", "");
                    $("#widget-bookOnline form select").blur();
                }
                var that = this;
                clearTimeout(navWidgetTimer);
                navWidgetTimer = setTimeout(function() {
                    expandRightNavWidget(that);
                }, 100);
            },
            function() {
                clearTimeout(navWidgetTimer);
            }
        );

        // Special case for the homepage which is fully collapsed when not in use.
        $("#right-nav-widgets.homepage").hover(function() {}, function(e) {
            if ($(e.target).is("select") || $(e.target).is("option")) {
                return;
            }
            $("#bookonline-calendar").css("left", "");
            $("#widget-bookOnline form select").blur();
            clearTimeout(navWidgetTimer);
            collapseAllWidgets();
        });

        function expandRightNavWidget(element) {
            var elem = $(element);
            var expandedWidgets = $(".right-nav-widget.expand");

            if (elem.hasClass("expand")) {
                return;
            }

            var collapsedHeight = elem.height();
            elem.addClass("expand");
            var expandedHeight = elem.height(); 
            elem.height(collapsedHeight);

            expandedWidgets.removeClass("expand");
            expandedWidgets.height(expandedHeight);

            // iepngfix looks to see if the class has changed on the element 
            // to decide whether or not to trigger the pngfix.
            // so we add a dummy class here
            if ($.browser.msie && $.browser.version < "7") {
                var elements = expandedWidgets.add(elem);
                elements.find("h3.iepngfix_dummyclass").removeClass("iepngfix_dummyclass");
                elements.find("h3:not(.iepngfix_dummyclass)").addClass("iepngfix_dummyclass");
            }

            $(".right-nav-widget").stop(true, true);

            elem.animate({
                height : expandedHeight + "px"
            }, { 
                easing : "swing",
                duration : 350,
                step : function(i) {
                    var h = expandedHeight - i + collapsedHeight;
                    if ($.browser.msie || $.browser.safari) {
                        h = Math.ceil(h);
                    }
                    expandedWidgets.height(h);
                },
                complete : function() {
                    elem.css("height", "");
                    expandedWidgets.css("height", "");
                }
            });
        }

        function collapseAllWidgets() {
            var expandedWidgets = $(".right-nav-widget.expand");
            if (expandedWidgets.size() == 0) {
                return;
            }

            $(".right-nav-widget").stop(true, true);

            var expandedHeight = expandedWidgets.height();
            expandedWidgets.removeClass("expand");
            var collapsedHeight = expandedWidgets.height();
            expandedWidgets.height(expandedHeight);

            // iepngfix looks to see if the class has changed on the element 
            // to decide whether or not to trigger the pngfix.
            // so we add a dummy class here
            if ($.browser.msie && $.browser.version < "7") {
                var elements = expandedWidgets;
                elements.find("h3.iepngfix_dummyclass").removeClass("iepngfix_dummyclass");
                elements.find("h3:not(.iepngfix_dummyclass)").addClass("iepngfix_dummyclass");
            }

            expandedWidgets.animate({
                height : collapsedHeight + "px"
            }, { 
                easing : "swing",
                duration : 350,
                complete : function() {
                    expandedWidgets.css("height", "");
                }
            });
        }

        /*
        var initialY = $("#right-nav").offset().top;
        $(window).scroll(function() {
            var paddingTop = 10;
            var scrollY = $(window).scrollTop();
            var posY = $("#right-nav").offset().top;
            var y = Math.min(Math.max(scrollY - initialY + paddingTop, 0), $("#content-container").height() - $("#right-nav").height());

            $("#right-nav").stop(true, true);
            $("#right-nav").animate({
                marginTop :  y + "px"
            }, {
                easing : "swing",
                duration : 300
            });
        });
        */
    });

    // Book online / Calendar widget
    $(document).ready(function() {
        //$("#bookonline-calendar").css("display", "none");
        $("#bookonline-calendar").bgiframe();
            
        var calendarInitialized = false;
        $("#bookonline-calendar-button").click(function() {
            $("#bookonline-calendar").css({
                "left" : "-133px"
            });
            if (!calendarInitialized) {
                $("#bookonline-calendar > #bookonline-calendar-container").datepicker({
                    dayNamesMin : ['S','M','T','W','Th','F','S'],
                    prevText : '',
                    nextText : '',
                    showOtherMonths : true,
                    onSelect : function(dateText) {
                        var dateSplit = dateText.split("/");
                        var d = new Date(dateSplit[2], dateSplit[0] - 1, dateSplit[1]);
                        setDate(d);
                        $("#bookonline-calendar > .close").click();
                    }
                });
                var selBgColor = $("#bookonline-calendar .ui-datepicker-current-day").css("background-color");
                var selFontColor = $("#bookonline-calendar .ui-datepicker-current-day a").css("color");

                $("#bookonline-calendar td:not(.ui-datepicker-current-day)").live("mouseover", function() {
                    $(this).css({ "background-color":selBgColor });
                    $(this).find("a").css({ "color":selFontColor });
                });
                $("#bookonline-calendar td:not(.ui-datepicker-current-day)").live("mouseout", function() {
                    $(this).css({ "background-color":"" });
                    $(this).find("a").css({ "color":"" });
                });
                calendarInitialized = true;
            }
            return false;
        });

        $("#bookonline-calendar > .close").click(function() {
            $("#bookonline-calendar").css("left", "");
            return false;
        });

        $("#bookOnline-form select[name='DateInMonth'], #bookOnline-form select[name='DateInYear']").change(function() {
            var day = parseInt($("#bookOnline-form select[name='DateInDay']").val());
            var month = parseInt($("#bookOnline-form select[name='DateInMonth']").val());
            var year = parseInt($("#bookOnline-form select[name='DateInYear']").val());
            var numDays = daysInMonth(month, year);
            $("#bookOnline-form select[name='DateInDay'] option").css({
                "display" : "", 
                "visibility" : ""
            }).attr("disabled", "");
            $("#bookOnline-form select[name='DateInDay'] option:gt(" + (numDays - 1) + ")").css({
                "display" : "none", 
                "visibility" : "hidden"
            }).attr("disabled", "disabled");

            if (day > numDays) {
                day = numDays;
            }
            $("#bookOnline-form select[name='DateInDay']").val(day);
        });

        $("#bookOnline-form select[name='DateInMonth'], #bookOnline-form select[name='DateInDay'], #bookOnline-form select[name='DateInYear']").change(function() {
            var month = parseInt($("#bookOnline-form select[name='DateInMonth']").val());
            var day = parseInt($("#bookOnline-form select[name='DateInDay']").val());
            var year = parseInt($("#bookOnline-form select[name='DateInYear']").val());
            d = new Date(year, month, day);
            setDate(d);
        });

        var selectedDate = new Date();
        var today = new Date();
        today.setHours(0);
        today.setMinutes(0);
        today.setSeconds(0);
        today.setMilliseconds(0);

        function setDate(dateObj) {
            var month = dateObj.getMonth();
            var day = dateObj.getDate();
            var year = dateObj.getFullYear();
            var dateText = (dateObj.getMonth()+1) + "/" + dateObj.getDate() + "/" + dateObj.getFullYear();
            $("#bookOnline-form input[name='DateIn']").val(dateText);
            $("#bookOnline-form select[name='DateInMonth']").val(month);
            $("#bookOnline-form select[name='DateInDay']").val(day);
            $("#bookOnline-form select[name='DateInYear']").val(year);
            $("#bookonline-calendar > div").datepicker('setDate', dateObj);
            selectedDate = dateObj;
        }
        
        function getDate() {
            return selectedDate;
        }

        setDate(new Date());

        // Form submission handler and validation
        $("#bookOnline-form").submit(function() {
            var selectedDate = getDate(); 
            if (selectedDate.getTime() < today.getTime()) {
                alert("Please select a valid date.");
                return false;
            }
            if ($("#bookOnline-form select[name='HotelID']'").val() == "") {
                alert("Please select a hotel");
                return false;
            }
            
            var url = $(this).attr("action") + "?" + $(this).serialize();
            window.open(url, 'onlinebooking');
            return false;
        });

        $("#bookonline-submit").hover(
            function() {
                $(this).addClass("hover");
            },
            function() {
                $(this).removeClass("hover");
            }
        ).click(function() {
            $("#bookOnline-form").submit();
            return false;
        });


        function daysInMonth(iMonth, iYear) {
            return 32 - new Date(iYear, iMonth, 32).getDate();
        }
    });


    // Call/Chat widgets (3rd party: "LivePerson")
    // The LivePerson service will send a different image depending on whether the liveperson
    // representative is online or offline. We will inspect this image to determine online/offline state
    $(document).ready(function() {

        // The update function
        function updateChatAndCallWidgetStates() {
            var isSA = false;
            if (typeof(SITE_CODE) != 'undefined' && SITE_CODE != null && SITE_CODE == 'SA') {
                isSA = true;
            }

            var acctID = "37855838";
            if (isSA) {
                acctID = "69158678";
            }

            var lpImgSrc = "https://server.iad.liveperson.net/hc/" + acctID + "/?cmd=repstate&site=" + acctID + "&ver=1";
            lpImgSrc = lpImgSrc + "&imageUrl=http://www.destinationkohler.com/common/images/liveperson/";
            //lpImgSrc = lpImgSrc + '&d=' + ((new Date()).getTime());

            //if (isSA) {
            //    lpImgSrc = lpImgSrc + "&skill=St%20Andrews";
            //}

            // Test to see if the LivePerson call representative is online
            var lpCallImgSrc = lpImgSrc + '&channel=voice';
            var lpCallImg = $('<img style="position:absolute; left:-1000px;" src="' + lpCallImgSrc + '" border="" alt=""/>')
            lpCallImg.load(function() {
                if (lpCallImg.height() == 2) {
                    // if the height of the image returned is 2 pixels, the agent is online
                    $("#widget-call .offline").css("display", "none");
                    $("#widget-call .online").css("display", "block");
                } else {
                    $("#widget-call .online").css("display", "none");
                    $("#widget-call .offline").css("display", "block");
                }
                lpCallImg.remove();
            });
            $("body").append(lpCallImg);

            // Test to see if the LivePerson chat representative is online
            var lpChatImgSrc = lpImgSrc + '&channel=web';
            var lpChatImg = $('<img style="position:absolute; left:-1000px;" src="' + lpChatImgSrc + '" border="" alt=""/>')
            lpChatImg.load(function() {
                if (lpChatImg.height() == 2) {
                    // if the height of the image returned is 2 pixels, the agent is online
                    $("#widget-chat .offline").css("display", "none");
                    $("#widget-chat .online").css("display", "block");
                } else {
                    $("#widget-chat .online").css("display", "none");
                    $("#widget-chat .offline").css("display", "block");
                }
                lpChatImg.remove();
            });
            $("body").append(lpChatImg);
        }

        // Periodically check the call/chat widget states and update accordingly
        function periodicUpdate() {
            updateChatAndCallWidgetStates();
            setTimeout(function() {
                periodicUpdate();
            }, 180000);
        }

        // Start it up
        periodicUpdate();
    });

})(jQuery);





	
	
						
				







