var friendList = friendList || {};



friendList.getFriendCount = function(userId){
	
	var url = "/api/friendList.php";
	var params = {u:userId,total:"true"};
	$.getJSON(url,params,function(data){
		memberCount = data.result;
		$("#totalFriends").html(memberCount);

	});
	

}

friendList.getFriendList = function(userId,page,type){	
		var sortOrder =  $("#friendsSortOrder option:selected").val();

	$("#friendList").load("/api/friendList.php",{"p": page,"u":userId,"type":type,"sortOrder":sortOrder},function(){
		
	if(type == "grid"){
		$("#friendListImg").attr("src","/images/v3/list_off.png");
		$("#friendGridImg").attr("src","/images/v3/grid_on.png");
	}else if(type == "list"){
		$("#friendListImg").attr("src","/images/v3/list_on.png");
		$("#friendGridImg").attr("src","/images/v3/grid_off.png");
	}
		$(".gridLink").tooltip({showURL: false });
	
		$(".friendListImage").click(function(event){			
			var dropDownImage = event.target.id;
			if(dropDownImage.lastIndexOf("dropDownFriendImg") != -1){
				var userId = dropDownImage.split("_")[1];
				var dropDownItemMenu = "#dropDownItemFriendMenu_"+userId;
				
				$(dropDownItemMenu).css({"margin-top":10+"px", "margin-left": 10+"px", "position" : "absolute", "left" : "0"});
				if($(dropDownItemMenu).css("display") == "block"){
					$(dropDownItemMenu).fadeOut("fast");			
				}else{
					$(".dropDownEditMenu").fadeOut("fast");
					$(dropDownItemMenu).fadeIn("fast");			
					$(dropDownItemMenu).click(function(){ $(this).fadeOut();});			
					$(dropDownItemMenu).bind("mouseleave",function(){
					 $(this).fadeOut();
					 });
				}

				
			}

		});
	});	
}

