google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.2");
    
google.setOnLoadCallback(function() {
    $(document).ready(function() {
        // Apply drop shadow
        $(".shadow").dropShadow();

        // Set up facebox stuff including a darkened background
        $('a[rel*=facebox]').facebox({
            noAutoload: true
        });
        $(document).bind('loading.facebox', function() {
            $("#opaque").fadeIn('slow');
        });
        $(document).bind('close.facebox', function() {
            $("#opaque").fadeOut('slow');
        });
        $(document).bind('afterReveal.facebox', function() {
            // this is a fix for IE6 which resets the height to 100% of the window height
            $("#opaque").height($(document).height());
        });

        // Expand Top Panel
        $("#open").click(function(){
            $("div#panel").slideDown({
                easing: 'easeOutElastic',
                duration: 1800
            });
        }); 
        // Collapse Panel
        $("#close").click(function() {
            $("div#panel").slideUp({
                duration: 1100,
                easing: 'easeOutBounce'
            }); 
        });     
        // Switch buttons from "Log In | Register" to "Close Panel" on click
        $("#toggle a").click(function () {
            $("#toggle a").toggle();
        });
        // Submit register form via ajax
        $('.error').hide();
        $("#register_button").click(function() {
            $('.error').hide();
            var email = $("input#email").val();
            if (email === "") {
                $("label#email_error").show();
                $("input#email").focus();
                return false;
            }
            $.ajax({
                type: "POST",
                url: "addEmail.php",
                data: "emailAddr=" + email,
                dataType: "text",
                success: function(data, textStatus) {
                    var status = data.split(':')[0];
                    if (status === "success") {
                        $('#register_form').html("<h1>Email Submitted!</h1>")
                        .append("<p class='grey' id='register_message'>Thanks for signing up! You'll be hearing from us soon.</p><img id='checkmark' src='images/check.png' alt='success'/>")
                        .hide().fadeIn(2000);
                        $('#greeting').html('Hello ' + data.split(' ')[2].split('@')[0]);
                    } else {
                        $("label#email_error").show();
                        $("input#email").focus();
                        return false;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    this; // the options for this ajax request
                    alert('XHR Status = ' + XMLHttpRequest.status + ':' + XMLHttpRequest.responseText + '\nError = ' + errorThrown);
                }
            });
        });
        
        $("#menu a").hover(function() {
            $(this).stop(true, true).fadeOut(100);
            $(this).fadeIn(400);
        });

        $(".step").hover(function() {
            $(this).stop(true, true).fadeOut(100);
            $(this).fadeIn(600);
            var stepId = "#" + this.id + "Txt";
            $(stepId).stop(true, true).animate({ backgroundColor:"#E0E0E0", color:"#F14D28", top:"+=.8em" }, "slow"); 
        }, function() {
            var stepId = "#" + this.id + "Txt";
            $(stepId).stop(true, true).animate({ backgroundColor:"#fff", color:"#444", top:"-=.8em" }, "slow");
        });

        // This loads the newest live times into the info box every minute.
        $("#info").load("/findjoey/index.php");
        $(document).everyTime(60000, function() {
            $("#info").load("/findjoey/index.php");
        }, 0, true);        
    });
});