$(document).ready(
	function() {
		$('.title a.mediaTitle, .boxComment .cover a').tooltip({ bodyHandler: function() { return 'Loading...'; }, showURL: false, fade: 250, delay: 150 });	
		
		$('.title a.mediaTitle, .boxComment .cover a').hoverIntent({
				sensitivity: 3, 
				interval: 400, 
				over: getMedia, 
				timeout: 500, 
				out: out
			});

		
		function getMedia() {
			$('#tooltip .body').html('Loading...');
			$.ajax({
				type: "POST",
				url: "/ajax/showMediaBox",
				data: "mediaId="+$(this).siblings("input[name='id']").val(),
				success: function(msg){
					$('#tooltip .body').html(msg);
				}
			});
		}
		
		function out() {	
		}
		
		function follow(that) {
			//$.growl('Obserwujesz', 'Zapisuję...');

			coid = that.siblings('input[type:hidden]').val();
			$.ajax({
				type: "POST",
				url: "/ajax/followUser",
				data: "user="+coid,
				success: function(msg){
					that.replaceWith('<a href="#" class="buttonSmall buttonDoNotFollow"><span>Nie obserwuj</span></a>');
					$('.buttonDoNotFollow').bind("click", function() { doNotFollow($(this)); return false; });
					$.growl('Obserwujesz', 'Zapisano');
				}
			});
			return false;
		}

		function doNotFollow(that) {
			//$.growl('Nie obserwujesz', 'Zapisuję...');

			coid = that.siblings('input[type:hidden]').val();
			$.ajax({
				type: "POST",
				url: "/ajax/doNotFollowUser",
				data: "user="+coid,
				success: function(msg){
					that.replaceWith('<a href="#" class="buttonSmall buttonFollow"><span>Obserwuj</span></a>');
					$('.buttonFollow').bind("click", function() { follow($(this)); return false; });
					$.growl('Nie obserwujesz', 'Zapisano');
				}
			
			});
			return false;
		}
		
		$('.buttonFollow').bind("click", function() { follow($(this)); return false; });
		$('.buttonDoNotFollow').bind("click", function() { doNotFollow($(this)); return false; });
		
	});