
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

var onMenu = "";
var activeMenu = "";
var menuTimer = "";
var mainMenuButton = "";
var lastMenu = "";

$(document).ready(function() {
    $("#navHeader img").each(function() {

        var thisItem = $(this).attr("id");

        var newImg = $(this).attr("src");
        var overImg = newImg.replace(/.gif/, "_on.gif");

        $(this).bind("mouseover", function() {
            if (newImg.indexOf("_on.gif") == -1 && $(this).attr("rel") != "nochange") {
                $(this).attr("src", overImg);

// new
                clear_menus();

                if ($(this).attr("id") == "menu_welcome") {
                    onMenu = "welcome";
                    $("#drop_menu_welcome").show();
                }

                if ($(this).attr("id") == "menu_about") {
                    onMenu = "about";
                    $("#drop_menu_about").show();
                }

                if ($(this).attr("id") == "menu_services") {
                    onMenu = "services";
                    $("#drop_menu_services").show();
                }

                if ($(this).attr("id") == "menu_new_patients") {
                    onMenu = "new_patients";
                    $("#drop_menu_new_patients").show();
                }

// end new
            }
        });
        $(this).bind("mouseout", function() {
            var newImg = $(this).attr("src");
            if (newImg.indexOf("_on.gif") > 0 && thisItem != onMenuItem && $(this).attr("rel") != "nochange") {

                newImg = newImg.replace(/_on.gif/, ".gif");
                $(this).attr("src", newImg);
// new
                drop_menu_timeout();
// end new
            }
        });

        // preload
        if ($(this).attr("rel") != "nochange") {
                jQuery.preLoadImages(overImg);
        }
        if (onMenuItem == $(this).attr("id") ) {
            $(this).attr("src", overImg);
        }

    });

// new
    $('.drop_menu').each(function() {
        $(this).bind("mouseover", function() {
            activeMenu = true;
            onMenu = $(this).attr("id");

            // show the over state of the menu item
            mainMenuItem = onMenu.substr(10, 30);

            $("#menu_" + mainMenuItem).attr("src", "/images/but_" + mainMenuItem + "_on.gif");
            onMenu = mainMenuItem;
        });

        $(this).bind("mouseout", function() {
            activeMenu = false;
            drop_menu_timeout();
        });

    });

// end new
})

function drop_menu_timeout() {

    if (activeMenu) {

    } else {
        onMenu = "";
        menuTimer = setTimeout("do_drop_menu_timeout()", 1000);
    }
}

function do_drop_menu_timeout() {
    clearTimeout(menuTimer);

   if (onMenu != "welcome" && onMenu != "drop_menu_welcome") {
        $("#drop_menu_welcome").hide();
        if (onMenuItem != "menu_welcome") {
            $("#menu_welcome").attr("src", "/images/but_welcome.gif");
        }
    }

    if (onMenu != "about" && onMenu != "drop_menu_about") {
        $("#drop_menu_about").hide();
        if (onMenuItem != "menu_about") {
            $("#menu_about").attr("src", "/images/but_about.gif");
        }
    }

    if (onMenu != "services" && onMenu != "drop_menu_services") {
        $("#drop_menu_services").hide();
        if (onMenuItem != "menu_services") {
            $("#menu_services").attr("src", "/images/but_services.gif");
        }
    }

    if (onMenu != "new_patients" && onMenu != "drop_menu_new_patients") {
        $("#drop_menu_new_patients").hide();
        if (onMenuItem != "menu_new_patients") {
            $("#menu_new_patients").attr("src", "/images/but_new_patients.gif");
        }
    }

}

function clear_menus() {
        $("#drop_menu_welcome").hide();
        $("#drop_menu_about").hide();
        $("#drop_menu_services").hide();
        $("#drop_menu_new_patients").hide();
}

function submitContactForm() {
    if ($("#ea").val() != "") {
        $("#ccoptin").submit();
    } else {
        alert("Please provide an email address before submitting.")
        $("#ea").focus();
    }
}



  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-16613299-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

