function Story() {}

Story.commit_overlay = function(story_id, type) {
	if (require_login()) return false;
	Overlay.show("story/post", {type: type, story_id: story_id});
	return false;
}

Story.post_overlay = function(type, text, desc) {
	if (require_login()) return false;
	Overlay.show("story/post", {type: type, text: text, desc: desc});
	return false;
}

Story.complete_overlay = function(story_id) {
	if (require_login()) return false;
	Overlay.show('story/post', {story_id: story_id});
	return false;
}

Story.edit_overlay = function(story_id) {
	if (require_login()) return false;
	Overlay.show('story/post', {story_id: story_id, edit: true});
	return false;
}

Story.show_photo = function(story_id) {
	Overlay.show('story/photo', {'story_id': story_id}, null, {'width': 590});
	return false;
}

Story.message_doers = function(story_id) {
	if (require_login()) return false;
	Overlay.show('story/message_doers', {'story_id':story_id});
	return false;
}

Story.approve = function(story_id, story_user_id, sponsoring_story_id) {
	$('#approve_box' + story_id).hide();
	$("#approve_box_loading" + story_id).show();
	data = {'story_id': story_id, sponsoring_story_id: sponsoring_story_id};
	var ajx = new Ajax('/ajax/story/approve', data);
	ajx.type = "POST";
	ajx.fetch(function(result) {
		$("#approve_box_loading" + story_id).hide();
		if (!result.success) {
			$("#approve_box" + story_id).show();
			alert("You do not have sufficient permission to approve this story.");
		} else {
			if (!result.paid) {
				$("#approve_box" + story_id).show();
				if (confirm("You do not have enough Qens to approve this person. Would you like to add more Qens?")) {
					window.location = "/wallet/buy";
				}
			} else {
				$('#approved_box' + story_id).show();				
			}
		}
	});
	return false;
}

Story.reject = function(story_id, story_user_id, sponsoring_story_id) {
	$('#approve_box' + story_id).hide();
	$("#approve_box_loading" + story_id).show();
	data = {'story_id': story_id, sponsoring_story_id: sponsoring_story_id};
	var ajx = new Ajax('/ajax/story/reject', data);
	ajx.type = "POST";
	ajx.fetch(function() {
		$("#approve_box_loading" + story_id).hide();
		$('#rejected_box' + story_id).show();
	});
	return false;
}

Story.like = function(story_id) {
	if (require_login()) return false;
	data = {'story_id': story_id, 'page': page};
	var ajx = new Ajax('/ajax/story/like', data);
	ajx.type = "POST";
	ajx.fetch(function() {
		if (page == "iphone") {
			reload_activity();
		} else {
			Feed.update_story(story_id);
		}
	});
	return false;
}

Story.like_url = function(url) {
	if (require_login()) return false;
	data = {'url': url, 'page': page};
	var ajx = new Ajax('/ajax/story/like', data);
	ajx.type = "POST";
	ajx.fetch(function(result) {
		if (result.success) {
			Feed.update_story(result.story_id);
		}
	});
	return false;	
}

Story.dislike = function(story_id){
	if (require_login()) return false;
	data = {'story_id': story_id};
	var ajx = new Ajax('/ajax/story/dislike', data);
	ajx.type = "POST";
	ajx.fetch(function() {
		Feed.update_story(story_id);
	});
	return false;
}

Story.comment = function(story_id, text) {
	if (text.indexOf("Write a comment") >= 0 || text == "") {
		$(".error", "#feed_item"+story_id).show();
		return false;		
	}
	$(".error", "#feed_item"+story_id).hide();
	$(".comment_form_buttons", "#feed_item"+story_id).hide();
	$(".comment .loading", "#feed_item"+story_id).show();
	var ajx = new Ajax("/ajax/story/comment", {story_id: story_id, text: text});
	ajx.type = "POST";
	ajx.fetch(function() {
		if (page == "iphone") {
			reload_activity();
		} else {
			Feed.update_story(story_id);
		}
	});
	return false;
}

Story.hide_overlay = function(story_id) {
	$('#feed_item' + story_id + ' .close-item').hideTooltip();
	Overlay.show('story/hide', {"story_id": story_id}, function(result) {
		if (result) {
			var o = $("#feed_item" + story_id);
			o.animate({
				height: 0,
				opacity: 0
			}, 250, function() {
				o.hide();
			});
		}
	});
}

Story.hide = function(story_id) {
	if (require_login()) return false;
	data = {'story_id': story_id};
	var ajx = new Ajax('/ajax/story/hide', data);
	ajx.type = "POST";
	ajx.fetch();
	return false;
}

Story.restore = function(story_id) {
	if (require_login()) return false;
	$('#restore_button'+story_id).hide();
	$('#dislike_button'+story_id).hide();
	$('#restore_placeholder'+story_id).show();
	data = {'story_id': story_id, 'page': page};
	var ajx = new Ajax('/ajax/story/restore', data);
	ajx.type = "POST";
	ajx.fetch(function() {
	});
	return false;
}

