/*
 * AskRandom voodoo
 */
var AskRandom = {
    defaultQuestion: 'What might you wonder?'
};

/*
 * Load stuff
 */
$(document).ready(function(){   
    AskRandom.init();
});

/*
 * Start the randomness, baby!
 */
AskRandom.init = function()
{
    if (!Modernizr.input['placeholder']) {
        // No placeholder support, roll our own
        AskRandom.initPlaceholder();
    }
    
    if (!Modernizr.input['autofocus']) {
    	// No autofocus support, roll our own
    	$('input[autofocus]').each(function(){
    		$(this).focus();
    	})
    }
}

AskRandom.initPlaceholder = function() {
    $('input[placeholder]').each(function(){
        var p = $(this).attr('placeholder'),
        	v = $(this).val();
        
        if (!v || v == p) {
        	$(this).val(p).addClass('placeholder');
        }
        
        $(this).focus(AskRandom.placeholderFocus)
               .blur(AskRandom.placeholderBlur);
    });
    
    $('form').submit(function() {
    	//console.debug('SUBMIT!');
    	$('input[placeholder]', this).each(function() {
    		var p = $(this).attr('placeholder');
    		if ($(this).val() == p) {
    			// Clear value
    			$(this).val('');
    		}
    	});
    });
}

AskRandom.placeholderFocus = function()
{
    var p = $(this).attr('placeholder');
    if ($(this).val() == p) {
        $(this).val('').removeClass('placeholder');
    }
}

AskRandom.placeholderBlur = function()
{
	//console.debug("BLUR!");
    var p = $(this).attr('placeholder');
    if ($(this).val() == '') {
        $(this).val(p).addClass('placeholder');
    }
}
