var sns=
{
	group_cache: "",
	event_cache: "",
	place_holder: "",
	vid: 0,
	uid: 0,
	listGroup: function(id, type)
	{
		if (this.place_holder=="")
		{
			this.place_holder=$('#sns_place').html();
		}
		var url_="/sns/" + type + "group/";
		if (type=='add')
		{
			this.vid=id;//video id
		}
		else
		{
			this.uid=id;//invited uid
		}
		
		$.ajax({
			type: "GET",
			url: url_,
			beforeSend: function(req){
				$('#sns_place').html("Đang tải...");
			},
			complete: function(res, s){
				group_cache=res.responseText;
				$('#sns_place').html(res.responseText);
			}
		});
		return false;
	},
	addGroup: function()
	{
		if (!confirm('Bạn chắc chắn thêm video nào vào nhóm'))
		{
			return false;
		}

		$.ajax({
			type: "POST",
			url: "/sns/addgroup",
			data: $("#gid").serialize() + "&vid=" + this.vid,
			beforeSend: function(req){
				$('#sns_place').html("Đang gửi...");
			},
			complete: function(res, s){
				$('#sns_place').html(res.responseText);
			}
		});
		return false;
	},
	inviteGroup: function()
	{
		if (!confirm('Bạn chắc chắn mời người đăng vào nhóm'))
		{
			return false;
		}

		$.ajax({
			type: "POST",
			url: "/sns/invitegroup",
			data: $("#gid").serialize() + "&uid=" + this.uid,
			beforeSend: function(req){
				$('#sns_place').html("Đang gửi...");
			},
			complete: function(res, s){
				$('#sns_place').html(res.responseText);
			}
		});
		return false;		
	},
	listEvent: function(id, type)
	{
		if (this.place_holder=="")
		{
			this.place_holder=$('#sns_place').html();
		}
		var url_="/sns/" + type + "event/";
		if (type=='add')
		{
			this.vid=id;//video id
		}
		else
		{
			this.uid=id;//invited uid
		}
		$.ajax({
			type: "GET",
			url: url_,
			beforeSend: function(req){
				$('#sns_place').html("Đang tải...");
			},
			complete: function(res, s){
				group_cache=res.responseText;
				$('#sns_place').html(res.responseText);
			}
		});
		return false;
	},
	addEvent: function()
	{
		if (!confirm('Bạn chắc chắn thêm video nào vào sự kiện'))
		{
			return false;
		}

		$.ajax({
			type: "POST",
			url: "/sns/addevent",
			data: $("#eid").serialize() + "&vid=" + this.vid,
			beforeSend: function(req){
				$('#sns_place').html("Đang gửi...");
			},
			complete: function(res, s){
				$('#sns_place').html(res.responseText);
			}
		});
		return false;		
	},
	inviteEvent: function()
	{
		if (!confirm('Bạn chắc chắn mời người đăng vào sự kiện'))
		{
			return false;
		}

		$.ajax({
			type: "POST",
			url: "/sns/inviteevent",
			data: $("#eid").serialize() + "&uid=" + this.uid,
			beforeSend: function(req){
				$('#sns_place').html("Đang gửi...");
			},
			complete: function(res, s){
				$('#sns_place').html(res.responseText);
			}
		});
		return false;		
	},
	restore: function()
	{
		$('#sns_place').html(this.place_holder);
		return false;
	}
}