﻿$(function() {
    var itemSelected = false;

    // loop through menu items and set selected image for button whose id exists in url
    $(".menuButton").each(
        function() 
        {
            if (window.location.toString().indexOf($(this).attr("id")) != -1) 
            {
                $(this).attr("src", $(this).attr("src").split(".").join("_SELECTED."));
                $(this).attr("data-selected", "true");
                itemSelected = true;
            }
            else
                $(this).attr("data-selected", "false");
        }
    );

    // default selected image to products if none set above
    if (!itemSelected) 
    {
        $("#Product").attr("src", $("#Product").attr("src").split(".").join("_SELECTED."));
        $("#Product").attr("data-selected", "true");
    }

    // set hover events 
    $(".menuButton").hover(
        function() 
        {
            if ($(this).attr("data-selected") == "false")
                $(this).attr("src", $(this).attr("src").split(".").join("_HOVER."));
            else
                $(this).attr("src", $(this).attr("src").split("_SELECTED.").join("_HOVER."));
        },
        function() 
        {
            if ($(this).attr("data-selected") == "false")
                $(this).attr("src", $(this).attr("src").split("_HOVER.").join("."));
            else
                $(this).attr("src", $(this).attr("src").split("_HOVER.").join("_SELECTED."));
        }
    );
});