
initCommentLinks = function (groupid, type, userimage, eventid) {
	if (type == 'forum') {
		var container = $("#forum");
		postaction = "/ajax/forumpost.php";
		var pageview = '/vpv/event/comment';
	} else {
		var container = $("#groupwall");
		postaction = "/ajax/wallcomment.php";
		var pageview = '/vpv/groupwall/comment';
	}
	$(container).delegate("a.commentlink", "click", function () {
		var commentlink = $(this);
		var wallpostid = $(this).attr("rel");
		$(commentlink).next().append('<div class="commentform"><hr class="light"><div class="grid_2 alpha" align="right"><img src="' + userimage + '" width="36"></div><div class="grid_10 alpha"><textarea class="grid_8 alpha"></textarea><button class="small">Kommenter</button>&nbsp;<a href="#" class="small undo">Fortryd</a></div></div>');
		$(commentlink).hide();
		$("div.commentform a.undo").click(function () {
			$(commentlink).show();
			$("div.commentform").remove();
			return false;
		});
		$("div.commentform button").click(function() {
			var text = $('div.commentform textarea').val();
			if (text == '') {
				$('<div class="notice">Skriv kommentaren inden du klikker på knappen ;)</div>')
					.insertAfter( $(this).next() )
					.fadeIn('slow')
					.animate({opacity: 1.0}, 2000)
					.fadeOut('slow', function() {
					  $(this).remove();
					});
				return false;
			}
			if (wallpostid) {
				//alert(wallpostid);
				$.post(postaction, { text: text, group_id: groupid, post_id: wallpostid, event_id: eventid},
					  function(data){
						//console.log(data);
						//alert(data.content.text);
						$(commentlink).next('.postcomments').append('<div class="postcomment">'
								+ '<a href="#" class="remove" rel="' + data.content.postid + '">&nbsp;</a>'
								+ '<div class="grid_2 alpha" align="right"><img src="' + data.content.userimg + '" width="36"></div>'
								+ '<div class="grid_10 alpha"><strong>' + data.content.usernick + '</strong> '
								+ data.content.text + ' <span class="timestamp">' + data.content.time + '</span> '
								+ '</div><div class="clear"></div></div>');
						$(commentlink).show();
						$("div.commentform").remove();
						_gaq.push(['_trackPageview', pageview]);
					  }, "json");
			} else {
				alert("JS fail: The answer could not be created: questionid missing");
			}
		});
		return false;
	});

	$("#groupwall").delegate('div.wallpost > a.remove', "click", function () {
		var post_id = $(this).attr("rel");
		var postdiv = $(this).parent();
		if (confirm('Ønsker du at slette denne post og alle kommentarer til den?')) {
			$.post("/ajax/wallpost.php", {group_id: groupid, delpost: post_id},
				  function(data){
					if (data.status == 'ok') {
						$(postdiv).fadeOut();
					} else {
						alert(data.content);
					}
				  }, "json");
		}
		return false;
	});

	$("#groupwall").delegate('div.postcomment a.remove', "click", function () {
		var comment_id = $(this).attr("rel");
		var commentdiv = $(this).parent();
		if (confirm('Ønsker du at slette denne kommentar?')) {
			$.post("/ajax/wallcomment.php", {group_id: groupid, delcomment: comment_id},
				  function(data){
					if (data.status == 'ok') {
						$(commentdiv).fadeOut();
					} else {
						alert(data.content);
					}
				  }, "json");
		}
		return false;
	});
}

init_placeholderfallback = function () {
	//if(!jQuery('<input placeholder="1" />')[0].placeholder){
	if(true){
		jQuery(':input[placeholder]').each(function(){
			var $this = $(this);
			if($this.val() == $this.attr('placeholder') ) {$this.val('');}
			if(!$this.val()){
				$this.val($this.attr('placeholder'));
				$this.addClass('input-placeholder');
			}
		}).live('focus', function(e){
			var $this = $(this);
			if($this.hasClass('input-placeholder')){
				$this.val('');
				$this.removeClass('input-placeholder')
			}
		}).live('blur', function(e){
			var $this = $(this);
			if(!$this.val()){
				$this.addClass('input-placeholder');
				$this.val($this.attr('placeholder'));
			}
		});
	}
}
