//window.addEvent('domready', function() {

	/* Vote Stars */
	if($('rating')) {

		if($$('#rateStars .star')){
			var starCount = 0;
			var voteStars = $$('#rateStars .star');
			
			// add hover actions to voteStars
			voteStars.each(function(element) {
				var here = ++starCount;
				element.addEvent('mouseenter', function(event) {
					for(j=1;j<=here;j++){
						if ($('star'+j).firstChild)
							$('star'+j).firstChild.className = 'full';
					}
					for(k=5;k>here;k--){
						if ($('star'+k).firstChild)
							$('star'+k).firstChild.className = '';
					}
				});
			});
			
			// add mouseexit function to VoteStars parent div
			$('rateStars').addEvent('mouseleave', function(event) {
				voteStars.each(function(element) {
					if (element.firstChild)
						element.firstChild.className = '';
				});
			});
			
		}
	}

	/* Rating Stars */
	var ajaxResponse = '';
	if($$('#rateStars ul li a')) {

		var ratingStars = $$('#rateStars ul li a');
		ratingStars.each(function(element) {
			var voteURL = element.href;

			element.addEvent('click', function(event) {		
						   
				event.stop();
				/* setup AJAX for Voting */
//				alert(voteURL);
				
				new Request({
					method: 'get',
					url: voteURL, 
					update: $('updateStars'),
					onComplete: function() {
						parseRating();
					}
				}).send();
				
			});
		});
	}

	function parseRating() {

        // get current rating value
        var currentRate = $('currentRate').className;
//        alert(currentRate);
        // get voted value
        // var
        // calculate new rating value
        // var

        // disappear current star
        $('rateStars').style.display = 'none';

        // If first vote
        if (currentRate==0)
            currentRate = 3;

        // display updated star
        var foo = '<div id="rateStars"><ul class="Rate show' + currentRate + '"><li id="star1" class="star"></li><li id="star2" class="star"></li><li id="star3" class="star"></li><li id="star4" class="star"></li><li id="star5" class="star"></li></ul></div><div id="VoteMsg">Your vote has been Recorded</div>';
		ajaxResponse = $('updatedStars').innerHTML = foo;
	}

//}
