var circleMembers = circleMembers || {};

var memberCount = 0;
var editorCount = 0;

circleMembers.getMemberCount = function(listId){
	
	var url = "/api/circleMembers.php";
	var params = {l:listId,total:"true"};

	$.getJSON(url,params,function(data){
		memberCount = data.result;
		$("#totalMembers").html(memberCount);

	});
	

}

circleMembers.getMemberList = function(listId,page,type){	

	var sortOrder =  $("#memberSortOrder option:selected").val();
	
	$("#memberList").load("/api/circleMembers.php",{"p": page,"l":listId,"type":type,"sortOrder":sortOrder},function(){
		
	if(type == "grid"){
		$("#memberListImg").attr("src","/images/v3/list_off.png");
		$("#memberGridImg").attr("src","/images/v3/grid_on.png");
	}else if(type == "list"){
		$("#memberListImg").attr("src","/images/v3/list_on.png");
		$("#memberGridImg").attr("src","/images/v3/grid_off.png");
	}
		
		$(".gridLink").tooltip({showURL: false });
	
		$(".memberListImage").click(function(event){			
			var dropDownImage = event.target.id;
			if(dropDownImage.lastIndexOf("dropDownMemberImg") != -1){
				var userId = dropDownImage.split("_")[1];
				var dropDownItemMenu = "#dropDownItemMenu_"+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();
					 });
				}

				
			}
			
		
		});
		
	});	
}



circleMembers.getEditorCount = function(listId){
	
	var url = "/api/circleEditors.php";
	var params = {l:listId,total:"true"};
	
	$.getJSON(url,params,function(data){
		memberCount = data.result;
		$("#totalEditors").html(memberCount);

	});
	

}

circleMembers.getEditorList = function(listId,page,type){	
	var sortOrder =  $("#editorSortOrder option:selected").val();

	$("#editorList").load("/api/circleEditors.php",{"p": page,"l":listId,"type":type,"sortOrder":sortOrder},function(){
	
		if(type == "grid"){
		$("#editorListImg").attr("src","/images/v3/list_off.png");
		$("#editorGridImg").attr("src","/images/v3/grid_on.png");
	}else if(type == "list"){
		$("#editorListImg").attr("src","/images/v3/list_on.png");
		$("#editorGridImg").attr("src","/images/v3/grid_off.png");
	}
		
		$(".gridLink").tooltip({showURL: false });
	
			$(".editorListImage").click(function(event){	

			var dropDownImage = event.target.id;
			if(dropDownImage.lastIndexOf("dropDownEditImg") != -1){
				
				var userId = dropDownImage.split("_")[1];
				
				var dropDownItemMenu = "#dropDownEditItemMenu_"+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();
					 });
				}

				
			}

		});
	
	
	
	
	
	
	});	
}



circleMembers.getWatchingCount = function(listId){
	
	var url = "/api/circleWatching.php";
	var params = {l:listId,total:"true"};
	$.getJSON(url,params,function(data){
		memberCount = data.result;
		$("#totalWatching").html(memberCount);

	});
	

}

circleMembers.getWatchingList = function(listId,page,type){	
		var sortOrder =  $("#watchingSortOrder option:selected").val();

	$("#watchingList").load("/api/circleWatching.php",{"p": page,"l":listId,"type":type,"sortOrder":sortOrder},function(){
		
	if(type == "grid"){
		$("#watchingListImg").attr("src","/images/v3/list_off.png");
		$("#watchingGridImg").attr("src","/images/v3/grid_on.png");
	}else if(type == "list"){
		$("#watchingListImg").attr("src","/images/v3/list_on.png");
		$("#watchingGridImg").attr("src","/images/v3/grid_off.png");
	}
		$(".gridLink").tooltip({showURL: false });
	
		$(".watchingListImage").click(function(event){			
			var dropDownImage = event.target.id;
			if(dropDownImage.lastIndexOf("dropDownWatchingImg") != -1){
				var userId = dropDownImage.split("_")[1];
				var dropDownItemMenu = "#dropDownItemWatchMenu_"+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();
					 });
				}

				
			}

		});
	});	
}



circleMembers.getWatchedCount = function(listId){
	
	var url = "/api/circleWatched.php";
	var params = {l:listId,total:"true"};
	$.getJSON(url,params,function(data){
		memberCount = data.result;
		$("#totalWatched").html(memberCount);

	});
	

}

circleMembers.getWatchedList = function(listId,page,type){	
		var sortOrder =  $("#watchedSortOrder option:selected").val();

	$("#watchedList").load("/api/circleWatched.php",{"p": page,"l":listId,"type":type,"sortOrder":sortOrder},function(){
		
	if(type == "grid"){
		$("#watchedListImg").attr("src","/images/v3/list_off.png");
		$("#watchedGridImg").attr("src","/images/v3/grid_on.png");
	}else if(type == "list"){
		$("#watchedListImg").attr("src","/images/v3/list_on.png");
		$("#watchedGridImg").attr("src","/images/v3/grid_off.png");
	}
		$(".gridLink").tooltip({showURL: false });
	
		$(".watchedListImage").click(function(event){			
			var dropDownImage = event.target.id;
			if(dropDownImage.lastIndexOf("dropDownWatchedImg") != -1){
				var userId = dropDownImage.split("_")[1];
				var dropDownItemMenu = "#dropDownItemWatchedMenu_"+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();
					 });
				}

				
			}

		});
	});	
}





