$(document).ready(function(){
		
		// Check to see if user is certified // Change background
		
		 $("#draggable").draggable();
		 
		   $(".profile_img").live("mouseover", function() { 
		   	$(this).draggable({
			    opacity: 1,
			    helper: 'clone',
			    start: function(event, ui) { },
			    stop: function(event, ui) {  }
			  });
			  
			   $(".droppable").droppable({
			   		hoverClass: 'drophover',
			      drop: function(event, ui) { 
			      	$(this).fadeOut('slow');
			      	$(this).html('<img src="/images/ajax-loader.gif" align="center" width="20%"/>');
			      	$(this).fadeIn();
			      	
			      	user_id = $('#user_id').html();
			      	user_name = $('#act_user_name').html();

			      	// Unfollow action //
			      	if($(this).attr('id') == 'act_unfollow')
			      	{
			      		$.post("user/action/unfollow", { user_id: user_id},
						   function(data){
						     	$('#act_unfollow').html('<img src="/images/icons/user_add.png"> Follow User');
						     	$('#act_unfollow').attr('id','act_follow');
						     	$.jGrowl("Yeah! You unfollowed "+user_name+".", { header: 'TwitChuck Says:', life: 5000 });
						   });
			      	} 
			      	else if($(this).attr('id') == 'act_follow')
			      	{
			      		$.post("user/action/follow", { user_id: user_id},
						   function(data){
						   		$('#profile_header_bar').prepend('<span id="you-follow">You Follow</span>');
						   		$('#act_follow').html('<img src="/images/icons/user_delete.png"> Unfollow User');
						     	$('#act_follow').attr('id','act_unfollow');
						     	// Growl functionality
								$.jGrowl("Congrats! You followed "+user_name+".", { header: 'TwitChuck Says:', life: 5000 });

						   });
			      	}
			      	else if($(this).attr('id') == 'act_block')
			      	{
			      		$.post("user/action/block_user", { user_id: user_id},
						   function(data){
						   		$('#act_block').html('<img src="/images/icons/user_delete.png"> Unblock User');
						     	$('#act_block').attr('id','act_unblock');
						     	$.jGrowl("Alright! You blocked "+user_name+".", { header: 'TwitChuck Says:', life: 5000 });
						   });
			      	}
			      	else if($(this).attr('id') == 'act_unblock')
			      	{
			      		$.post("user/action/unblock_user", { user_id: user_id},
						   function(data){
						   		$('#act_unblock').html('<img src="/images/icons/user_delete.png"> Block User');
						     	$('#act_unblock').attr('id','act_block');
						     	$.jGrowl("No bitterness, you unblocked "+user_name+".", { header: 'TwitChuck Says:', life: 5000 });
						   });
			      	}
			      }
			    });
			    
			  });

			
			 
		 
});

$(document).ready(function(){
		
		user = jQuery.url.segment(0);

			if($('#profile_wrapper').length == 1)
			{	
				$('#user_search').hide();
				$('#profile_wrapper').html('<div style="margin:30px auto 0 auto; text-align:center; font-size:20px">Figuring Out '+user+'<br/><br/><img src="/images/ajax-loader.gif" align="center" width="10%"/></div>');

				
				$.get("/get_profile/"+user, function(data){
					  $('#user_search').fadeIn('slow');
					  $('#profile_wrapper').html(data);
					  if(document.getElementById('cert_fresh'))
						{
							$('body').css({'background-image':'url(/images/background-fresh.jpg)'});
						}
						else if(document.getElementById('cert_spammer'))
						{
							$('body').css({'background-image':'url(/images/background-spammer.jpg)'});
						}
					  	
					});
							
			}
					
		$('#u_name').click(function(){
		
			if($(this).val() == 'Twitter Username'){
					$(this).val('');
			}
		});
		
		//$("#pb2").progressBar({ barImage: '/images/progressbg_yellow.gif'} );
		
		// Friend list cleaner
		$('#start_list').click(function(){
				
				$('#start_list').fadeOut();
				
				$('#profile_wrapper_1_mg').append('<div class="error_msg">We have begun your friend search. This can take up to 10 minutes to complete. Sorry!</div>');
				
				var increment = 0;
				
				var lpOnComplete = function(response) {
					if(response == 'dead')
					{
						alert('dead');
						return;
					}
					$('#profile_wrapper_1').prepend(response).fadeIn();
					// do more processing
					lpStart();
				};
				
				var lpStart = function() {
					$.post('/test/function/friend_list', {page:increment}, lpOnComplete);
					increment++;
				};
				
				lpStart();
			
		});
		

});
