// rating system object
function kap_starSystem(type, size, stats) {
	// store the stats for the object
	this.stats = stats;
	// store the size of it
	this.size = size;
	// what type of star system it is
	this.type = type;
	// what the average of it is
	this.avg = stats.avg;
	// variable to store the sytem for access
	this.system = null;

	// create the system
	starList = document.createElement('ul');
	starList.className = 'ka_starSystem' + size;

	// add the stars
	for (var x = 0; x < 5; x++) {
		// new list item
		starListItem = document.createElement('li');
		// if it's the large system
		if (size == 'L') {
			// add an id
			starListItem.id = 'ka_starL' + (x + 1);
		}
		// the classs (depending on what the avg is)
		starListItem.className = (x + 1) <= stats.avg ? ' ka_starSelected' + size : 'ka_star' + size;
		// the inner linkthis.
		starListItemLink = document.createElement('a');
		starListItemLink.innerHTML = '&nbsp;';
		// what the links points to
		starListItemLink.href = 'Javascript: ;';
		// the mouse pointer above the href
		// if it's to rate (not view)
		if (this.type == 'rate') {
			// add the onmouseover event
			starListItemLink.onmouseover = function () {
				// get the li nodes
				liNodes = starList.getElementsByTagName('li');

				// highlight nothing
				for (var q = 0; q < 5; q++) {
					// change them all to off
					liNodes[q].className = 'ka_star' + size;
				}
				// highlight this
				this.parentNode.className = 'ka_starHighlight' + size;

				// change the ones less than it into different classes
				for (var q = 0; q < 5; q++) {
					// if the current one is not the one in this iteration of the loop
					if (liNodes[q] != this.parentNode) {
						// highlight it
						liNodes[q].className = 'ka_starHighlight' + size;
					}
					// otherwise it is
					else {
						// break the loop
						break;
					}
				}
			};
			// add the onmouseout event
			starListItemLink.onmouseout = function () {
				// get the li nodes
				liNodes = starList.getElementsByTagName('li');

				// highlight nothing
				for (var q = 0; q < 5; q++) {
					// change them all to off
					liNodes[q].className = 'ka_star' + size;
				}
				// highlight stars to be the average
				for (var q = 0; q < stats.avg; q++) {
					// highlight it
					liNodes[q].className = 'ka_starSelected' + size;
				}
			};
			// add the onclick event
			starListItemLink.onclick = function () {
				// blur it
				this.blur();

				// get the li nodes
				liNodes = starList.getElementsByTagName('li');

				// make it DANCE
				kap_starsBlink(liNodes, this, size, 0);
				// variable to store the value of the rating
				var ratingValue;

				// remove any effects
				for (var q = 0; q < 5; q++) {
					// remove the onmouseover event
					liNodes[q].getElementsByTagName('a')[0].onmouseover = function () {};
					// remove the onmouseout event
					liNodes[q].getElementsByTagName('a')[0].onmouseout = function () {};
					// remove the onclick event
					liNodes[q].getElementsByTagName('a')[0].onclick = function () {};

					// change them all to the default mouse cursor
					liNodes[q].getElementsByTagName('a')[0].style.cursor = 'default';

					// if this' parent and the node are equal
					if (liNodes[q] == this.parentNode) {
						// mark that the rating value
						ratingValue = q + 1;
					}
				}

				// DWR call to inser the rating
				kap_rateMedia(ratingValue);

				// change the numRatings text
				$('ka_starRatingSubText').innerHTML = Ka.Messages.PlayPage.THANKSFORTHEVOTE + ' ' + Ka.Messages.Common.APPENDTOCONFIRMATIONMSG.replace('($siteName)', Ka.Info.SITENAME);
			};
		}

		// add it to the item
		starListItem.appendChild(starListItemLink);
		// add it to the list
		starList.appendChild(starListItem);
	}

	// if it's just to view
	if (type == 'view') {
		// get the li nodes
		liNodes = starList.getElementsByTagName('li');

		// remove any effects
		for (var q = 0; q < 5; q++) {
			// change them all to the default mouse cursor
			liNodes[q].getElementsByTagName('a')[0].style.cursor = 'default';
		}
	}

	// if it's the media play page
	if (Ka.Info.PAGE == 'pages/mediaPlayPage.jsp' || Ka.Info.PAGE == 'pages/kickPlaceServerSide.jsp') {
		// if the user isn't logged in
		if (Ka.Info.USERID == '') {

			// get the li nodes
			liNodes = starList.getElementsByTagName('li');

			// add effects
			for (var q = 0; q < 5; q++) {
				// change them all to the pointer mouse cursor
				liNodes[q].getElementsByTagName('a')[0].style.cursor = 'pointer';
			}
			// add an onclick for the ul
			//starList.onclick		=	function() { ka_toggleDiv('#ka_loginPopup'); };
			// add an onclick for the li's
			for (var i = 0; i < liNodes.length; i++) {

				// add the onmouseover event
				liNodes[i].onmouseover = function () {
					// highlight this
					this._oldClassName = this.className;
					this.className = 'ka_starHighlight' + size;
				};

				// add the onmouseout event
				liNodes[i].onmouseout = function () {
					// highlight it
					this.className = this._oldClassName;
					//this.className = 'ka_star'+size;

				};

				// liNodes the onclick event
				liNodes[i].onclick = function () {
					Ka.popup('#ka_loginPopup');
					return false;
				};

			}
		}
	}

	// store the system object
	this.system = starList;

	// method to show the system
	this.show = function (divId) {
		// write it to the div
		$(divId).appendChild(this.system);

		// span to display the number of ratings
		numRatingsSpan = document.createElement('span');
		numRatingsSpan.className = 'ka_starsNumRatings' + size;
		numRatingsSpan.id = 'ka_starRatingSubText';
		// write in the number of ratings
		// numRatings                  =    document.createTextNode('('+this.stats.numRatings+' Rating'+(this.stats.numRatings==1 ? '' : 's')+')');
		numRatings = document.createTextNode("(" + (this.stats.numRatings == 1 ? Ka.Messages.PlayPage.RATING.replace('($count)', this.stats.numRatings) : Ka.Messages.PlayPage.RATINGS.replace('($count)', this.stats.numRatings)) + ")");
		numRatingsSpan.appendChild(numRatings);
		// show it to the div
		$(divId).appendChild(numRatingsSpan);
	};
}
// function to handle the blinking of the stars
function kap_starsBlink(liNodes, lastLi, size, itCount) {
	// if the iteration count is less than 2
	if (itCount < 2) {
		// change the ones less than it into different classes
		for (var q = 0; q < 5; q++) {
			// turn it off
			liNodes[q].className = 'ka_star' + size;
		}

		// show it
		setTimeout(
		function () {
			// highlight the 'this' one
			lastLi.parentNode.className = 'ka_starHighlight' + size;

			// change the ones less than it into different classes
			for (var q = 0; q < 5; q++) {
				// if the current one is not the one in this iteration of the loop
				if (liNodes[q] != lastLi.parentNode) {
					// highlight it
					liNodes[q].className = 'ka_starHighlight' + size;
				}
				// otherwise it is
				else {
					// break the loop
					break;
				}
			}
			// call it again
			setTimeout(function () {
				kap_starsBlink(liNodes, lastLi, size, itCount + 1);
			},
			250);
		},
		250);
	}
}