function subscribe(to) {
	
	document.getElementById("subtxt").href = "javascript:unsubscribe('"+ to +"');";
	$.post( "post/subscribe.php", { "to" : to } );
	$("#subtxt").text("Subscribed successfully!");
	setTimeout("$('#subtxt').text('Unsubscribe from "+ to +"');", 3000);
	
}

jQuery.fn.popup = function() {
		
	return $(this).toggle();
		
};

function unsubscribe(from) {
	
	var answer = confirm("Are you sure you want to unsubscribe from "+ from +"?");
	if(answer) {
	
		document.getElementById("subtxt").href = "javascript:subscribe('"+ from +"');";
		$.post( "post/unsubscribe.php", { "from" : from } );
		$("#subtxt").text("Unsubscribed successfully!");
		setTimeout("$('#subtxt').text('Subscribe to "+ from +"');", 3000);
	
	} else {
		
		void(0);
		
	}
	
}

function joinGroup(group) {

	document.getElementById("join-remove").href = "javascript:removeGroup('"+ group +"');";
	$.post( "post/joinGroup.php", { "group" : group } );
	history.go(0);
	
}

function removeGroup(group) {

	alert("stuff");

}

function deleteAccount() {

	alert("This feature is still under development.");
	
	/* var answer = confirm("Are you sure you want to delete your account? There is no undo!");
	if(answer) {
	
		$.post( "post/deleteAccount.php", { "delete" : "true" } );
		window.location = "./logout";
	
	} else {
	
		void(0);
	
	} */

}

function repost(entry, username) {

	alert("We're sorry, but the repost feature is under construction.\r\nLearn more: http://cloudi.ca/cloudica:story-983");
	
	/* var contents = $("#repost_"+ entry).text();
	var repost = "RP @"+ username +": "+ contents;
	$("#repost_link_"+ entry).text("Reposted!");
	setTimeout("$('#repost_link_"+ entry +"').text('Repost');", 3000);
	$.post( "post/repost.php", { "entry" : entry, "user" : username } );
	$.post(
	
		"post/update.php", {
		
			"entry" : repost
			
		},
		
		function(r) {
		
			$("#newPost").prepend(r);
			$(".latest").slideDown();
		
		}
	
	); */

}

function deleteEntry(id) {

	var answer = confirm("Are you sure you want to delete this entry?");
	if(answer) {
	
		$("#story_"+ id).fadeOut();
		$("#story_"+ id).removeClass("latest");
		$.post( "post/deleteEntry.php", { "entry" : id } );
		
	} else {
	
		void(0);
		
	}

}

function deleteComment(id) {

	var answer = confirm("Are you sure you want to delete this comment?");
	if(answer) {
	
		$("#comment_"+ id).slideUp();
		$("#comment_"+ id).removeClass("latest");
		$.post( "post/deleteComment.php", { "comment" : id } );
		
	} else {
	
		void(0);
		
	}

}

function deleteNotification(notification) {

	$("#notification_"+ notification).slideUp();
	$.post( "post/deleteNotification.php", { "notification" : notification } );
	
}

function changeFrom() {
	
	var newname = prompt("Please enter an alternate name here.");
	if(newname.length < 3 || newname.length > 30) {
	
		alert("Please enter a name between 3 and 30 characters.");
		void(0);
		
	} else {
	
		$("#changeFrom").text(newname);
		
	}
	
}

function openTab(tab) {
		
	var tabs = new Array();
	tabs[0] = "text";
	tabs[1] = "video";
	tabs[2] = "vimeo";
	tabs[3] = "youtube";
			
	for(i = 0; i <= 3; i++) {
			
		if(tabs[i] == tab) {
			
			$("#"+ tabs[i]).show();
			$(".type").text(tabs[i]);
					
		} else {
				
			$("#"+ tabs[i]).hide();
					
		}
			
	}
		
}

function loadAjaxNotifications() {

	$.ajax({
		
		url: "inc/ajax/getNotifications.php",
		cache: false,
		success: function(r) {
		
			if(r !== "none") {
			
				$("#alertpanel .subpanel").html(r);
			
			}
		
		}
		
	});

}

function checkNotifications() {

	$.ajax({
	
		url: "inc/ajax/notifications.php",
		cache: false,
		success: function(r) {
		
			if(r !== "none") {
				
				$(".newNotifications").text(r);
				$("#alerter").text(r +" Notifications");
				loadAjaxNotifications();
			
			}

		}
	
	});
	
}
setInterval(checkNotifications, 30000);
window.onload = checkNotifications();