function onHoverRate(index){
	
	if(rateTimeout != null){
		clearTimeout(rateTimeout);
		rateTimeout=null;
	}	
	
	for(var i = 1; i<=newMaxRange; i++){
		if(index>=i){
			document.getElementById('star'+i).src = imgHoverStar;	
		}else{
			document.getElementById('star'+i).src = imgGrayStar;
		}
	}
}

function resetRate(){
	
	for(var i = 1; i<=maxRange; i++){
		if(roundRating>=i){
			document.getElementById('star'+i).src = imgYellowStar;
		}else{
			document.getElementById('star'+i).src = imgGrayStar;
		}
	}
	clearTimeout(rateTimeout);
	rateTimeout=null;
}

function addNewRate(loginUsername, albumUsername, folderId, encImageId, rate){
	
	var AJAXLINK = URLPREFIX+albumUsername+"/rate";
	
	clearTimeout(rateTimeout);
	rateTimeout=null;
	
	var options = { method: 'post', 
					parameters: {username: loginUsername, rate:rate, folderId:folderId, encImageId:encImageId},
					onSuccess: function(transport){
						
						response = transport.responseText;						
						
						if(response.length > 0){							
							document.getElementById('rateDiv').innerHTML = response;				
						}
						
					},
					onFailure: function(){alert("FAIL");
					}
				};

	new Ajax.Request(AJAXLINK, options); 								
					
}


function showRatingSummary(methodType){

	Effect.toggle('rateSummaryDiv', 'appear');
	if(methodType == "more"){
		document.getElementById('more').style.display='none';
	}else{
		setTimeout("document.getElementById('more').style.display='inline'", 500);				
	}
	
}

function summaryPageSwitch(TheForm, albumUsername){
	
	var showLast = document.getElementById('showLast').value;
	var displayPerPage = document.getElementById('displayPerPage').value;	
	
	TheForm.method = "POST";
	TheForm.action = URLPREFIX+albumUsername+"/rateSummary?optPage=1&showLast="+showLast+"&displayPerPage="+displayPerPage;
	TheForm.submit();	
}


function updateRate(encImageId){
	
	var AJAXLINK = URLPREFIX+albumusername+"/rate.switch";
	
	var options = { method: 'post',
					parameters:{encImageId:encImageId, loginusername:loginusername, albumusername:albumusername},
					onSuccess: function(transport){
						response = transport.responseText;
					
						aryResp = response.split("_____");
						
						if(response.length > 0){
							roundRating = aryResp[0];
							document.getElementById('rateDiv').innerHTML = aryResp[1];
						}else{							
							document.getElementById('rateDiv').innerHTML = commentDisplay[10];
						}
						
					}, 
					onFailure: function(transport){alert("FAILURE"+transport.responseText);}
				};
	
	new Ajax.Request(AJAXLINK, options); 
	
}
