$(document).ready(function(){
    
    $('#feedback').click(function(e){
        e.preventDefault();
        $('#tender_toggler a').click();
    });

	$('#email-signup #signup-button').click(function(e){
		e.preventDefault();
		$.ajax({
			url : '/email/add',
			data : {name:$('input#name').val(), email:$('input#email').val()},
			success : function(msg) {
				$('#email-form').fadeOut('fast', function(){
					if(msg == 'true') {
						$('#email-thanks').fadeIn();
					} else {
					
						$('#email-error #error-yes').click(function(e){
							e.preventDefault();
							$('#email-error').fadeOut('fast', function(){
								$('#email-form').fadeIn('fast');
							});
						});
						
						$('#email-error #error-no').click(function(e){
							e.preventDefault();
							window.location = 'http://mlb.mlb.com/video/play.jsp?content_id=12092851&topic_id=8806612&c_id=tb';
						});
						
						
						$('#email-error').fadeIn();
					}
				});
			}
		});
	});
	
	$('label[for]').each(function(){
        var labelText = $(this).html();
        var input = $('input#' + $(this).attr('for'));
        
        if(input.attr('type') == 'password') {
            var fakeInput = $('<div class="input text"><input class="input-default-text" type="text" value="'+ labelText +'"/></div>');
            input.parent().after(fakeInput);
            input.hide();
            fakeInput.find('input').focus(function(e){
                fakeInput.hide();
                input.show().focus();
            });
            
        } else {
            input.attr('title', labelText)
	       	if(input.val() == labelText) {
                input.addClass('input-default-text');
    		}
    		
    		input.focus(function(){
    		  if ($(this).val() == $(this)[0].title) {
                    $(this).removeClass("input-default-text");
                    $(this).val("");
                }
    		});
        }
        
        input.blur(function(){
            if($(this).val() == "") {
                if($(this).attr('type') == 'password') {
                    input.hide();
                    fakeInput.show();      
                } else {
                    $(this).addClass("input-default-text");
                    $(this).val($(this)[0].title);
                }              
            }
        });
    
		$(this).hide();
	});


    
    $("input[title]").blur();    
	
});
