/*
* @el id of div element where will be placed stars
* @url url to template (for including images)
* @max max rating
* @text text
* @class_id unique adds for ids
*/
	var int__switch=false;
	commentRating = function(el, url, max, text, class_id)
	{
		this.element = document.getElementById(el);
	
		this.class_id = class_id;	
		this.numStars = max;
		this.URL = url;
		this.text = text;
		
		this.init();
	}

	commentRating.prototype = 
	{
		init:function()
		{
			if(this.element)
			{
				this.printStars();
			}
		},
		
		printStars:function()
		{
			var html = '';
			var css = '';
	
			css = "background: url('" + this.URL + "/img/gray.png'); ";
			css += "width: 15px; height: 15px; ";
			css += "cursor: pointer; ";
			css += "float: left;";
	
			for(var i = 1; i <= this.numStars; i++)
			{
				html += '<div style="' + css + '" ';
				html += 'id="'+this.class_id+'rate' + i + '"';
				html += ' ></div>';
			}
	
			html += '<div id="'+this.class_id+'rate_text" style="float: left; font-size: 11px; padding-left: 5px;">&nbsp;</div>';
			html += '<input type="hidden" name="rating" id="'+this.class_id+'rating" value="" />';
	
			this.element.innerHTML = html;
	
			for(var i = 1; i <= this.numStars; i++)
			{
				this.attachEvent(this.class_id+'rate' + i, i);
			}
		},
	
		attachEvent:function(el, item)
		{
			var class_id = this.class_id;
			var el = document.getElementById(el);
			var rateText = document.getElementById(class_id+'rate_text');
				
			var numStars = this.numStars;
			var URL = this.URL;
			var text = this.text;
			var rating = document.getElementById(class_id+'rating');
			var clicked = false;
	
			el.onmouseover = function()
			{
				if (!int__switch)
				{
					for(var i = 1; i <= numStars; i++)
					{
						var star = document.getElementById(class_id+'rate' + i);
						star.style.background = "url('" + URL + "/img/gray.png')";
					}
					
					// selected new stars
					for(var i = 1; i <= item; i++)
					{
						var star = document.getElementById(class_id+'rate' + i);
						star.style.background = "url('" + URL + "/img/gold.png')";
						rateText.innerHTML = text + '&nbsp;:&nbsp;' + i;
					}
				}
			}
			el.onmouseout = function()
			{
				if(!int__switch)
				{
					for(var i = 1; i <= item; i++)
					{
						var star = document.getElementById(class_id+'rate' + i);
						star.style.background = "url('" + URL + "/img/gray.png')";
						rateText.innerHTML = '&nbsp;';
					}
					rating.value = '';
				}
			}
			el.onclick = function()
			{
				if(!int__switch)
				{
					for(var i = 1; i <= item; i++)
					{
						var star = document.getElementById(class_id+'rate' + i);
						star.style.background = "url('" + URL + "/img/gold.png')";
					}
		
					rating.value = item;
					clicked = true;
					int__switch=true;
				}
			}
		}
	}
