
	
	//Click event on Chat Panel and Alert Panel	
	if( $( "alert-link" ) )
	{
		$( "alert-link" ).observe( "click", function(e) {
				Event.stop(e);
				
				if( $("alertpanel").down(".subpanel").visible() ) { //If subpanel is already active...
	
					$("alertpanel").down(".subpanel").hide(); //Hide active subpanel
					$$("#footpanel li a").each( function(elem) {
						$(elem).removeClassName('active'); //Remove active class on the subpanel trigger
					});
				}
				else { //if subpanel is not active...
	
					$$(".subpanel").each( function(elem) {
						$(elem).hide(); //Hide all subpanels
					});
					
					$("alertpanel").down(".subpanel").toggle(); //Toggle the subpanel to make active
					
					$$("#footpanel li a").each( function(elem) {
						$(elem).removeClassName('active'); //Remove active class on all subpanel trigger
					});
					
					$("alertpanel").toggleClassName('active'); //Toggle the active class on the subpanel trigger
				}
				
				return false; //Prevent browser jump to link anchor
		});
	}
	
	var hasRetrievedFavs	= false;
	
	//Click event on Chat Panel and Alert Panel	
	$( "favorites-link" ).observe( "click", function(e) {
			Event.stop(e);
			
			if( $("favoritepanel").down(".subpanel").visible() ) { //If subpanel is already active...

				$("favoritepanel").down(".subpanel").hide(); //Hide active subpanel
				$$("#footpanel li a").each( function(elem) {
					$(elem).removeClassName('active'); //Remove active class on the subpanel trigger
				});
			}
			else { //if subpanel is not active...

				$$(".subpanel").each( function(elem) {
					$(elem).hide(); //Hide all subpanels
				});
				
				$("favoritepanel").down(".subpanel").toggle(); //Toggle the subpanel to make active
				
				$$("#footpanel li a").each( function(elem) {
					$(elem).removeClassName('active'); //Remove active class on all subpanel trigger
				});
				
				$("favoritepanel").toggleClassName('active'); //Toggle the active class on the subpanel trigger
				
				//-----------------------------------------
				// First time, get the data
				//-----------------------------------------
				
				if( !hasRetrievedFavs )
				{
					var url = ipb.vars['base_url'] + 'app=bottombar&module=ajax&section=favorites&do=list&md5check=' + ipb.vars['secure_hash'];
					
					new Ajax.Request(	url,
										{
											method: 'get',
											onSuccess: function(t)
											{
												hasRetrievedFavs	= true;
												$("favorites-bb").insert( { bottom: t.responseText } );
											}
										}
									);
				}
			}
			
			return false; //Prevent browser jump to link anchor
	});
	
	$( "add-favorite-link" ).observe( "click", function(e) {
		Event.stop(e);
		
		var pagetitle	= document.title;
		var pageurl		= location.href;
		
		var url = ipb.vars['base_url'] + 'app=bottombar&module=ajax&section=favorites&do=add&md5check=' + ipb.vars['secure_hash'];
		
		new Ajax.Request(	url,
							{
								method: 'post',
								evalJSON: 'force',
								parameters: {
									title:		pagetitle,
									url:		pageurl
								},
								onSuccess: function(t)
								{
									if( t.responseJSON['error'] )
									{
										alert( t.responseJSON['error'] );
									}
									else
									{
										//alert( t.responseJSON['message'] );
										
										$$("li.center").each( function(elem){
											$(elem).remove();
										});

										$("favorites-bb").insert( { bottom: t.responseJSON['html'] } );
									}
								}
							}
						);
		
		return false; //Prevent browser jump to link anchor
	});


	
	var hasRetrieved	= false;
	
	//Click event on Chat Panel and Alert Panel	
	$( "pm-link" ).observe( "click", function(e) {
			Event.stop(e);
			
			if( $("pmpanel").down(".subpanel").visible() ) { //If subpanel is already active...

				$("pmpanel").down(".subpanel").hide(); //Hide active subpanel
				$$("#footpanel li a").each( function(elem) {
					$(elem).removeClassName('active'); //Remove active class on the subpanel trigger
				});
			}
			else { //if subpanel is not active...

				$$(".subpanel").each( function(elem) {
					$(elem).hide(); //Hide all subpanels
				});
				
				$("pmpanel").down(".subpanel").toggle(); //Toggle the subpanel to make active
				
				$$("#footpanel li a").each( function(elem) {
					$(elem).removeClassName('active'); //Remove active class on all subpanel trigger
				});
				
				$("pmpanel").toggleClassName('active'); //Toggle the active class on the subpanel trigger
				
				//-----------------------------------------
				// First time, get the data
				//-----------------------------------------
				
				if( !hasRetrieved )
				{
					var url = ipb.vars['base_url'] + 'app=bottombar&module=ajax&section=messages&md5check=' + ipb.vars['secure_hash'];
					
					new Ajax.Request(	url,
										{
											method: 'get',
											onSuccess: function(t)
											{
												hasRetrieved	= true;
												$("private-message-list-bb").insert( { bottom: t.responseText } );
											}
										}
									);
				}
			}
			
			return false; //Prevent browser jump to link anchor
	});
	
	
	//Click event outside of subpanel
	$("ipbwrapper").observe( "click", function(e) {
		$$('.subpanel').invoke('hide');
		
		$$("#footpanel li a").each( function(elem) {
			$(elem).removeClassName('active'); //Remove active class on all subpanel trigger
		});
	});

	$$('.subpanel ul').each( function(elem) {
		$(elem).observe( "click", function(e) {
			// This is bugged
			var anc = Event.findElement( e, 'a' );
			
			if( anc == undefined )
			{
				Event.stop(e);
			}
			else if( $(anc).hasClassName( "delete" ) )
			{
				var favid	= $(anc).rel;
			
				var url = ipb.vars['base_url'] + 'app=bottombar&module=ajax&section=favorites&do=remove&md5check=' + ipb.vars['secure_hash'];
				
				new Ajax.Request(	url,
									{
										method: 'post',
										evalJSON: 'force',
										parameters: {
											id:		favid
										},
										onSuccess: function(t)
										{
											if( t.responseJSON['error'] )
											{
												alert( t.responseJSON['error'] );
											}
											else
											{
												$("fav" + favid ).remove();
			
												var _hasrows = 0;
												
												$$("#favorites-bb li").each( function(elem) { 
													_hasrows++; 
												});
												
												if( _hasrows == 1 )
												{
													$("favorites-bb").insert( { bottom: "<li class='center'><em>" + bbzfavs + "</em></li>" } );
												}
											}
										}
									}
								);
				
				Event.stop(e);
				return false;
			}
		});
	});


	//Click event on Chat Panel and Alert Panel	
	$( "friends-link" ).observe( "click", function(e) {
			Event.stop(e);
			
			if( $("friendpanel").down(".subpanel").visible() ) { //If subpanel is already active...

				$("friendpanel").down(".subpanel").hide(); //Hide active subpanel
				$$("#footpanel li a").each( function(elem) {
					$(elem).removeClassName('active'); //Remove active class on the subpanel trigger
				});
			}
			else { //if subpanel is not active...

				$$(".subpanel").each( function(elem) {
					$(elem).hide(); //Hide all subpanels
				});
				
				$("friendpanel").down(".subpanel").toggle(); //Toggle the subpanel to make active
				
				$$("#footpanel li a").each( function(elem) {
					$(elem).removeClassName('active'); //Remove active class on all subpanel trigger
				});
				
				$("friendpanel").toggleClassName('active'); //Toggle the active class on the subpanel trigger
			}
			
			return false; //Prevent browser jump to link anchor
	});