/*
 * JavaScript interface to the SB network.
 * class SB.rating - rating management
 *
 * Requirements: jQuery library 1.4.2 and above
 * Copyright (C) 2010 Tomas Hnilica.   All Rights Reserved.
 */



SB.rating = function(cid) {
	this.DOM = $("#rating-" + cid);
	this.id = cid;
	this.topic = $("#rating-" + cid).attr('topic');
}

/** initialize*/
SB.rating.prototype.init = function() {
			$("#rating-" + this.id + "-avg").stars();
			var context = this;
			$("#rating-" + this.id + "-rate").stars({
				inputType: "select",
				cancelShow: false,
				captionEl: $("#rating-" + this.id + "-caption"),
				callback: function(ui, type, value)
				{
					
					thConfirm("Hodnotit známkou " + value + "?","Známkovat", function(ret) {
						if (!ret) return false;
						ui.disable();
						$("#messages").text("Ukládání...").stop().css("opacity", 1).fadeIn(30);
						var params = {}
						params["thread"] = context.id;
						params["points"] = value;
						params["author"] = context.DOM.attr("author");
						params["ref_subject"] = context.DOM.attr("ref_subject");
						params["ref_id"] = context.DOM.attr("ref_id");
						$.post("/ws/?ws=addRating", params, function(data){
					     thAlert("Děkujeme za Vaše hodnocení.","Známka uložena");
					     if (SBuser) {
					       var link = jQuery.url.attr("path"); 
					       SBuser.addActivity("ohodnotil [[a href='"+link+"' ]]"+context.topic+"[[/a]]", "comment", context.id, link, context.DOM.attr("author") );
					       /*
					       sbp = new SB.profile(SBuser.uid);
					       sbp.updatePoints(4);
					       */
					     }
					     
						});	
						
					});


				}
			});
			$("#" + this.id + "-rate").stars("selectID", -1);
			$('<div id="messages"/>').appendTo("#" + this.id + "-rate");

}

SB.comment.prototype.rate = function() {

}


