// JavaScript Document
$(function() {	
	
	var clase = new Array();

	clase[1] = 'ratedone';
	clase[2] = 'ratedtwo';
	clase[3] = 'ratedthree';
	clase[4] = 'ratedfour';
	clase[5] = 'ratedfive';
	
	var attrClass;
	
	$('.redStar_padding ul li a').mouseover(function() {
		
		title = $(this).parent().parent().attr('title');

		if(title == '') {	
			id = $(this).attr('href');
			id = id.split("v=");
			id = parseInt(id[1]);
			
			attrClass = $(this).parent().parent().attr('class');
			html = $(this).parent().parent().attr('class',clase[id]);
		} else {
			return false;
		} 
		
	});
	
	$('.redStar_padding ul').mouseout(function() {
		title = $(this).attr('title');

		if(title == '') {	
			$(this).attr('class', attrClass);
		} else {
			return false;
		}
		
	});
	
	$('.redStar_padding ul li a').bind('click',function() {
		
		title = $(this).parent().parent().attr('title');
		
		if(title == '') {			
			
			id = $(this).attr('href');
			co = id.split("c=");
			co = parseInt(co[1]);
			ty = id.split("t=");
			ty = parseInt(ty[1]);
			id = id.split("v=");
			id = parseInt(id[1]);			 
			
			var newClass = clase[id];
			var html = $(this);
			
			$.getJSON('rates/ratedAjax.php', {c:co,t:ty,v:id}, function(data) {
				
				if(data.succes == true) {

					html.parent().parent().attr('class', newClass).attr('title','Ya Votaste');			
					
					for(i=0; i<=2; i++) {
						setTimeout(null,300);
						if((i % 2) == 0) {
							html.parent().parent().fadeIn();
						} else {
							html.parent().parent().fadeOut();
						}						
					}					
				}				
			});					
		}
		return false;
	});
});