    <?php if ($D->is_my_profile) {?>
    
    <div id="areabfriend">
    	<div id="bteditprofile" class="bfriendly hand"><?php echo $this->lang('profile_areafollow_editprofile'); ?></div>
    </div>

    <script>
        $('#bteditprofile').click(function(){
            location.href = siteurl + "dashboard/configuration";
        });
    </script>            
    
    <?php } else { ?>
    
    <div id="areabfriend">
        <div id="bactionfriend" class="<?php echo(($D->friendship==0 || $D->friendship==1)?'bfriendly2':'bfriendly')?>" <?php if ($D->friendship==1) { ?> style="background-image:url(<?php echo $C->SITE_URL.'themes/'.$C->THEME.'/imgs/ico-check-black.png'?>); background-repeat:no-repeat; background-position:7px 8px;"<?php } ?>>
        <?php
        if ($D->friendship==0) echo($this->lang('profile_areafriends_addfriend'));
        if ($D->friendship==1) { echo('&nbsp;&nbsp;&nbsp;'.$this->lang('profile_areafriends_friends')); }
        if ($D->friendship==2) echo($this->lang('profile_areafriends_requestsent'));
        if ($D->friendship==3) echo($this->lang('profile_areafriends_respondrequest'));
        ?>
        </div>
        <div id="preload-friend" class="hide"><img src="<?php echo $C->SITE_URL?>themes/<?php echo $C->THEME?>/imgs/loading.gif"></div>
        <input name="friendship" type="hidden" id="friendship" value="<?php echo $D->friendship?>">
        <div id="smn1" class="boxsubmenu hide">
            <div id="opc-unfriend" class="opcsm"><?php echo $this->lang('profile_areafriends_unfriend');?></div>
        </div>
    
        <div id="smn2" class="boxsubmenu hide">
            <div id="opc-cancelrequest" class="opcsm"><?php echo $this->lang('profile_areafriends_cancelrequest');?></div>
        </div>
    
        <div id="smn3" class="boxsubmenu hide">
            <div id="opc-confirmrequest" class="opcsm"><?php echo $this->lang('profile_areafriends_confirmrequest');?></div>
            <div id="opc-deleterequest" class="opcsm"><?php echo $this->lang('profile_areafriends_deleterequest');?></div>
        </div>
	</div>

   	<?php if ($D->is_logged) { ?>

    <script>
	var dsm1, dsm2;
	var msg_norequest = '<?php echo $this->lang('dashboard_no_request')?>';
	var uidprofile = <?php echo $D->u->iduser; ?>;
	
	$('#bactionfriend').mouseover(function(){
		if ($('#friendship').val() != 0) {
			$('#bactionfriend').css('cursor','default');
			$('#bactionfriend').css('background-color','#6D84B4');
			$('#bactionfriend').css('color','#FFF');
			
			if ($('#friendship').val() == 1) {
				$('#bactionfriend').css('background-image','url(<?php echo $C->SITE_URL.'themes/'.$C->THEME.'/imgs/ico-check-white.png'?>)');
				$('#bactionfriend').css('background-repeat','no-repeat');
				$('#bactionfriend').css('background-position','7px 8px');
			}
			
		} else {
			$('#bactionfriend').css('cursor','pointer');
		}
		
		if ($('#friendship').val() != 0) {
			showSmn('#smn' + $('#friendship').val());
		}

	});
	
	$('#bactionfriend').mouseleave(function(){
		
		if ($('#friendship').val() != 0) {
			
			hideSmn('#smn' + $('#friendship').val());
		
		}
	});
	
	function keepSmnVisible() {
		clearInterval(dsm2);
	}
	
	function hideSmn(submenu) {
		clearInterval(dsm1);
		dsm2 = setInterval(function() {
			if ($('#friendship').val() != 0) {
				$('#bactionfriend').css('cursor','default');
				$('#bactionfriend').css('background-color','#F3F4F6');
				$('#bactionfriend').css('color','#333');
				
				if ($('#friendship').val() == 1) {
					$('#bactionfriend').css('background-image','url(<?php echo $C->SITE_URL.'themes/'.$C->THEME.'/imgs/ico-check-black.png'?>)');
					$('#bactionfriend').css('background-repeat','no-repeat');
					$('#bactionfriend').css('background-position','7px 8px');
				}
			} else {
				$('#bactionfriend').css('cursor','default');
			}
			$(submenu).hide();
			clearInterval(dsm2);	
		},200);
	}
	
	function hideSmnFast(submenu, value) {
		clearInterval(dsm1);
		clearInterval(dsm2);
		if ($('#friendship').val() != 0) {
			$('#bactionfriend').css('cursor','default');
			$('#bactionfriend').css('background-color','#F3F4F6');
			$('#bactionfriend').css('color','#333');
		} else {
			$('#bactionfriend').css('cursor','default');
		}
		$(submenu).hide();
		$('#friendship').val(value);
	}
	
	function showSmn(submenu) {
		clearInterval(dsm2);
		dsm1 = setInterval(function() {
			$(submenu).show();
		},50);
	}
	
	$('#smn1, #smn2, #smn3').mouseover(function() {
		keepSmnVisible();
	});

	$('#smn1').mouseleave(function() {
		hideSmn('#smn1');
	});

	$('#smn2').mouseleave(function() {
		hideSmn('#smn2');
	});

	$('#smn3').mouseleave(function() {
		hideSmn('#smn3');
	});
	
	//////////////////////////////
	//Action CANCEL
	$('#opc-cancelrequest').click(function(){

		$('#bactionfriend').hide();
		$('#preload-friend').show();
		
		$.ajax({
			type: 'POST',
			url: siteurl + "ajax/friends-actions/r:" + Math.round(Math.random()*1000),
			data: 'todo=3&uid=' + uidprofile,
			success: function(resp){
				switch(resp.charAt(0)){
					case '0':
						alert(resp.substring(3));
						break;
					case '1':
						hideSmnFast('#smn2',0);
						$('#bactionfriend').html('<?php echo $this->lang('profile_areafriends_addfriend')?>');
						break;
					}
			},
			error: function(){
				alert(msg_norequest);
			} //end error
		}); // end ajax	
		
		$('#bactionfriend').show();
		$('#preload-friend').hide();			

		return false;
	});

	//////////////////////////////	
	//action DELETE REQUEST
	$('#opc-deleterequest').click(function(){
		
		$('#bactionfriend').hide();
		$('#preload-friend').show();
		
		$.ajax({
			type: 'POST',
			url: siteurl + "ajax/friends-actions/r:" + Math.round(Math.random()*1000),
			data: 'todo=2&uid=' + uidprofile,
			success: function(resp){
				switch(resp.charAt(0)){
					case '0':
						alert(resp.substring(3));
						break;
					case '1':
						hideSmnFast('#smn3',0);
						$('#bactionfriend').html('<?php echo $this->lang('profile_areafriends_addfriend')?>');
						break;
					}
			},
			error: function(){
				alert(msg_norequest);
			} //end error
		}); // end ajax	
		
		$('#bactionfriend').show();
		$('#preload-friend').hide();			

		return false;
	});
	
	//////////////////////////////	
	//action CONFIRM REQUEST
	var showprofile = <?php echo $D->show_profile?>;
	$('#opc-confirmrequest').click(function(){
		
		$('#bactionfriend').hide();
		$('#preload-friend').show();
		
		$.ajax({
			type: 'POST',
			url: siteurl + "ajax/friends-actions/r:" + Math.round(Math.random()*1000),
			data: 'todo=4&uid=' + uidprofile,
			success: function(resp){ 
				switch(resp.charAt(0)){
					case '0':
						alert(resp.substring(3));
						break;
					case '1':
						hideSmnFast('#smn3',1);
						$('#bactionfriend').html('&nbsp;&nbsp;&nbsp;<?php echo $this->lang('profile_areafriends_friends')?>');
						$('#numfriends').html(parseInt($('#numfriends').html()) + 1);
						if (showprofile==0) self.location = self.location;
						break;
					}
			},
			error: function(){
				alert(msg_norequest);
			} //end error
		}); // end ajax	
		
		$('#bactionfriend').show();
		$('#preload-friend').hide();
		
		return false;
	});
	
	$('#opc-unfriend').click(function(){		
		
		$('#bactionfriend').hide();
		$('#preload-friend').show();
		
		$.ajax({
			type: 'POST',
			url: siteurl + "ajax/friends-actions/r:" + Math.round(Math.random()*1000),
			data: 'todo=5&uid=' + uidprofile,
			success: function(resp){ 
				switch(resp.charAt(0)){
					case '0':
						alert(resp.substring(3));
						break;
					case '1':
						$('#spaceFollow').hide();
						hideSmnFast('#smn1',0);
						$('#bactionfriend').html('<?php echo $this->lang('profile_areafriends_addfriend')?>');
						$('#numfriends').html(parseInt($('#numfriends').html()) - 1);
						break;
					}
			},
			error: function(){
				alert(msg_norequest);
			} //end error
		}); // end ajax	
		
		$('#bactionfriend').show();
		$('#preload-friend').hide();
		
		return false;
	});
	
	//////////////////////////////
	// action SENT REQUEST FRIEND
	$('#bactionfriend').click(function(){

		if ($('#friendship').val() == 0) {
			
			$('#bactionfriend').hide();
			$('#preload-friend').show();
			
			$.ajax({
				type: 'POST',
				url: siteurl + "ajax/friends-actions/r:" + Math.round(Math.random()*1000),
				data: 'todo=1&uid=' + uidprofile,
				success: function(resp){
					switch(resp.charAt(0)){
						case '0':
							alert(resp.substring(3));
							break;
						case '1':
							$('#bactionfriend').html('<?php echo $this->lang('profile_areafriends_requestsent')?>');
							$('#friendship').val(2);
							break;
						}
				},
				error: function(){
					alert(msg_norequest);

				} //end error
			}); // end ajax	
			
			$('#bactionfriend').show();
			$('#preload-friend').hide();			
			return false;
		}
		
	});
	
	</script>

	<?php } else { ?>

    <div id="msgnotloggedin" class="hide">
		<div class="only-redbox"><?php echo $this->lang('profile_areafollow_youmustbe');?> <span class="linkblue"><a href="<?php echo $C->SITE_URL?>"><?php echo $this->lang('profile_areafollow_signed');?></a></span>.</div>
    </div>

	<script> 
	
	$('#bactionfriend').mouseover(function(){
		if ($('#friendship').val() == 0) {
			$('#bactionfriend').css('cursor','pointer');
		}
	});
	
	$('#bactionfriend').one('click',function(){
	
		$("#areabfriend").fadeOut("slow",function(){
			$("#areabfriend").hide(function(){
				$("#msgnotloggedin").fadeIn('slow');
			});
		});			
	
	});  
	</script>
	
	<?php } //end isloged ?>
    

	<?php } // end is my profile ?>
