
	$.profile = 
	{
			pid : 0
		,	build : function()
			{
				try
				{
					$.profile.pid = $("input.uid").val();
					
					if(!$.profile.pid)
						false;
						
					$.getJSON("http://pb.top2008.radio2.nl/user_check/uid_"+$.profile.pid+"/?pbcall=?", function(data)
					{
						var	data = eval(data);
	
						if(data.success)
						{
							var hoeText = $("div.profiel_detail table tr td.profiel_hoe").text();
							
							$("div.profiel_beleef_max").show();
							
							var iExt = ( parseInt($.browser.version) >= 6 && $.browser.msie === true ) ? "gif" : "png";
							
							$("div.profiel_detail table tr td.voegtoe").html("<input class=\"pas-aan\" type=\"image\" src=\"http://top2008.radio2.nl/static/images_smart/pas-aan."+iExt+"\" width=\"118\" height=\"46\" />");
							$("div.profiel_detail table tr td.profiel_hoe").html("<textarea maxlength=\"50\" class=\"who-text\">"+hoeText+"</textarea>");
							
							$.profile.setTagLine()
							$.profile.setProfileMessageDelete( );
							$.profile.setPreferceLink();
							$.profile.setGadgetLink();
						}
						
						$.profile.setProfileMessage();
						$.profile.setProfileAddFriends();
						$.profile.setAbuseAlarm();
						
						$.profile.log( "info", "Class \"profile\" wordt geladen");
					});
				}
				catch(err)
				{
					$.profile.log( "error", "Class \"profile\" wordt NIET geladen - " + err);
				}	
			}
			
		,	setTagLine : function()
			{
				$("input.pas-aan").bind("mousedown", function(){ return false; });
				$("input.pas-aan").unbind("click").bind("click", function()
				{
					$.getJSON("http://pb.top2008.radio2.nl/profile_change_tagline/?pbcall=?", { tagline : $("textarea.who-text").val() }, function(data)
					{
						var	data = eval(data);

						if(data.success)
						{
							$.post("http://top2008.radio2.nl/frontmodules/pb.clearcache.php", { pageCacheId : $("input.page_cache_id").val() }, function( data )
							{ 
								$.get("http://top2008.radio2.nl/frontmodules/pb.clearcache.php", { pageCache : "profile", uid : $.profile.pid  });
								
								alert("Uw \"Hoe beleef ik de Top2000?\" is aangepast!"); 
							});s
						}
						else
						{
							alert("U bent verplicht hier iets in te vullen!");
						}
					});
				});
					
				if(parseInt($("input.uid").val()) == $.registration.uid)
					$("table.posted-message tr td.links a").before("<a href=\"#\">Verwijder</a>&nbsp;&nbsp;");
			}
		
		,	setProfileMessage : function()
			{
				if($.registration.uid && $.profile.pid != $.registration.uid)
					$("table.post-message").show();
			
				try
				{
					$("table.post-message tr td a.post-message").bind("mousedown", function(){ return false; });
					$("table.post-message tr td a.post-message").bind("click", function()
					{
						var obj = $(this);
						
						if(!obj.parent().find(".message").val())
						{
							$.profile.log( "warn", "Bericht is leeg");
							return false;
						}
						
						$.getJSON("http://pb.top2008.radio2.nl/message_user_add/uid_"+$("td.voegtoe input.uid").val()+"/?pbcall=?&", { message : escape($(this).parent().find(".message").val()) }, function( data )
						{
							var	data = eval(data);
	
							if(data.success)
							{
								try
								{
									var postMsg = 	"<div class=\"new-message posted-message-top\"><table class=\"posted-message\" width=\"263\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
													+"<tr class=\"content\">"
													+"<td class=\"sender\"><a href=\"http://top2008.radio2.nl/page/08_profiel/"+$.registration.uid+"/meer#tabId_profiel-overzicht\"><img src=\"http://pb.top2008.radio2.nl/data/avatars/52/"+$.registration.avatar+"\" width=\"52\" height=\"52\" /></a><br />"
													+"<a href=\"http://top2008.radio2.nl/page/08_profiel/"+$.registration.uid+"/#tabId_profiel-overzicht\">"+$.registration.username+"</a></td>"
													+"<td width=\"10\"></td>"
													+"<td valign=\"top\">"+obj.parent().find(".message").val()+"</td>"
													+"</tr>"
													+"<tr class=\"bottom\">"
													+"<td>&nbsp;</td>"
													+"<td width=\"10\"></td>"
													+"<td class=\"links\">&nbsp;</td>"
													+"</tr>"
													+"</table></div>";

									obj.parent().find(".message").val("");
									
									$("table.post-message").after(postMsg);
						
									$.get("http://top2008.radio2.nl/frontmodules/pb.clearcache.php", { pageCache :"message", uid : $.profile.pid }, function()
									{		
										$.profile.updateBodyTabs();
									});
						
									$.profile.log( "info", "\"a.post-message\" is uitgevoerd");
								}
								catch(err)
								{
									$.profile.log( "error", "\"a.post-message\" wordt NIET uitgevoerd - " + err);
								}
							}
						});
						
						return false;
					});
					
					$.profile.log( "info", "setProfileMessage is uitgevoerd");
				}
				catch(err)
				{
					$.profile.log( "error", "setProfileMessage wordt NIET uitgevoerd - " + err);
				}
			}
			
		,	updateBodyTabs : function()
			{
				$.profile.log( "info", "test: updateBodyTabs ");
				
				try
				{
					if( $("ul.body-tabs").find(".active").hasClass("profiel-overzicht") )
					{
						 $.bodyTabs.loadContentFrame( "/page/08_tabcontent_overzicht/"+$.profile.pid );
						 $.profile.log( "info", "De body van tab \"profiel-overzicht\" is geupdate");
					}
					else if( $("ul.body-tabs").find(".active").hasClass("profiel-berichten") )
					{
						 $.bodyTabs.loadContentFrame( "/page/08_tabcontent_berichten/"+$.profile.pid );
						 $.profile.log( "info", "De body van tab \"profiel-berichten\" is geupdate");
					}
				}
				catch(err)
				{
					$.profile.log( "error", "Frame update niet uitgevoerd - " + err);
				}
			}
			
		,	setProfileMessageDelete : function()
			{	
				if($.profile.pid  == $.registration.uid)
				{
					$("span.delete-message").remove();
					$("a.mbr").before("<span class=\"delete-message\"><a class=\"delete-message\" href=\"#\">Verwijder</a>&nbsp;&nbsp;</span>");
				}
				
				$("a.delete-message").bind("mousedown", function(){ return false; });
				$("a.delete-message").bind("click", function()
				{
					try
					{
						var mid = $(this).parent().find(".mbr").attr("href");
						
							$.profile.log( "warn", "test: "+ mid);
		
						$("div.msgId_"+mid).css( { overflow:"hidden" } ).animate({ height:0 }, function()
						{
							$.getJSON("http://pb.top2008.radio2.nl/message_user_delete/mid_"+mid+"/?pbcall=?&", function( data )
							{	
								var	data = eval(data);
								
								$.profile.log( "info", "message: "+mid+" deleted");
		
								if(data.success)
								{
									$.get("http://top2008.radio2.nl/frontmodules/pb.clearcache.php", { pageCache :"message", uid : $.profile.pid }, function()
									{		
										$.profile.updateBodyTabs();
									});
								}
							});
						});
					}
					catch(err)
					{
						$.profile.log( "error", "dalete message niet verwijder - " + err);
					}
					
					return false;
				});
			}
			
		,	setProfileAddFriends : function( )
			{
				if(!$.registration.uid)
					return false;
				
				$("input.delete-friend, input.add-friend").remove();
				
				$.getJSON("http://pb.top2008.radio2.nl/profile_check_friend/uid_"+$("td.voegtoe input.uid").val()+"/?pbcall=?&", function( data )
				{
					var	data = eval(data);

					if(data.success)
					{
						$("td.voegtoe input.uid").after("<input class=\"delete-friend\" type=\"image\" src=\"http://top2008.radio2.nl/static/images_smart/verwijder-vriend.png\" width=\"185\" height=\"46\" />");
						$("td.voegtoe input.delete-friend").unbind("mousedown").bind("mousedown", function(){ return false; });
						$("td.voegtoe input.delete-friend").unbind("click").bind("click", function()
						{	
							$.getJSON("http://pb.top2008.radio2.nl/profile_delete_friend/uid_"+$("input.uid").val()+"/?pbcall=?&", function( data )
							{	
								var	data = eval(data);
								
								if(data.success)
								{
									$.get("http://top2008.radio2.nl/frontmodules/pb.clearcache.php", { pageCache : "friend", user : $.profile.pid, friend:$.registration.uid  }, function( data )
									{
										//alert("output friend: " + data )

										$.profile.setProfileAddFriends();
									});
								}
							});
						});
					}
					else
					{
						var iExt = ( parseInt($.browser.version) >= 6 && $.browser.msie === true ) ? "gif" : "png";
						
						$("td.voegtoe input.uid").after("<input class=\"add-friend\" type=\"image\" src=\"http://top2008.radio2.nl/static/images_smart/voegtoe_vrienden."+iExt+"\" width=\"242\" height=\"46\" />");
						$("td.voegtoe input.add-friend").unbind("mousedown").bind("mousedown", function(){ return false; });
						$("td.voegtoe input.add-friend").unbind("click").bind("click", function()
						{
							$.getJSON("http://pb.top2008.radio2.nl/profile_add_friend/uid_"+$("input.uid").val()+"/?pbcall=?&", function( data )
							{	
								var	data = eval(data);
								
								if(data.success)
								{	
									$.get("http://top2008.radio2.nl/frontmodules/pb.clearcache.php", { pageCache : "friend", user : $.profile.pid, friend:$.registration.uid  }, function( data )
									{
										//alert("output friend: " + data )

										$.profile.setProfileAddFriends();
									});
								}
							});
						});
					}
				});
			}
			
		,	setProfileDeleteFriends : function( )
			{
				if($.profile.pid != $.registration.uid)
					return false;
				
				$("div.friendof-card").each( function()
				{
					var content = $(this).html();
					$(this).html(content+"<a href=\"#\" class=\"delete delete-friendof\"></a>");
				})
				
				$("a.delete-friendof").unbind("mousedown").bind("mousedown", function(){ return false; });
				$("a.delete-friendof").unbind("click").bind("click", function()
				{	
					var	did = $(this).parent().find(".link-url").attr("href").split("/");
						did = did[(did.length-2)];
					
					$(this).parent().fadeOut( function()
					{
						$.getJSON("http://pb.top2008.radio2.nl/profile_delete_friend/uid_"+did+"/?pbcall=?", function( data )
						{
							var	data = eval(data);

							if(data.success)
								$.get("http://top2008.radio2.nl/frontmodules/pb.clearcache.php", { pageCache :"message", uid : $.profile.pid  });
							
							$(this).remove();
						});
					});
				
					return false;
				});
			}
		
		,	setTabsCallBack : function()
			{
				$("a.meer-gepraat").unbind("mousedown").bind("mousedown", function(){ return false; });
				$("a.tabButton").unbind("click").bind("click", function()
				{	
					var	anchors = $(this).attr("href").toString();
	
					top.location.href="#tabLocation";
					$.bodyTabs.setActiveTab( $("ul.body-tabs"), anchors);
	
					return false;
				});
				
				$.profile.setProfileDeleteFriends();
				$.profile.setProfileMessageDelete();
			}
			
		,	setAbuseAlarm : function()
			{
				$("a.mbr").unbind("mousedown").bind("mousedown", function(){ return false; });
				$("a.mbr").unbind("click").bind("click", function()
				{			
					$.getJSON("http://pb.top2008.radio2.nl/message_abuse/mid_"+$(this).attr("href")+"/?pbcall=?", function( data )
					{	
						var	data = eval(data);
						
						if(data.success)
							alert("Uw melding is verzonden.\nDit bericht wordt spoedig door de redactie verwijderd!");
					});
					
					
					return false;
				});
			}
			
		,	setPreferceLink : function()
			{
				$("div.my-preferences").html("<a href=\"http://top2008.radio2.nl/page/08_instellingen\">Mijn instellingen</a>");
			}
			
		,	setGadgetLink : function()
			{
				$("div.balloon").bind("click", function(){ return false; });
				
				$("div.my-gadget").show();
				$("div.my-gadget").find("a.show-balloon").bind("mousedown", function(){ return false; });
				$("div.my-gadget").find("a.show-balloon").bind("click", function()
				{
					var	bObj = $(this).parent().find("div.balloon");
						bObj.show();
						
					$(this).parent().find("table").find("a").bind("click", function()
					{
						window.open("http://www.hyves.nl/profielbeheer/toevoegen/gapmember/", "_blank");
						
						$(document).unbind("click");
						bObj.hide();
						
						return false;
					});
					
					$(document).bind("click", function()
					{
						$(document).unbind("click");
						bObj.hide();
						
						return false;
					});
					
					return false;
				});
			}
			
		,	log : function( type, msg )
			{
				
				$.pbLog.debug( { title:"Profile", msgs : [{type:type, msg:msg }] } );
			}
	};
	
	$.fn.extend
	({
			profile : $.profile.build
	});
	