// Roman Hrypa
// imp->OV start
//impRater = function(uid, items_count, set_thru, tuid, tname) {
impRater = function(uid, items_count, set_thru, tuid, tname, tname_language, language_uid){
// imp->OV end
	this.uid = uid;
	this.pos = 0;
	this.items_count = items_count;
	this.set_thru = set_thru;
	this.tuid = tuid;
	this.tname = tname;
// imp->OV start
	this.tname_language = tname_language;
	this.language_uid = language_uid;
// imp->OV end
	this.main_obj = document.getElementById('impRater' + uid);
	this.floatEl = document.getElementById('impRaterFloatEl' + uid);
	this.actEl = document.getElementById('impRaterActDiv' + uid);

	if(!this.main_obj) return false;
	this.width = (this.main_obj.clientWidth) ? this.main_obj.clientWidth : this.main_obj.offsetWidth;
	this.height = (this.main_obj.clientHeight) ? this.main_obj.clientHeight : this.main_obj.offsetHeight;

	this.item_width = (this.items_count > 0 ? Math.floor(this.width / this.items_count) : 0.001);

	var obj = this;


	if(this.floatEl) {
		this.main_obj.onmousemove = function(e) {
		//	var eX = (window.event ? window.event.x : e.layerX);
			var eX = ( navigator.userAgent.indexOf("MSIE") > -1 ? window.event.x : e.layerX );
			obj.pos = Math.ceil(eX/obj.item_width);
			obj.floatEl.style.width = (obj.pos * obj.item_width) + "px";
		}

		this.main_obj.onclick = function(e) {
			obj.saveRating();
// imp->OV start
			var items = $('.'+obj.tname + '_' + obj.tuid);
			var len = items .length;
			for(var i = 0; i<len ; i++){
				if(items[i].id != ('impRater'+obj.uid)){
					item_uid = items[i].id;
					eval(''+item_uid+'.saveRating();')
				}
			}
// imp->OV end
		}

		this.main_obj.onmouseout = function(e) {
			obj.floatEl.style.width = 0 + "px";
		}
	}

	// save rating here
	this.saveRating = function() {
		if(this.set_thru == "ajax") {
			var base_url = '';
			$.ajax({
				url: base_url + "index.php?eID=imp_rating_ajax",
				data:"ajaxData=on&pos="+this.pos+"&tuid="+this.tuid+"&tname="+this.tname+"&language_uid="+this.language_uid+"&tname_language="+this.tname_language,
				type: "POST",
				async: false,
				success: function(responseText){
			    	obj.killEl(obj.floatEl);
					obj.killEv();

					if(!$(obj.main_obj).hasClass('imp-rater-lock')) {
						$(obj.main_obj).addClass('imp-rater-lock');
					}
					var exp = new Date();
					var expires= exp.getTime()+(1000*60*60*24);
					exp.setTime(expires);
					expires = 'expires=' + exp.toGMTString();
// imp->OV start
					//document.cookie = 'imp_rating[' + obj.tname + '][' + obj.tuid + ']=1;' + expires;
					cookie_path = 'path=/';
					document.cookie = 'imp_rating[' + obj.tname + '][' + obj.tuid + '][' + obj.language_uid + ']=1;' + expires+ ';'+cookie_path;
// imp->OV end
					obj.setRating(responseText);

			   	}
			});
		} else {
			// --- form ---
		}
	}

	this.killEl = function(el) {
		var pNode = el.parentNode;
		pNode.removeChild(el);
	}

	this.killEv = function() {
		this.main_obj.onmousemove = null;
		this.main_obj.onclick = null;
		this.main_obj.onmouseout = null;
	}

	this.setRating = function(r) {
		this.actEl.style.width = ((r / this.items_count) * this.width) + "px";
	
	}

	// ---------------------
}
