function rebind() {
	$('#email')
		.keyup(function(evt) {
			if (evt.keyCode == 13)
				do_signup();
		});
}
var defemail = 'youremail@yourcompany.com';
var mpmetrics;
function init_home () {
    init_new_input('#email', 'youremail@yourcompany.com');

	rebind();
    $('#screenshot').click(function(evt) {
		//XXX: disable the screencast for now -- go to the tour page instead
		window.location.href = '/tour/';
		return;
        st_dialog($('#screencast-box'));
        flowplayer("screencast-player", "/static/flowplayer-3.1.1.swf",
                    {
                        plugins: {
                            controls: {
                                autoHide: 'always'
                            }
                        }
                    }
                );
        $('#screencast-close').click(function(evt) {
            st_close_dialog();
            flowplayer('screencast-player').stop();
        });
    });
    try {
        mpmetrics = new MixpanelLib("955fc3da29eba7f0feda4fd758cfb182");
    } catch(err) {
        null_fn = function () {};
        mpmetrics = { track: null_fn, track_funnel: null_fn, register: null_fn, register_once: null_fn };
    }
    mpmetrics.track_funnel('Signup', 1, "Homepage View");
}
function signup_error(message) {
	$('#throbber').replaceWith('<div class="error">'  +
	message +
	'</div><img src="/static/images/button_signup.png" id="createaccount" onclick="do_signup()" />');
	rebind();
}
function do_signup() {
	var e = $('#email');
	$('.error').remove();
	$('#createaccount').replaceWith('<div id="throbber"><img src="/static/images/home/throbber.gif" /></div>');
	if (e.val() == defemail)
		signup_error("Please enter your email address.");
	else {
		$.post('/signup', {'email':e.val()}, function(data, status) {
			if (data.success_message != '') {
				$('#throbber').replaceWith('<p class="h3">'+data.success_message+'</p>');
				$('#email').attr('disabled', 'disabled');
			} else if (data.error_message != '') 
				signup_error(data.error_message);
			}, 
			'json'
		);
	}
	mpmetrics.track_funnel('Signup', 2, "Signup");
}
$.preloadImages("/static/images/home/throbber.gif", "/static/images/close.gif");
