$(function() {

    // set the default one to the correct position and show
    if ($("#main-nav .default a.off").position()) {
        var leftpos = $("#main-nav .default a.off").position().left;
        $("#main-nav .default a.on").css({ 'left': leftpos + "px", 'display': 'block' })
    }

    // manage menu rollovers
    $("#main-nav a.off").mouseenter(function() {
        if ($(this).next().is(':hidden')) {
            // fade out the default button
            $("#main-nav .on").hide();

            // fade in the rollover state into the correct position
            $(this).next().css({ 'left': $(this).position().left + 'px' });
            $(this).next().fadeIn(200).css({ 'display': 'block' });

            // hide all subnavs
            $("#subNav > ul").hide();

            // and show the one we need
            var parentId = $(this).parent().attr("id");
            if (parentId) {
                $("ul#" + parentId + "_sub").fadeIn(200);
            }
        }
    });

    $("#nav").mouseleave(function() {
        $("#main-nav a.on").hide();
        $("#subNav > ul:visible").hide();

        if ($('#main-nav a.on:visible').length == 0) {
            $('#main-nav .default a.on').show();
            $('#subNav .default').show();
        }
    });

    $('#subNav li').hover(function() {
        if (!$(this).hasClass('default')) {
            $('#subNav li.default').removeClass('default').addClass('defaultInactive');
        }
    }, function() {
        $('#subNav li.defaultInactive').removeClass('defaultInactive').addClass('default');
    });

    //clears text inputs onfocus
    $('textarea').focus(function() {
        if (!$(this).hasClass('cleared')) {
            $(this).addClass('cleared');
            $(this).val('');
        }
    });

    //submit rollovers
    $('.hover').mouseover(
            function() { // Change the input image's source when we "roll on"
                $(this).css("background-position", "bottom left");
            });

    $('.hover').mouseout(
			function() { // Change the input image's source back to the default on "roll off"
			    $(this).css("background-position", "top left");
			}
        );

    // signup menu
    $('.signup2 a').hover(function() {
        $(this).children('.on').show();
        $(this).children('.off').hide();
    }, function() {
        $(this).children('.on').hide();
        $(this).children('.off').show();
    });
});            //document ready end 
