﻿$(document).ready(function() {
    var selected = "Cruises";

    $(".cruiseButton").each(
                function() {
                    var overSrc = "";
                    if (this.src.endsWith(".gif"))
                        overSrc = this.src.replace(".gif", "-over.gif");
                    if (this.src.endsWith(".jpg"))
                        overSrc = this.src.replace(".jpg", "-over.jpg");
                    if (this.src.endsWith(".png"))
                        overSrc = this.src.replace(".png", "-over.png");

                    if (this.alt == selected) {
                        var src = this.src;
                        this.src = overSrc;
                        overSrc = src;
                    }

                    jQuery("<img>").attr("src", overSrc);
                }
            );

    $(".cruiseButton").hover(
            function() {
                if (this.src.search("-over") < 0) {
                    var overSrc = "";
                    if (this.src.endsWith(".gif"))
                        overSrc = this.src.replace(".gif", "-over.gif");
                    if (this.src.endsWith(".jpg"))
                        overSrc = this.src.replace(".jpg", "-over.jpg");
                    if (this.src.endsWith(".png"))
                        overSrc = this.src.replace(".png", "-over.png");

                    this.src = overSrc;
                }
            },
            function() {
                if (this.alt != selected)
                    this.src = this.src.replace("-over", "");
            });

    $(".cruiseButton").click(
            function() {
                oldselection = selected;
                selected = this.alt;

                $(".cruiseButton").each(function() {
                    if (this.alt != selected)
                        this.src = this.src.replace("-over", "");
                });

                $("#" + oldselection.replace(/ /g, "")).slideUp("slow",
                function() {
                    $("#" + selected.replace(/ /g, "")).slideDown("slow");
                });
            });
});
