// 1209001155 - ancino 1198350286 - sphere



$(document).ready(function (){

	$("#connections").tabs().fadeIn("normal"); 

	$("#test_fb").click(function(){
		load_feed();
	});
	$("#search_friend_submit").click(function(){
		//load_feed()
		var search_text = $("#search_users").val()
		if (search_text == "") return false;
		notify("#search_message","searching ...",500);
		var url = $(this).attr("url");
		$.post(url, {search:search_text}, function(data){
			$("#user_search_results").slideDown(300).html(data);
		});
		return false;
	});

	/* fix IE issue with submitting form where return = false */
	$("#search_users").live('keyup', function(e) {
		if ($.browser.msie) {
			if (e.which == 13 || e.which == 10) {
				$("#search_friend_submit").trigger('click');
			}
		}
	});
	
	
	$("#email_invite_submit").live('click', function(){

		var email_addresses = $("#email_invite_addresses").val();
		if (email_addresses == ""){
			alert("Please input 1, or more, email address.");
			return false;
		}
		if(email_addresses.length > 150){
			alert("Too long. Please limit to 150 chars.");
			return false;
		}
		if(uShow.email_valid(email_addresses) == false) {
			alert("There's something wrong with one, or more, of these email addresses.");
			return false;
		}
		$("#email_invite_addresses").val("");
		notify("#email_message","sent to ... " + email_addresses, 2400);
		var url = $(this).attr("url");
		$.post(url, {addresses: email_addresses}, function(data) {
			return false;
		});
		return false;
	
	});
	var toggle_text;
	$("#email_example_show").toggle(function(){
		$("#email_example").slideDown(400);
		toggle_text = $(this).html();
		$(this).html("hide");
	},
	function(){
		$("#email_example").slideUp(400);
		$(this).html(toggle_text);
	});



/**
* Capture Events on Friends pages
*/

	$("#friends").tabs().fadeIn("normal");
	$("#followers .block").live('click', function(){
		var url = $(this).attr('href');
		
		$("#blockwarning").clone().dialog({
			bgiframe: true,
			title: "Are you sure you want to block this person?",
			resizable: false,
			width:600,
			modal:true,
			buttons: {
				'Ya, I still want to block this person.': function() {
					location.href = url;
				},
				"Never mind, we're cool.": function() {
					$(this).dialog('close');
				}
			}
			});
		return false;
	});

	$("#blocked .block").live('click', function(){
		var url = $(this).attr('href');
		
		$("#blockwarning").clone().dialog({
			bgiframe: true,
			title: "Are you sure you want to un-block this person?",
			resizable: false,
			width:600,
			modal:true,
			buttons: {
				"Yes": function() {
					location.href = url;
				},
				"No": function() {
					$(this).dialog('close');
				}
			}
			});
		return false;
	});
	
	$("#following .block").live('click', function(){
		var li = $(this).parents('#following li')
		$.get( $(this).attr('href'), {}, function(data, status){
			$("#following_count").text($("#following_count").text() -1);
			li.slideUp();
		});
		return false;
	});
	
});

