﻿var domain = document.domain;

$(function() {
	$("a[ugcId]").click(function(event) {
		event.preventDefault();

		var ugcId = $(this).attr("ugcId");
		var id = $(this).attr("id");

		$.get("http://" + domain + "/WebServices/GetFeedback.aspx?uid=" + ugcId, function(data) {

			var snippet = $("snippet", data).text();
			var feedback = $("feedback", data).text();

			if ($("#" + id).text() == "Read more") {

				$("a[ugcId]").each(function() {
					var ugcIdAll = $(this).attr("ugcId");
					var idAll = $(this).attr("id");

					if ($("#" + idAll).text() == "Show less") {
						$.get("http://" + domain + "/WebServices/GetFeedback.aspx?uid=" + ugcIdAll, function(data) {

							snippetAll = $("snippet", data).text();
							$("#" + idAll).text("Read more");
							$("#" + idAll).parent().prev().children().next().text(snippetAll);
							
							$("#" + idAll).corner();
						});												
					}
				});
				
				$("#" + id).text("Show less");
				$("#" + id).parent().prev().children().next().text(feedback);				
			}
			else {
				$("#" + id).text("Read more");
				$("#" + id).parent().prev().children().next().text(snippet);
			}
			
			$("#" + id).corner();
		});		
	});
});