var sister = sister || {};




sister.addSister = function(sisterId,sisterTitle){
	
	var loadingDiv = document.createElement("div");
		loadingDiv.className='flora';
		loadingDiv.id='sisterLoading';
		
		$(loadingDiv).html("<div style='text-align:center;'><img src='/images/v3/loading.gif'></div>");
		
		$("#bodyRight").append(loadingDiv);
		
		$(loadingDiv).dialog();
	
	var dialogDiv = document.createElement("div");
		dialogDiv.id = "dialog_"+sisterId;
		dialogDiv.className='flora';

		htmlStr = "<div id='dialogMessage' style='margin-bottom: 10px;'>Which circle would you like to make "+unescape(sisterTitle)+" a sister of?</div>";
		htmlStr += "<div id='dialogContent' style='width: 200px; margin-bottom: 10px;'></div>";

		$(dialogDiv).hide();
		$(dialogDiv).html(htmlStr);
		url = "/api/circle.php?c=getEditLists";
		
		var cs = document.getElementById("circleStreamShow");
		cs.appendChild(dialogDiv);

		
		var selectObject = document.createElement("select");
			selectObject.id="pickCircle";
			$(selectObject).attr("name","pickCircle");
			
//				var optionObj = document.createElement("option");
//					$(optionObj).attr("value",follower);
//					$(optionObj).text("My Home");					
//					selectObject.appendChild(optionObj);			
					
		var dialogContent = document.getElementById("dialogContent");
			dialogContent.appendChild(selectObject);

		$.getJSON(url,function(jsondata){
			$("#sisterLoading").dialog("close");
			$("#sisterLoading").remove();
			$("#dialog_"+sisterId).show();
			$(jsondata.response).each(function(i,itemdata){
				if(itemdata.name !="My Home" && itemdata.name != unescape(sisterTitle)){
				var optionObj = document.createElement("option");
					$(optionObj).attr("value",itemdata.id);
					$(optionObj).text(itemdata.name);					
					selectObject.appendChild(optionObj);
				}
			});
				
		
		$("#dialog_"+sisterId).dialog(
			{
			width: 480,
			height: 300,
			buttons: { 
      		  "Ok": function() { 
					var listId = $("#pickCircle").val();
  				var url = "/api/sister.php?c=addSister&l="+listId+"&sl="+sisterId;
    				$.getJSON(url,function(data){
    					
    					$("#dialog_"+sisterId).dialog("close");
    					
    					
    					var dialog2 = document.createElement("div");
    						dialog2.className='flora';
    						dialog2.id='dialog2_'+sisterId;
    						
    					$(dialog2).html("<div style='text-align: center;'>"+unescape(sisterTitle)+" has been added as a sister.</div>");
    						
    						$("#bodyRight").append(dialog2);
							    						
    						$(dialog2).dialog({
    							buttons: { 
    							"Ok": function(){
	    								$(this).dialog("close");
	    								$(this).remove();
    								}
    							}
    						
    						});

						
					}); 

					},
				 "Cancel": function() { 
		          	  $(this).dialog("close"); 
        		  	  $(this).remove();
				}					
					
					}	      	
				
				
				});
			
			
			
						
		});


}


sister.removeSister = function(listId,sisterId,sisterTitle){

				
		var dialogDiv = document.createElement("div");
		dialogDiv.id = "dialog_"+sisterId;
		dialogDiv.className='flora';

		htmlStr = "<div id='dialogMessage' style='margin-bottom: 10px;'>Are you sure that you want to remove "+unescape(sisterTitle)+" from the Sister Circle List?</div>";
		htmlStr += "<div id='dialogContent' style='width: 200px; margin-bottom: 10px;'></div>";
		$(dialogDiv).html(htmlStr);
		
		$("#bodyRight").append(dialogDiv);
		$(dialogDiv).dialog({
			"buttons":{
				"Ok": function(){
					
					var url = '/api/sister.php?c=removeSister&l='+listId+'&sl='+sisterId;
					
					$.getJSON(url,function(data){
						
						$("#dialog_"+sisterId).dialog("close");
						$("#dialog_"+sisterId).remove();
						
						var completeDialog = document.createElement("div");
							completeDialog.className='flora';
							completeDialog.id='complete_'+sisterId;
							
							$(completeDialog).html("<div style='text-align:center;'>"+unescape(sisterTitle)+" has been removed");
						
							$("#bodyRight").append(completeDialog);
							
							$(completeDialog).dialog({
								"buttons": {
									"Ok": function(){
										$(this).dialog("close");
										$(this).remove();
										
										window.location=window.location.href;
										
									}
								}
							});							
					});
				
				
					
				},
				"Cancel": function(){
					$("#dialog_"+sisterId).dialog("close");
					$("#dialog_"+sisterId).remove();
				}
			
			}
		});
			

	}

