/* SPARKART */
/* Comments Javascript Functions
----------------------------------------------------------------------------- */


	function loadComments() {
	

/* ELEMENT MOVES / REWORDING
----------------------------------------------------------------------------- */


	$('ul.comments > li').each(function() {
	
		$(this).children('div.post').children('strong').children('span').remove();

		var timestamp = $(this).children('div.post').children('strong').text();
		var timestamp = timestamp.replace('Posted ','');
		var timestamp = timestamp.split('(');
		var timestamp = timestamp[0];
		
		var insertion = $(this).children('div.member');
		
		$(this).children('div.post').children('strong').remove();
		$('<strong>' + timestamp + '</strong>').appendTo(insertion);
				
		if ($(this).children('div.member').children('a.alias').text() == alias) {
			$(this).addClass('self');
		}
		
		var insertion = $(this).children('div.post');
		
		$(this).children('div.post').children('ul.actions').appendTo(insertion);
	
	});
		
	$('ul.comments').css('visibility','visible');


/* PROFILE PICTURE UPLOADER
----------------------------------------------------------------------------- */


	$('ul.comments li.self a.picture').click(function() {
	
		var position = $(this).position();	
		var left = position.left - 13;
		var top = position.top - 13;

		$('div.widget-profile').css('top', top + 'px').css('left', left + 'px');
		$('div.widget-profile').fadeIn();

		return false;
	
	});

	$('<a class="action replace" href="#">Replace Picture</a>').appendTo('div.widget-profile label');
	$('<a class="action cancel" href="#">Cancel</a>').appendTo('div.widget-profile label');

	$('div.widget-profile a.cancel').click(function() {
	
		$('div.widget-profile').fadeOut();
		return false;
	
	});

	/* Why is the submit button named submit - needed? */

	$('div.widget-profile input[type=file]').each(function() {
	
		$(this).attr('size','1');		

	});

	$('div.widget-profile input[type=file]').change(function() {
		
		$('div.widget-profile #user_alias').val(alias);		
		$('div.widget-profile').parent().ajaxForm();
		$('div.widget-profile').parent().ajaxSubmit(function() {
		
			setTimeout(function() {

				$('div.widget-profile div').load('/picture');
				var picture = $('div.widget-profile img').attr('src');

				$('ul.comments li.self div.member img').remove();
				$('div.widget-profile div img').clone().appendTo('ul.comments li.self div.member a.picture');

			}, 2000);

			$('div.widget-profile').fadeOut();

		});

	});


/* END FUNCTION
----------------------------------------------------------------------------- */


	}
