
/*

*/

OTS.raterReqURL = "/community/ajax/ajax_rater.html";
OTS.rater = function(oid, id, avg, loggedin, named) {
	this.oid = oid;
	this.named = named;
	this.id = id;
	this.avg = avg;
	this.loggedin = loggedin;
	this.sw = 15;
 	/*this.init_value=init_value;*/
	this.init();
}
OTS.rater.prototype.init = function() {
	this.title = '';
	this.voted = false;
	this.rObj = document.getElementById('rater' + this.oid + '');
	if (!this.rObj) return;
	this.rObj.className = 'rater';
	
	var html = '<ul>';
	html += '<li class="rater_curr"></li>';
	html += '<li><a href="#" class="stars1">1</a></li>';
	html += '<li><a href="#" class="stars2">2</a></li>';
	html += '<li><a href="#" class="stars3">3</a></li>';
	html += '<li><a href="#" class="stars4">4</a></li>';
	html += '<li><a href="#" class="stars5">5</a></li>';
	html += '</ul><input type="hidden" id="rater' + this.oid + '_rating" name="' + this.named + '" value="' + this.avg + '" />';
	
	/*rater' + this.oid + '_rating;*/
	this.rObj.innerHTML = html;
	this.vObj = document.getElementById('rater' + this.oid + '_rating');
	
	var refs = this.rObj.getElementsByTagName('a');
	for (var i = 0; i < refs.length; i++) {
		var r = this.rObj.getElementsByTagName('li');
		refs[i].o = r[0];
		refs[i]._this = this;
		refs[i].onmouseover = function() {
			this._this.showDesc(this.innerHTML);
		}
		refs[i].onmouseout = function() {
			this._this.hideDesc();
		}
		refs[i].onclick = function() {
			this._this.set(this.o, this.innerHTML);
			this._this.record(this.innerHTML);
			this._this.hideDesc();
			return false;
		}
	}
	
	this.load(this.avg);
	this.makeTxtObj();
}
OTS.rater.prototype.setFormValue = function() {
	
}
OTS.rater.prototype.makeTxtObj = function() {
	this.rTxtObj = document.createElement('div');
	this.rTxtObj.id = 'rater' + this.oid + '_txt';
	this.rTxtObj.className = 'rater_txt';
	this.rObj.appendChild(this.rTxtObj);
	/*if (this.rr) this.title = this.rr.innerHTML;*/
}
OTS.rater.prototype.showDesc = function(s) {
	var obj = this.rTxtObj;
	if (!obj) return;
	if (!OTS.raterTxtObj) return;
	/*if (this.voted == true) return;*/
	var str = '';
	if (this.loggedin == false) {
		str = OTS.raterTxtObj.t0;
	} else {
		if (s == '1') {
			str = OTS.raterTxtObj.t1;
		} else if (s == '2') {
			str = OTS.raterTxtObj.t2;
		} else if (s == '3') {
			str = OTS.raterTxtObj.t3;
		} else if (s == '4') {
			str = OTS.raterTxtObj.t4;
		} else if (s == '5') {
			str = OTS.raterTxtObj.t5;
		}
	}
	obj.style.display = 'block';
	obj.innerHTML = '<span>' + str + '</span><b></b>';
}
OTS.rater.prototype.hideDesc = function() {
	var obj = this.rTxtObj;
	if (!obj) return;
	obj.style.display = 'none';
	/*obj.innerHTML = this.title;*/
}
OTS.rater.prototype.load = function(avg) {
	var o = this.rObj;
	if (!o) return;
	var r = o.getElementsByTagName('li');
	this.setAvg(r[0], avg);		
}
OTS.rater.prototype.setAvg = function(o, v) {
	if (!o) return;
	o.style.width = parseInt(this.sw * v) + 1 + 'px';
}
OTS.rater.prototype.set = function(o, v) {
	if (this.loggedin == true) {
		this.setAvg(o, v);
	}
}
OTS.rater.prototype.record = function(v) {
	if (this.loggedin == true) {
		/*var u = OTS.raterReqURL + '?cid=' + this.oid + '&id=' + this.id + '&rate=' + v;*/
		this.vObj.value = v;
		this.voted = true;
	} else {
		/* Do Login */
	}
}
