/**
 * General purpose javascript functions
 * @author Emil og John
 */

if (typeof doCufon === 'undefined') {
	var doCufon = function() {};
}

var initPagination = undefined;



/** 
 * onWindowLoad
 */
$(function(){
	
	// Bind an event to window.onhashchange that, when the history state changes,
	// gets the fragment from the hash and act upon it
	$(window).hashchange(function() {
		// consider caching
		
		var url = location.hash;
	    Hash.action(url);
	});
  
	// Since the event is only triggered when the hash changes, we need to trigger
	// the event now, to handle the hash the page may have loaded with.
	$(window).hashchange();
	
	// This piece of code handles how the popdown box behaves when you click on 
	// the arrow next to your profile.
	$('#UserProfileNameBox').click(function() {
		$("#UserHoverMenu").toggle();
	});


	
//	$('#PopupBackground').click(function() {
//		PopupCompletedGoal.close();
//		PopupWarning.close();
//	});
	
	$('#UserEditTags').click(function(e) {
		PopupEditTags.show(e);
	});
	
	$('#EditTagsPopDown .cancel').click(function() {
		PopupEditTags.close();
	});
	
	
	
	//Code to handle the HoverGoalInfoBox
	$('.ProfilePic').live('hover', function() {
		HoverGoalInfoBox.show(this);
	});
	
	$('.ProfilePic').live('mouseleave', function() {
		HoverGoalInfoBox.hide();
	});
	
	//Code to handle the HoverGoalInfoBox3
	$('.CommentProfilePic').live('hover', function() {
		HoverGoalInfoBox2.show(this);
	});
	
	$('.CommentProfilePic').live('mouseleave', function() {
		HoverGoalInfoBox2.hide();
	});
	
	//Code to handle the HoverGoalInfoBox2
	$('#CommentProfilePicGoalComment').live('hover', function() {
		HoverGoalInfoBox2.show(this);
	});
	
	$('#CommentProfilePicGoalComment').live('mouseleave', function() {
		HoverGoalInfoBox2.hide();
	});
	
	
	$('.subprofilepic').live('hover', function() {
		HoverGoalInfoBox.show(this);
	});
	
	$('.subprofilepic').live('mouseleave', function() {
		HoverGoalInfoBox.hide(this);
	});
	
	
	$('#UserUnsubscribe').live('hover', function() {
		$(this).find('.BubbleTooltip').show();
	});
	
	$('#UserUnsubscribe').live('mouseleave', function() {
		$(this).find('.BubbleTooltip').hide();
	});
	
	$('#UserSubscribe').live('hover', function() {
		$(this).find('.BubbleTooltip').show();
	});
	
	$('#UserSubscribe').live('mouseleave', function() {
		$(this).find('.BubbleTooltip').hide();
	});
	
	
	
//	$("#PostForm").live('submit', function() {
//		$.post("Ajax", 
//				{
//				"userofpost" : $(this).find('input[name=UserIdField]').val(),
//				"method" : "post",
//				"action" : "create",
//				"addyourtags" : $(this).find('input[name=addyourtags]').val(),
//				"posttitle" : $(this).find('input[name=posttitle]').val(),
//				"postdescription" : $(this).find('textarea[name=postdescription]').val()
//				},
//				function(data){
//			console.log('F�rdig med post: ', data);
//		});
//		return false;
//	});
	
	doCufon();
});

var PopupEditTags = {
	show : function(e) {
		//Show
		$("#EditTagsPopDown").css({"left": e.pageX - 150,
								   "top": e.pageY});
		$('#EditTagsPopDown').fadeIn("fast");
		$("#PopupBackground").css({"opacity": "0.41"});
		$("#PopupBackground").fadeIn("fast");
	},
	close : function() {
		$("#PopupBackground").fadeOut("fast");
		$('#EditTagsPopDown').fadeOut("fast");
	}
};

/**
 * Bubble tooltip
 */
var BubbleTooltip = {
	open : function() {
		
	},
	
	close : function() {
		
	}
};

/**
 * Popup
 */
var PopupCompletedGoal = {
	open : function() {
		// set title and text -- title, message
//		$("#popup .content .header h1").text(title);
//		$("#popup .content .message .text").html(message);
	
		var windowWidth = document.documentElement.clientWidth;  
		var windowHeight = document.documentElement.clientHeight;  
		var popupHeight = $("#PopupTrophyContainer").height();  
		var popupWidth = $("#PopupTrophyContainer").width();  
		
		//centering  
		//console.log(windowHeight);
		
		$("#PopupTrophyContainer").css({  
			"position": "absolute",  
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		  
		$("#PopupBackground").css({  
			"height": windowHeight  
		});  
	
		// show
		$("#PopupBackground").css({"opacity": "0.41"});  
		$("#PopupBackground").fadeIn("slow");
		$("#PopupTrophyContainer").fadeIn("slow");
	},
	
	close : function() {
		$("#PopupBackground").fadeOut("slow");
		$("#PopupTrophyContainer").fadeOut("slow");
	}
};

var PopupWarning = {
		open : function() {
			// set title and text -- title, message
//			$("#popup .content .header h1").text(title);
//			$("#popup .content .message .text").html(message);
		
			var windowWidth = document.documentElement.clientWidth;  
			var windowHeight = document.documentElement.clientHeight;  
			var popupHeight = $("#PopupWarningContainer").height();  
			var popupWidth = $("#PopupWarningContainer").width();  
			
			//centering  

			
			$("#PopupWarningContainer").css({  
				"position": "absolute",  
				"top": windowHeight/2-popupHeight/2,
				"left": windowWidth/2-popupWidth/2
			});
			  
			$("#PopupBackground").css({  
				"height": windowHeight  
			});  
		
			// show
			$("#PopupBackground").css({"opacity": "0.41"});  
			$("#PopupBackground").fadeIn("slow");  
			$("#PopupWarningContainer").fadeIn("slow");  
		},
		
		close : function() {
			$("#PopupBackground").fadeOut("slow");  
			$("#PopupWarningContainer").fadeOut("slow");  
		}
	};

/**
 * Menu-bar that appears if you click on the profile link-arrow on top of the page.
 */
var t;
var HoverMenuOptions = {
	open : function() {
		$("#UserHoverMenu").css({"display": "block"});
	},

	close : function() {
		//$("#UserHoverMenu").delay(2000);

			$("#UserHoverMenu").fadeOut(200);

	}
};

/**
 * A hovering box that will appear next to a portrait.
 * Remember to supply the element from which you call in the selector.
 */
var HoverGoalInfoBox = {
		show : function( element ) {
			var profilePic = $(element).parent().parent();
			var dialog = $(element).find('.HoverBox');
			
			var left, top;
			left = profilePic.position().left;
			top = profilePic.position().top;
			
	
		
			//$('#MainContent').append(dialog);
			$('#MainContent>.HoverBox').remove();
			dialog.clone().appendTo('#MainContent');
			
//			$('#MainContent>.HoverBox').offset({
//				"top"  : top,
//				"left" : left
//			});
			$('#MainContent>.HoverBox').css("top", (top));
			$('#MainContent>.HoverBox').css("left", (left+200));
			$('#MainContent>.HoverBox').css("position", "absolute");
			$('#MainContent>.HoverBox').fadeIn();
			
			
		},
		hide : function() {
			$("#MainContent>.HoverBox").stop(true, true).fadeOut(function() {
				$(this).css({"display": "none"});
			});
			
		}
};

/**
 * A hovering box that will appear next to a portrait.
 * Remember to supply the element from which you call in the selector.
 */
var HoverGoalInfoBox2 = {
		show:function(element) {
			var link = $(element);
			var dialog = $(element).find('.HoverBox');
				dialog.delay(500).fadeIn(50, function() {
					dialog.css("top", -70);
					dialog.css("left",50);
					dialog.css("position", "absolute");
				});
			},
			
			hide : function () {
					$(".HoverBox").stop(true, true).fadeOut(function() {
					$(this).css({"display" : "none"});
				});
			}
};




/**
 * A hovering box when going over a subscriber on the subscriber page
 * Will list his infomartion like the userpage
 * 
 */
var HoverSubUserinfo = {
		show : function(element) {
			var link = $(element);
			var dialog = $(element).find('.SubhoverBox');
			
			dialog.delay(500).fadeIn(50, function() {
				dialog.css("position", "absolute");
			});
		},
		hide : function() {
			$(".SubhoverBox").fadeOut(function() {
				$(this).css({"display" : "none"});
			});
		}
};

/**
 * View post
 */
var ViewPost = {
	view : function( postid ) {
		
	}
};



/**
 * Url hashing
 */
var Hash = {
	
	/**
	 * Evaluates the fragment of the URL, and call the method specified
	 * by the fragment given
	 * @param fragment the string mapping to a function with arguments.
	 * @author Mikkel
	 */
	action : function(fragment) {
		var fragment_arr = fragment.split("/");
		var string = fragment_arr[1];
		
		// only accept methods with chars or _
		if (string != null && string != "" && string.match(/\w+/)) {
			var args = fragment_arr;
			args.splice(0, 2); // remove the first 2 elements
			
			for (var i = 0; i < args.length; i++) {
				args[i] = "\"" + args[i] + "\"";
			}
			
			var s = "Hash.methods." + string + "(" + args + ")";
			eval(s);
			
			// update new message count
			Hash.methods.updateNewMessageCount();
			
			return;
		}
	},
	
	load : function(method, args, callback) {
		$.post(
			
		);
	},
	
	methods : {
//		test : function(args) {
//			var $page = $('#pageContainer');
//			$page.hide();
//			
//			$page.load("Ajax", 
//					{	// post data
//				"method" : "test",
//				"id" : args[0],
//				"something" : args[1]
//					}, function(html) {
//						$page.show();
//					}
//			);
//		},
//		
		tag : function(args) {
			var $page = $('#pageContainer');
			$page.hide();
			
			$page.load("Ajax", 
					{	// post data
				"method" : "test",
				"id" : args[0]
					}, function() {
						$page.show();
			});
		},
		
		search : function(searchtext) {
			var $titlebanner = $('#DisplayListTop .ribbon');
			
			if( Validate.empty( searchtext ) ) {
				$("#searchtop").css({"border" : "1px solid red"});
				return false;
			}
			else {
				$("#searchtop").css({"border" : "none"});
			}	
			$.post(	'Ajax',
					{
						"method" : "searchBox",
						"args" : searchtext
					},
					function(data) {
						if (data.success == 'true') {
							$('#searchtop').val("");
							
							
							Hash.methods.recenttags();
							Hash.methods.tagpostlist(data.tagId);
							$titlebanner.find('h1').text(unescape(searchtext));
							
						} else {
							$('#message').html("Something whent wrong: " + data.error);
						}
					}
				);
		},
		
		
		viewuser : function(id) {
			var $page = $('#InnerContainer');
			
			$page.load("viewuser.jsp", 
					{ "userid" : id }, function() {
						doCufon();
			});
		},
		
		viewpost : function(id) {
			var $page = $('#InnerContainer');
			
			$page.load("viewpost.jsp", 
					{ "postid" : id }, function() {
						doCufon();
			});
		},
		
		showpostlist : function(id) {
			var $page = $('#PostWrapper');
			
			$page.load(
				"pages/post.jsp", 
				{ 
					"postid" : id,
					"goldenOrNot" : false
				}, 
				function() {
					Hash.methods.initPagination();
					doCufon();
				}
			);
		},
		
		updateNewMessageCount : function() {
			var $page = $('#newMessageCountWrapper');
			
			
			$page.load(
				"pages/newMessageCount.jsp", 
				{ }, 
				function() {
					doCufon();
				}
			);
		},
		
		successtorieslist : function() {
			var $page = $('#InnerPostWrapper');
			var $titlebanner = $('#DisplayListTop .ribbon');
			
			$titlebanner.attr('class', "");
			$titlebanner.addClass("ribbon");
			$titlebanner.addClass("yellow");
			$titlebanner.find('h1').text("Succes Stories");
			
			$("#PostWrapper .displayListPost").removeClass('golden');
  			$("#PostWrapper .displayListPost>div").fadeOut();
  			$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").show();
  			
  			$("#PostWrapper .displayListPost>div").promise().done(function() {
  				$("#Recent").remove();
  				$("#TopRated").remove();
  				$("#Updates").remove();
  				$.get(
				"pages/successtorieslist.jsp", 
				{ 
									
				}, 
				function(data) {
					$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").hide();
					$page.html(data);
					var totalheight   = 0;
					doCufon(function() {
						$("#PostWrapper .displayListPost>div").hide().fadeIn('slow').promise().done(function() {
							$("#PostWrapper .displayListPost").each(function(i, val) {
								 totalheight += Math.round($(val).height()+1);
								return i != 4;
								
							});
							$("#PostWrapper").animate({
								"height" : totalheight
							});
						});
					});
				}
			);
		});
	},
		
		recenttags
		: function() {
			var $page = $('#RecentTagsList ul');
	
			$page.load(
				"pages/recenttaglist.jsp", 
				{
				},
		
				function() {
					doCufon();
				}
			);
		},
		

		
		tagpostlist
		: function(id, sortOption) {
			var $page = $('#InnerPostWrapper');
			var $ribbon = $('#RecentTagsList');
			var $titlebanner = $('#DisplayListTop .ribbon');
			
			$titlebanner.attr('class', "");
			$titlebanner.addClass("ribbon");
			$titlebanner.addClass("gray");
			$titlebanner.find('h1').text($ribbon.find('a.recentTag' + id).text());
			
			   $.get('pages/postListTopBar.jsp', { id: id, typeOfPostlist : "tagpostlist" }, function (data) {
					$("#Recent").remove();
					$("#TopRated").remove();
					$("#Updates").remove();
				   $('#TopOptions').prepend(data);
			    });
			
			
			$("#PostWrapper .displayListPost").removeClass('golden');
  			$("#PostWrapper .displayListPost>div").fadeOut();
  			$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").show();
  			
  			$("#PostWrapper .displayListPost>div").promise().done(function() {
				$.get(
						"pages/tagpostlist.jsp", 
					{ 
						"tagid" : id,
						"sortOption" : sortOption
					}, 
					function(data) {
						$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").hide();
						$page.html(data);
						var totalheight   = 0;
						doCufon(function() {
							$("#PostWrapper .displayListPost>div").hide().fadeIn('slow').promise().done(function() {
								$("#PostWrapper .displayListPost").each(function(i, val) {
									 totalheight += Math.round($(val).height()+1);
									return i != 4;
									
								});
								$("#PostWrapper").animate({
									"height" : totalheight
								});
							});
						});
					}
				);
  			});
		},
		
		myposts : function(sortOption) {
			var $page = $('#InnerPostWrapper');
			var $ribbon = $('#RecentTagsList');
			var $titlebanner = $('#DisplayListTop .ribbon');
		
			
			$titlebanner.attr('class', "");
			$titlebanner.addClass("ribbon");
			$titlebanner.addClass("gray");
			$titlebanner.find('h1').text("My Posts");
			
			   $.get('pages/postListTopBar.jsp', { typeOfPostlist : "myposts" }, function (data) {
					$("#Recent").remove();
					$("#TopRated").remove();
					$("#Updates").remove();
				   $('#TopOptions').prepend(data);
			    });
			
			
			$("#PostWrapper .displayListPost").removeClass('golden');
  			$("#PostWrapper .displayListPost>div").fadeOut();
  			$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").show();
  			
  			$("#PostWrapper .displayListPost>div").promise().done(function() {
				$.ajax({ 
						url : "pages/mypostlist.jsp", 
						
							data: "sortOption=" + sortOption,
							
							cache : false,
							
							success : function(data) {
								$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").hide();
								$page.html(data);
								var totalheight   = 0;
								doCufon(function() {
									
									$("#PostWrapper .displayListPost>div").hide().fadeIn('slow').promise().done(function() {
										$("#PostWrapper .displayListPost").each(function(i, val) {
											 totalheight += Math.round($(val).height()+1);
											return i != 4;
											
										});
										$("#PostWrapper").animate({
											"height" : totalheight
										});
									});
									
									
								});
							}
					}
				);
  			});
		},
		

		
		goalpostlist : function(id, sortOption) {
			var $page = $('#InnerPostWrapper');

			var color = "";
			var title = "";
			
			var $ribbon = $('#LeftOptionsList .ribbonmenuoption_id_' + id);
			var classes = $ribbon.attr('class').split(" ");
			for (var i=0; i<classes.length; i++) {
				if (classes[i].indexOf('ribbonmenuoption') == -1) {
					// must be color class name
					color = classes[i];
				}
			}
			
			   $.get('pages/postListTopBar.jsp', { id: id, typeOfPostlist : "goalpostlist" }, function (data) {
					$("#Recent").remove();
					$("#TopRated").remove();
					$("#Updates").remove();
				   $('#TopOptions').prepend(data);
			    });
			
			var $titlebanner = $('#DisplayListTop .ribbon');
			$titlebanner.attr('class', "");
			$titlebanner.addClass("ribbon");
			$titlebanner.find('h1').text($ribbon.find('.RibbonBody a').text());
			$titlebanner.addClass(color.toLowerCase());
			
			$().ajaxStart(function(){
			    
			 }).ajaxStop(function(){
			    
			 });
			
			$("#PostWrapper .displayListPost").removeClass('golden');
  			$("#PostWrapper .displayListPost>div").fadeOut();
  			$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").show();
  			
  			$("#PostWrapper .displayListPost>div").promise().done(function() {
				$.get(
						"pages/goalpostlist.jsp", 
					{ 
						"goalid" : id,
						"sortOption" : sortOption
					}, 
					function(data) {
						$("#MainContent #displayList .displayListPost .PostBody .PostBackground ").hide();
						$page.html(data);
						var totalheight   = 0;
						doCufon(function() {
							$("#PostWrapper .displayListPost>div").hide().fadeIn('slow').promise().done(function() {
								$("#PostWrapper .displayListPost").each(function(i, val) {
									 totalheight += Math.round($(val).height()+1);
									return i != 4;
									
								});
								$("#PostWrapper").animate({
									"height" : totalheight
								});
							});
						});
					}
				);
  			});
  			var $n = $(".displayListPost").size();
			$("#TotalPosts p").text($n);
		},
		
		/*showpostlist : function(id) {
			var $page = $('#PostWrapper');
			
			$page.get(
				"pages/post.jsp", 
				{ 
					"postid" : id,
					"goldenOrNot" : false
				}, 
				function(data) {
					$page.html(data);
					doCufon();
				}
			);
		},*/
		
		deletemessage : function(id, oneOrAll, success) {
			
			$.post(	'Ajax',
					{
						"method" : "deleteMessage",
						"args" : id,
						"oneOrAll" : oneOrAll
					},
					function(data) {
						if (data.success == 'true') {
						
							var $tempMessageCount = parseInt($(".MessagesOptions span").text())-1;
						   
						        //$('#DialogMessageList').remove(data);
						      //  $('#DialogMessageList .Message:first').hide().slideDown();
						  
						    $(".MessagesOptions span").text($tempMessageCount);

						  //  Hash.methods.messagedialog(data.userId);
						    success();
						  
						} else {
							$('#message').html("Something whent wrong: " + data.error);
						}
					}
				);
		
		},
		
		ratekarma : function(id, plusOrMinus, type) {
			
			$.post(	'Ajax',
					{
						"method" : "rate",
						"plusOrMinus" : plusOrMinus,
						"type" : type,
						"id" : id
					},
					function() {
						doCufon();
					});
		
		},
		
		messages : function(id) {
			var $page = $('#InnerContainer');
				$page.load("viewmsgs.jsp", 
					{ 
						"whichMessages" : id 
					},
				function() {
					doCufon();
				});
		
		},
		
		message : function(id) {
			var $page = $('#InnerContainer');
			
			$page.load("viewmsg.jsp", 
					{ "msgid" : id }, function() {
						doCufon();
			});
		},
		
		messagedialog : function(userId) {
			var $page = $('#InnerContainer');
			
			$.post(	'Ajax',
				{
					"method" : "clickMessage",
					"userId" : userId
				},
				function(data) {
					if (data.success == 'true') {
						// do nothing
					} else {
						$('#message').html("Something whent wrong: " + data.error);
					}
				}
			);
			
			$page.load("viewmsgswithuser.jsp", 
					{ "userid" : userId }, 
					function() {
						doCufon();
						
			});
		},
		
		editprofile : function() {
			var $page = $('#InnerContainer');
			
			$page.load("editprofile.jsp", function() {
				doCufon();
			});
		},
		
		sendmessage : function(id) {
			var $page = $('#InnerContainer');
			
			$page.load("sendmsg.jsp", 
					{ "userid" : id }, function() {
						doCufon();
			});
		},
		
		addpost : function() {
			var $page = $('#InnerContainer');
			
			$page.load("createpost.jsp", 
					{
				"type" : "nogoal"
					},
					function() {
						doCufon();
			});
		},
		
		addpostwithgoal: function(id) {
			var $page = $('#InnerContainer');
		
			$page.load("createpost.jsp",
					{
				"goalId" : id,
				"type" : "goal"
				},
					function() {
						$(".choosegoal").val(id);
						Hash.methods.goalpost($(".choosegoal").val());
						Hash.methods.suggesttags($(".postform_tags_hidden"), "Goal", $(".choosegoal").val(), $(".goaltags"));
						$("#hiddenpercentbox, #Postsfromgoal").fadeIn();
						doCufon();
						
			});
		},
		
		editpost : function(id) {
			var $page = $('#InnerContainer');

				$page.load
				("editpost.jsp", 
					{
					"postid" : id
					},
					function() {
					doCufon();
			});	
		},
		
		
		posttags : function(id) {
			var $page = $(".Postaglist");
			$page.load(
			"pages/posttaglist.jsp",
					{
						"postId" : id
					},
					function() {
						doCufon();
					});
		},
		
		goalpost : function(id) {
			var $page = $("#Postsfromgoal");
			
			$page.load(
			"pages/postlist.jsp",
			{
				"goalId" : id
			},
			function() {
				doCufon();
			}
			);
		},
		
		
		addprogress : function(id) {
			var $page = $('#InnerContainer');
			
			$page.load("adddiary.jsp",
						{ "goalid" : id },
						function() {
							doCufon();
						});
		},
		
		
		index : function() {
			window.location = "index.jsp";
		},
		
		
		viewgoal : function(id){
			var $page = $('#InnerContainer');
			$page.load("viewgoal.jsp", 
					{"goalid": id},
					function() {
						doCufon();
					});
		},
		
		editgoal : function(id) {
			var $page = $('#InnerContainer');
			$page.load("editgoal.jsp" ,
					{"goalid" : id},
					function() {
						doCufon();
					});
		},
		
		
		subscribers : function() {
			var $page = $('#InnerContainer');
			$page.load("subscribers.jsp" ,
					{
				
					},
					function() {
					doCufon();	
					});
		},
		
		subscriptions : function() {
			var $page =$('#InnerContainer');
			$page.load("mysubscriptions.jsp" , 
					{
				
					},
					function() {
						doCufon();
					});
		},
		
		
		checkemail : function(temp, success, failure) {
			$.post("Ajax", {
				"method" : "check",
				"type" : "email",
				"temp" : temp
			},
			function(data) {
				//if true then the the email isn't in use atm
					if(data.result == true) {
						success();
					} else {
						failure();
					}	
			});
		},
		
		checkusername : function(temp, success, failure){
			$.post("Ajax", {
				"method" : "check",
				"type" : "username",
				"temp" : temp
			},
			function(data) {
				//if true then the the username isn't in use atm
					if(data.result == true) {
						success();
					} else {
						failure();
					}	
			});
		},
		
		//Suggest tags
		suggesttags : function($tagfield, type, typeId, $listen){
			$.post("Ajax" , {
				
				"method" : "suggest",
				"tagfield" : $tagfield.val(),
				"type" : type,
				"typeId" : typeId
			},
			function(data) {
				if(data.success){
					$listen.empty();
					for( var i in data.tags) {
						$listen.append('<li><a href="#">'+data.tags[i].name+'</a></li>');
					}
					
				}
			});
		},
		
		
		//published goal popup
		opengoalcomplete : function(id) {
			PopupCompletedGoal.open(this);
			$("#hiddengoalfield").val(id);
		},
		
		closegoalcomplete : function() {
				PopupCompletedGoal.close(this);
		},
		
		publishgoal : function () {
			var id =  $("#hiddengoalfield").val();
			PopupCompletedGoal.close(this);
			$.post("Ajax", {
				"method" : "publishgoal",
					"id" : id },
					function(){
						Hash.methods.index();
						}
			);
		},
		
		
		
		//CRUD GOAL FUNTIONS
		
		goalupdate : function(id) {
			
			$.post("Ajax",  {
				"method" : "updateGoal",
				"id" : id });
		},
		
		creategoal : function() {
			var $page = $('#InnerContainer');
			$page.load("creategoal.jsp" ,
					function() {
					doCufon();	
					});
		},
		
		//Sub and unSub Functions
		
		
		subscribe : function(subtoId) {
			$.post("Ajax" , {
				"method" : "subbing",
				"subtoId" : subtoId,
				"type" : "sub"
			}, function() {
				Hash.methods.viewuser(subtoId);				
			});
		},
		
		unsubscribe : function(subtoId) {
			$.post("Ajax" , {
				"method" : "subbing",
				"subtoId" : subtoId,
				"type" : "unsub"
			}, function() {
				Hash.methods.viewuser(subtoId);
			});
			
		},
		
		
		
		//CRUD POSTCOMMENT, GOALCOMMENT
		
		postcomment : function() {
			
			$.post("Ajax" , {
				"method" : "comment",
				"type" : "post"
			});
		},
		
		goalcomment : function() {
			
			$.post("Ajax" , {
				"method" : "comment" ,
				"type" : "goal"
			});
		},
		
		//CRUD POST FUNCTIONS
		postcreate : function(id) {
			
			$.post("Ajax", {
				"method" : "createPost",
				//"action" : 'delete',
				"id" : id});
		},
		
		postupdate : function(id) {
			$.post("Ajax", {
				"method" : "updatePost",
				"id" : id
			});
		}
	}
};
