

	





document.write('<div id="comments_0_1329845259678_n7B9hmpV" class="commentContext_0"></div>');
jQuery(function() {
	var el = jQuery("#comments_0_1329845259678_n7B9hmpV");
	
	var comments = jQuery("<div></div>");
	comments.addClass("commentsList");
            comments.addClass("latestComments");
    	
	var redraw = function() {
		comments.quickPager({pageSize:10, pagerLocation: "before"});
	}
	el.data("redraw", redraw);
	
	var refreshGuestbook = function(timedRefresh, callback) {
		clearTimeout(refreshTimer);
		if (!timedRefresh) {
			comments.addClass("commentsListLoading");
		}
		jQuery.getScript("http://parts.cupmanager.net/390812,sv/comments/refreshComments/0/0_1329845259678_n7B9hmpV/5/readOnly", function() {
			comments.removeClass("commentsListLoading");
			redraw();
			if (typeof callback == "function") {
				callback();
			}
		});
	};
	el.data("refreshGuestbook", refreshGuestbook);
	
	var refreshTimer = function() {
		setTimeout(function() {
			refreshGuestbook( true, refreshTimer );
		}, 1*60*1000);
	};
	refreshTimer();
	el.data("refreshTimer", refreshTimer);
	
	function deleteCommentClick(a, commentId) {
		CupMan.callService("website.DeleteCommentService", {
			data: {
				commentId: commentId
			},
			success: function() {
				var commentId = a.closest(".comment").attr("commentId");
				jQuery("div.comment[commentId='"+commentId+"']").slideUp(function() {
					jQuery(this).remove();
				});
			}
		});
		return false;
	}
	el.data("deleteCommentClick", deleteCommentClick);
	
	
	
	function buildReplyWriter(parentId, callback) {
		
		var buildFunc = function(uid) {
			var writer = jQuery("<div/>");
			writer.addClass("writer");
			writer.addClass("commentsWriter");
			
			var img = '<img width="32" src="http://static.cupmanager.net/images/silhouette.jpg" />';
			var name = '<span>$wr.user.person.name.name (admin)</span>';
			if (uid) {
				img = '<fb:profile-pic size="square" width="32" height="32" uid="'+uid+'" />';
				name = '<fb:name linked="false" useyou="false" uid="'+uid+'" />';
			}
			
			name += " replies:";
			
			var table = jQuery('<table><tr><td valign="top" align="left"></td><td valign="top" align="left"></td></tr></table>');
			
			table.find("td:first").html(img);
			table.find("td:first").addClass("profilePic");
            
			var closer = jQuery('<a href="#">X</a>');
			closer.addClass("closer");
			closer.hover(function() {
				jQuery(this).addClass("closerHover");			}, function() {
				jQuery(this).removeClass("closerHover");
			});
			closer.click(function() {
				writer.hide();
				return false;
			});
			
			
			table.find("td:last").html(name);
			
			table.find("td:last").prepend(closer);
			table.find("td:last").append("<br/>");
			
			var body = jQuery("<textarea></textarea>");
			body.height(16);
			body.autoResize({
			    // Quite slow animation:
			    animateDuration : 300,
			    // More extra space:
			    extraSpace : 16
			});
			
			table.find("td:last").append(body);
			
			var button = jQuery("<button></button>");
			button.attr("type", "button");
			table.find("td:last").append(button);
			button.html("Comment");
            button.css("margin-top","3px");
            button.css("margin-right","4px");
			
			button.click(function() {
				var data = {
					body: body.val(),
					contextId: 0,
					parentId: parentId
				};
				CupMan.callService("website.PostCommentService", {
					data: data,
					success: function() {
						jQuery(".commentContext_0").each(function() {
							var func = jQuery(this).data("refreshGuestbook");
							func();
							body.val("").blur();
							closer.click();
						});
					}
				});
			});
			
			button.css("display", "block");
			button.wrap("<div></div>").parent().attr("align", "right");
			
			button.hide();
			body.focus(function() {
				button.show();
			});
			body.blur(function() {
				if (jQuery(this).val() == "")  {
					button.hide();
					body.height(16);
				}
			});
			
			writer.append(table);
			
			// Return
			callback(writer);
		};
		
		ensureFacebookInit(function() {
			FB.getLoginStatus(function(response) {
				buildFunc();
			});
		});
	}
	
	var evenCounter = 0;
	function buildComment(commentId, body, name, pic, date, context, uid, parentId) {
		var div = jQuery("<div/>");
		div.addClass("comment");
		var isAdmin = (!uid || uid == "");
		if (isAdmin)
		{
			div.addClass("adminComment");
		}
		
		// div.css("position", "relative");
		
		
		
		
		div.attr("commentId", commentId);
		
		div.attr("id", "comment_"+commentId+"_0_1329845259678_n7B9hmpV");
		
		div.hover(function() {
			jQuery(this).addClass("commentHover");
		}, function() {
			jQuery(this).removeClass("commentHover");
		});
		
		var table = jQuery('<table><tr><td valign="top" align="left"></td><td valign="top" align="left"></td></tr></table>');
		table.width("100%");
		// table.css("position", "relative");
		
        
		var first = table.find("td:first");		
		var second = table.find("td:last");
		
				
	    first.html(pic);
        first.width(35);
        first.addClass("profileCell");
        
		var nameContainer = jQuery("<span>");
        nameContainer.addClass("nameContainer").addClass("notranslate"); 
					nameContainer.append("<small>"+CupMan.Name.formatNiceDate(new Date(date))+"</small>");
			nameContainer.find("small").addClass("time").attr("time", date);
				
					nameContainer.append("<small>&nbsp;om </small>");
			
			var contextLink = jQuery('<a href="#"></a>');
			contextLink.html(context.title);
			contextLink.attr("href", context.url);
			nameContainer.append(contextLink);
			contextLink.wrap("<small/>");
                
                    div.append(nameContainer);
        		
		
		second.append("<span>"+body+"</span>");
		second.find("span:last").addClass("body");
		
		second.attr("valign", "top");
		
		//////
		var xact = jQuery("<div/>");
		xact.addClass("commentXact");
		xact.addClass("notranslate");
		
				
				
				
		second.append(xact);
		
		div.append(table);
		
                    evenCounter++;
            if (evenCounter % 2 == 0)
            {
                table.find("td:first").before( table.find("td:last") );
                div.addClass("rightieComment");
            } else {
            	div.addClass("leftieComment");
            }
                
				
		return div;
	}
	el.data("buildComment", buildComment);
	
	
		
	
			
								
					
							
		var div = buildComment(500477, 'Fixa g&auml;rna s&aring; att det g&aring;r att se bilderna!', '<fb:name uid="1492340665" />', '<fb:profile-pic size="square" width="32" height="32" uid="1492340665" />', 1320243487997, {url:'http://vintrosa.cups.nu/sv/start', title:'Hem'}, '1492340665', 0);
				comments.append(div);
				
								
					
							
		var div = buildComment(457371, 'Nej, men anm&auml;laren kommer d&auml;r ifr&aring;n. Haha!', '<fb:name uid="589608561" />', '<fb:profile-pic size="square" width="32" height="32" uid="589608561" />', 1312528879365, {url:'http://vintrosa.cups.nu/2011,sv/result/club/441136#results', title:'Almunge IK'}, '589608561', 0);
				comments.append(div);
				
								
					
							
		var div = buildComment(457341, 'Lycka till med att f&ouml;rsvara f&ouml;rsta platsen', '<fb:name uid="100000669840541" />', '<fb:profile-pic size="square" width="32" height="32" uid="100000669840541" />', 1312472201388, {url:'http://vintrosa.cups.nu/2011,sv/result/club/441136#results', title:'Almunge IK'}, '100000669840541', 0);
				comments.append(div);
				
		
	ensureFacebookInit(function() {
		FB.XFBML.parse();
	});
	
	el.append(comments);
	
	redraw();
	if ( comments.parent().children("ul").size() > 0 ) {
		comments.parent().children("ul").css("display", "inline");
		var pageSpan = jQuery("<span>Sida:</span>")
		pageSpan.css("float", "left");
		comments.parent().prepend(pageSpan);
	}
	comments.css("clear", "left");
	
			el.addClass("commentsEmpty_false");
		el.parent().addClass("commentsEmpty_false");
	});
