function animateLogo(){
	$('.vowel').each(function(){
		$(this).fadeOut(3000,function(){
			$('.kern-r').css('letter-spacing','0.1em');
		});
	});
}

function strpos(haystack, needle) {
    var i = $.inArray(needle, haystack);
    return i === -1 ? false : i;
}

function substr_count(haystack, needle) {
	word_length = haystack.length;
	cnt = 0;
	for(i=0;i<word_length;i++){
		if(haystack.substr(i,1)==needle){
			cnt++;
		}
	}
 
    return cnt;
}

function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function abbr(str){
	
	var vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];
	var url_chars = ['www.'];
	var new_str = '';
	
	//This is the abbreviation dictionary to maintain
	var abbr_from_array = ['management','company','don\'t know','be','question','retweet','seriously','questions','what','tweet','very','something','would','ever','user','users','birthday','today','character','characters','when','tomorrow','really','money','after','three','five','six','seven','eight','nine','ten','heart','quick','image','at', 'into','before','anyone','one','someone','text','won', 'new', 'about','dollar','dollars','year', 'month','years','months','forward','favorite','facebook','two','to','too','are','our','your','you\'re','because','for','four','you','see','oh','regarding','going to','thank you','love','you\'ve','later','please','people','thanks','thank','with','google','street','state','government','michigan','governor','through','like','and','object','objects','point','points','ready','every','other','others','great','down', 'you all','you are','alternative','independent','cannot','doing'];
	var abbr_to_array = ['mgmt','co.','dunno','b','?','RT','srsly','?s','WTF','twt','vry','sumfin','wud','eva','usr','usrs','bday','2day','char','chars','whn','tmrw','rly','$','aftr','3','5','6','7','8','9','10','<3','quik','img','@','in2','b4','ne1','1','som1','txt','1','nu','abt','$','$s','yr','mo','yrs','mos','fwd','fav','FB','2','2','2','r','r','ur','ur','b/c','4','4','u','c','o','re:','gonna','thx','luv','u\'ve','l8r','plz','ppl','thx','thx','w/','gogl','st','st','gov','MI','gov','thru','lk','&','obj','objs','pt','pts','rdy','evry','othr','othrs','grt','dwn','yall','ur','alt','indie','can\'t','doin'];
	
	var word_array = str.split(' ');
	var new_word_array = Array();
	
	for(var i in word_array){
		var word = word_array[i];
		var next_key = parseInt(i) + 1;
		var prev_key = parseInt(i) - 1;
		
		//Ignore @replies and hashtags
		if(word.substr(0,1)=='@' || word.substr(0,1)=='#'){
			new_word_array.push(word);
			continue;
		}
		
		//Auto-bit.ly URLs if it's not already and if the next word is set
		if(word.substr(0,7)=='http://'){
			new_word_array.push(word);
			continue;
		}
		
		//Take the current and next word and try a abbr dictionary match
		if(word_array[next_key]){
			var next_word = word_array[next_key].replace(/[^a-z0-9’]/i, '');
			var this_word = word.replace(/[^a-z0-9’]/i, '');
			
			word_pair = this_word.toLowerCase()+' '+next_word.toLowerCase();
			var match = $.inArray(word_pair,abbr_from_array);
			if(match>=0){
				var punctuation = word_array[next_key].toLowerCase().replace(next_word,'');
				word = abbr_to_array[match] + punctuation;
				new_word_array.push(word);
				delete word_array[next_key];
				continue;
			}
		}
		
		//check for abbreviation
    	var match = $.inArray(word.toLowerCase(),abbr_from_array);
		if(match>=0){
			word = abbr_to_array[match];
			new_word_array.push(word);
			continue;
		}
		
		//Strip remaining punctuation
		word = word.replace(/[^a-z0-9’]/i, '');
		var punctuation = word_array[i].replace(word,'');
		
		//check for abbreviation again, without punctuation
    	var match = $.inArray(word.toLowerCase(),abbr_from_array);
		if(match>=0){
			word = abbr_to_array[match] + punctuation;
			new_word_array.push(word);
			continue;
		}
		
		var word_length = word.length;
		var vowel_count = 0;
		var leading_vowel = false;
		
		//Count the vowels in the word
		for(var j in vowels){
			var vowel = vowels[j];
			if(strpos(word,vowel)===0){
				leading_vowel = vowel;
			}
			vowel_count += substr_count(word,vowel);
		}
		var differential = word_length - vowel_count;
		
		//Replace endings
		word = word.replace('er','r');
		word = word.replace('ed','d');
		
		//Exceptions to stripping out vowels
		if(word_length<4){ //3 letter words or fewer
			new_word_array.push(word_array[i]);
			continue;
		}
		if(word_length==4 && vowel_count>1){ //4 letter words with more than 1 vowel
			new_word_array.push(word_array[i]);
			continue;
		}
		if(differential<4){ //Words larger than 4 letters containing a large ratio of vowels
			new_word_array.push(word_array[i]);
			continue;
		}
		
		//***Check for 3+ vowels
		//create an array of every character in our word
		char_array = new Array();
		vowel_str = '';
		for(j=0;j<word_length;j++){
			char_array.push(word.substr(j,1));
		}
		for(var j in char_array){
			var character = char_array[j];
			var next_key = parseInt(j) + 1;
			var next_next_key = parseInt(j) + 2;
			
			var match = $.inArray(character,vowels);
			if(match>=0){
				//We found a vowel. Look at the next 2 chars. If they're vowels, capture the string.
				if(char_array[next_next_key]){
					var next_match = $.inArray(char_array[next_key],vowels);
					var next_next_match = $.inArray(char_array[next_next_key],vowels);
					if(next_match>=0 && next_next_match>=0){
						//got 'em. protect 'em
						vowel_str = character+char_array[next_key]+char_array[next_next_key];
					}
				}
			}
		}
		
		if(vowel_str!=''){
			var temp_word_array = word.split(vowel_str);
			for(var j in temp_word_array){
				temp_word_array[j] = str_replace(vowels,'',temp_word_array[j]);
			}
			word = temp_word_array.join(vowel_str) + punctuation;
			new_word_array.push(word);
			continue;
		}
		
		if(leading_vowel){ //Words starting with a vowel
 			word_array[i] = leading_vowel + str_replace(vowels,'',word_array[i].substr(1));
		} else {
 			word_array[i] = str_replace(vowels,'',word_array[i]);
		}
		
		word = word_array[i];
		
		new_word_array.push(word);
		
	}
	
	new_str = new_word_array.join(' ');
	
	return new_str;
	
}

function bitlyAJAX(url){
	post = 'url='+url;
	$.ajax({
		type: "POST",
		url: "http://localhost/brfly/bitly.php",
		data: post,
		success: function(msg){
			return msg;
		}
	});
}

function sendTweet(){
	str = escape($("#output").text());
	tweet = str.replace(/%20/gi,'+');
	url = 'http://twitter.com/home?status='+tweet;
	window.location = url;
}