 $(document).ready(function(){
    $('a.email_top').nospam({
      replaceText: false,    // BOOLEAN, optional default false. If set to true, replaces matched elements' text with the e-mail address
      filterLevel: 'normal' // STRING, optional accepts 'low' or 'normal', default 'normal'.
                            // low: email/domain/tld
                            // normal: dlt/niamod/liame (email/domain/tld reversed)
    });
  });
 
 $(document).ready(function(){
$("img.rollover").hover(
						
function () { this.src = this.src.replace("_","_h");
},

function () { this.src = this.src.replace("_h","_");

});
});
 
 
 
 $(document).ready(function(){
	$('#wordPopularity').bind('click', wordPopularity);
	$('#followusername').bind('keydown', function(e){
		if (e.keyCode == 13) {
			wordPopularity();
		}
	});
});

var flagWord = function (e, word) {	
	$.ajax({
		type: 'POST',
		url:  'ajax.php',
		dataType: 'json',
		word: word,
		element: e,
		
		data: {
			method: 'flagWord',
			word: word
		},
		
		success: function(json)
		{
			var curentWord = userWords.pop();
			var html = ' <span class="flag flag_' + curentWord.word + '" onclick="flagWord(this, \'' + curentWord.word + '\')" title="Remove and mark as not descriptive" style="display: none; cursor: pointer;">' + curentWord.word + '</span> ';
			$('#words .user_words').append(html);
			$("#words .user_words span.flag_" + curentWord.word).fadeIn("slow");
		},
		beforeSend: function() {
			$(this.element).fadeOut("slow");
			$("#words .user_words span.flag_" + word).fadeOut("slow");
		}
	});
}

var followUser = function (username) {
	// insert lightbox magic
};

var userWords;

var wordPopularity = function () {
	$.ajax({
		type: 'POST',
		url:  'ajax.php',
		dataType: 'json',
		username: $('#followusername').val(),
		
		data: {
			method: 'wordPopularity',
			username: $('#followusername').val()
		},
		
		success: function(words)
		{
			if (typeof words.error != 'undefined') {
				var text = words.error;
			} else {
				userWords = words.reverse();
			
				var text = '<div class="content_ajax_right"><div class="step3_button"><a href="follow.php?user=' + this.username + '&KeepThis=true&TB_iframe=true&height=180&width=417" class="thickbox"><img src="images/follow_button_.gif" alt="Follow button" width="350" height="78" border="0" /></a></div><div class="step3"><div class="step3_user"><a href="http://www.twitter.com/' + this.username + ' ">@' + this.username + '</a><img src="images/user.gif" alt="user tweets about" width="201" /><div class="clear"></div></div><div class="user_words">';
				for (var i = 0, len = userWords.length<10?userWords.length:10; i < len; i++) {
					var curentWord = userWords.pop();
					text += ' <span class="flag flag_' + curentWord.word + '" onclick="flagWord(this, \'' + curentWord.word + '\')" title="Remove and mark as not descriptive" style="cursor: pointer;">' + curentWord.word + '</span> ';
				}
				
				text += '</div></div><div class="step3_bottom"></div></div>';
				
				//text += '<p><input type="button" onclick="followUser(\'' + this.username + '\')" value="follow ' + this.username + '" /></p>';
				
			}
			$('#words').html(text);	
			tb_reinit('a.thickbox');

			

		},
		
		beforeSend: function(){
			$('#followusername, #wordPopularity').attr('disabled', true);
			$('#words').html('<div class="loader"><img src="images/ajax-loader.gif" alt="loader" width="220" height="19" /></div>');
		},
		complete: function(){
			$('#followusername, #wordPopularity').removeAttr('disabled');
		}
	});
	return false;
};