$(document).ready(function() {

    //  Try loading Typekit
    try {
        Typekit.load();
    } catch(e) {
        console.log(e);
    }
 	
 	//	To hide something, just use .hide();
 	$('div.views').hide();
 
	$('#textbox').focus().keypress(function() {
		//	Need to make sure we're not hitting enter
	 	if($(this).val() == 'views') {
			$('div.views').fadeIn(500);
		} else if($(this).val() == 'viewsoff') {
			$('div.views').fadeOut(500);
		}
	});
    
    $('#short').submit(function() {
        var url = $('#textbox').val();
        var msg = $('#message:first');
        
        console.log(url);
        
        $.post('url.php',
            {
                url: url
            }, function(data) { 
            if(data=='error: No url') {
                msg.html('<p>No URL specified</p>');
            } else if (data == 'error: Invalid url'){
                msg.html('<p>Invalid URL</p>');
            } else if (data == 'error: This is already one of our URL\'s we do not see a point in shortening this. '){
                //	Still, should return the current URL.
                msg.html('<p>Already a shortened URL</p>');
            } else {
                $('#textbox').val(data).select();				
                msg.html('<p>URL has been successfully shortened.</p>');
                console.log(data);
            }
        });
        
        return false;
    });
});
