function init_profile(){
	if ($('set_access_form')) {
		$('set_access_form').observe('submit',function(e) {
			e.stop();
			new Ajax.Request(base_url+'user/set_access', {
				postBody: $('set_access_form').serialize()+'&user='+$('username_headline').innerHTML,
				onCreate: function() {
					$('subbtn').hide();
				},
				onSuccess: function(res) {
					$('subbtn').show();
				}
			});
		});
	}
	$$('.fetcher').invoke('observe','click',fetch_comments).invoke('writeAttribute','title','fetches the latest comments live (closes other expanded comments)');
	var preferred = /\/(\d+)$/.exec(window.location);
	preferred = (!preferred) ? 0 : preferred[1];
	
	tab_switchers = $$('.filler h3 a');
	tab_content = $$('.user_tab').invoke('hide');

	//first time switch without effect:
	tab_content.invoke('hide')[preferred].show();
	switch_tab(preferred);
	
	var imgs = $$('ul.multipost li span img');
	imgs.each(function(e){
		e.up('li').setStyle({'clear':'both'});
	});
	
	$$('a[title="Remove"]').invoke('observe','click',function(e){
		var uid = e.findElement('li').readAttribute('id').substr(5);
		new Ajax.Request(base_url+'user/remove_friend',{
			postBody: 'uid='+uid,
			onCreate: function(){
				[$('uava_'+uid),$('urem_'+uid)].invoke('blindUp',{duration:0.5});			
			}
		});
	});
}

function switch_tab(x) {
	if ( !tab_content[x].visible() ) tab_content.invoke('hide')[x].appear({duration:0.4});
	tab_switchers.invoke('setOpacity',0.6)[x].setOpacity(1);
}

function toggle_entry(id) {
	$('text_'+id).toggle();
}

function fetch_comments(e) {
	e.stop();
	$$('fieldset').invoke('show');
	e.element().up('fieldset').hide();
	if ( $$('.fetched_comments').any() ) $$('.fetched_comments').invoke('remove');
	var eid = /\/(\d+)$/.exec(e.element())[1];
	new Ajax.Request(base_url+'user/get_comments', {
		postBody: 'eid='+eid,
		onCreate: function() {
			$('text_'+eid).insert('<div class="fetched_comments" id="comments_'+eid+'"></div>');
			$('comments_'+eid).update('<span class="loadingi"></span>');
		},
		onSuccess: function(res) {
			d=res.responseText;
			$('comments_'+eid).update(d);
			initiate_commenter();
		}
	});
}
