﻿$(document).ready(function() {
            function calcPos() {
                $("[id$='dropdown']").each(function(i) {
                    var obj = $("[name='" + $(this).attr("id") + "']");

                    var offset = $(obj).offset();
                    var width = $(obj).css("width");
                    width = width.substring(0, width.length - 2);
                    var leftOffset = parseInt(offset.left) + parseInt(width);

                    var height = $(obj).css("height");
                    height = height.substring(0, height.length - 2);
                    var topOffset = parseInt(offset.top);

                    $(this).css("left", leftOffset + "px").css("top", Math.round(topOffset) + "px");
                });
            }

            $("body").append(
                $("<div></div>").attr("id", "TimerPlaceholder").css("display", "none")
            );

            $(".navMenuItem").hover(
                function() {
                    $(this).children("img").attr("src", $(this).children("img").attr("hoverSrc"));
                },
                function() {
                    $(this).children("img").attr("src", $(this).children("img").attr("defaultSrc"));
                }
            );

            //set up all the dropdowns to line up with their respective links
            calcPos();

            $(window).bind("resize", function() {
                calcPos();
            });

            //we need to add some sort of indicator on drop down stuff
            $("[name$='dropdown']").append(
                $("<span></span>").html("&nbsp;&nbsp;&nbsp;<b>&#187;</b>")
            );

            $("[name$='dropdown']").hover(
                function() {
                    $("#" + $(this).attr("name")).show();
                    $(this).stopTime("ddCollapse");
                },
                function() {
                    var me = this;
                    $(this).oneTime(150, "ddCollapse", function() {
                        $("#" + $(me).attr("name")).hide();
                    });
                }
            );

            $("[id$='dropdown']").hover(
                function() {
                    $(this).show();
                    $("[name='" + $(this).attr("id") + "']").stopTime("ddCollapse");
                },
                function() {
                    var me = this;
                    $("[name='" + $(this).attr("id") + "']").oneTime(150, "ddCollapse", function() {
                        $(me).hide();
                    });
                }
            );

            $("[id$='dropdown']").children().hover(
                function() {
                    $(this).parent().show();
                    $("[name='" + $(this).parent().attr("id") + "']").stopTime("ddCollapse");
                },
                function() {
                    var me = this;
                    $("[name='" + $(this).parent().attr("id") + "']").oneTime(150, "ddCollapse", function() {
                        $(me).parent().hide();
                    });
                }
            );
        });
