//Страница пользователя
$(document).ready(function() {
	//Проголосовать за красивые глазки, или за сиськи... сути не меняет - это пиндовато!!!
	$('#msgToUser').click(function (e) {
		e.preventDefault();
		user_id=$(this).attr('rel');
		if(auth_u_id!='{auth_u_id}' && auth_u_id!=user_id) {
			$('#basicModal').modal({
				onShow:function(){sendMessages('getForm');},
				containerCss:{height:'220px'}
			});
		}
		else if(auth_u_id!='{auth_u_id}' && auth_u_id==user_id && typeof(layoutUsersPage)=='function') layoutUsersPage('mail','toSelf');
		else if(auth_u_id=='{auth_u_id}' && typeof(layoutUsersPage)=='function') layoutUsersPage('mail','unAuth');
	});
	$('#u_plus').click(function() {
		//$('#hiddenFrame').attr('src','/lib/voter.php?obj='+vote_obj+'&vote='+$(this).attr('rel'));
		//alert('/lib/voter.php?obj='+vote_obj+'&vote='+$(this).attr('rel'));
		layoutUsersPage('vote','obj='+vote_obj+'&vote='+$(this).attr('rel'));
		return false;
	});
	$('#u_addFriend').click(function() {
		layoutUsersPage('friend',$(this).attr('rel'),$(this).attr('send'));
		return false;
	});
	//var tmp='';
	$('.track > p > a').each(function(){
		tmp=''+this;
		if(tmp.search('tracks')>0)$('#lnk_tracks').show();
		if(tmp.search('mixes')>0) $('#lnk_mixes').show();
	});
	//alert(tmp);
});

var timeOutBubble;
function layoutUsersPage(action,value,send) {
	//action => {vote, friend, send_friend, mail?}
	send=send || 0;
	clearTimeout(timeOutBubble);
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if(req.responseJS) {
				if(req.responseJS.answer && req.responseJS['class']) {
					var obj=$(document.getElementById("volumer"));
					var bt=document.getElementById("bubble");
					if(bt!=undefined){ $(bt).fadeIn("slow"); $(bt).addClass("plus")}
					obj.html(req.responseJS.answer);
					obj.attr('class',req.responseJS['class']);
					$("#bubble").css("backgroundPosition",req.responseJS.backPosition+"px 0px");
					timeOutBubble=setTimeout('$("#bubble").fadeOut("slow")', 10000);
					if(req.responseJS.run_previewMessages && req.responseJS.run_previewMessages==1) {
						previewMessages([0,0]);
					}
					if(req.responseJS.send && req.responseJS.send==1){
						$('#u_addFriend').parent().get(0).className='u-vote';
						$('#u_addFriend').attr('send',0);
						$('#u_addFriend').attr('title','');
					}
					if(req.responseJS.send && req.responseJS.send==0){
						$('#u_addFriend').parent().get(0).className='u-unvote';
						$('#u_addFriend').attr('send',1);
						$('#u_addFriend').attr('title','');
					}
				}
			}
			if(req.responseText!='') alert(req.responseText);
	    }
	}
	req.open(null, '/lib/voter.php', true);
	req.send( { q: value,
				action: action,
				send: send } );
}
