// JavaScript Document


// srore the article, write results to DB, change starring
function scoreIt(rev_page,rev_id,score,wikipath) {
	wikipath += "/extensions/ArticleScores/setScore.php";
	//alert(wikipath);
	jQuery(document).ready(function($) {
		safetyNumber = rev_page*rev_id+score*598;
		jQuery.ajax({
   			type: "POST",
			url: wikipath,
			data: "rev_page=" + rev_page + "&rev_id=" + rev_id + "&score=" + score + "&sn=" + safetyNumber,
			dataType: "text",
			success: function(server_response){
				if(!server_response) alert("Server error, please contact administrator!");
				else if(server_response==-1) {
					// wait for cookie expiration
					jQuery("#SC_blocked_warning").css("display","block");
				}
				else {
					// scoring has been sent
					jQuery("#SC_blocked_warning").css("display","none");
					arr = server_response.split("-");
					newscore = arr[0];	// the score
					rnumber = arr[1];	// number of reviewers
					
					for(i=1;i<6;i++) {
						jQuery("#SCstar" + i).removeAttr("onmouseover");	// remove stars' onmouseover
						jQuery("#SCstar" + i).removeAttr("onmouseout");		// remove stars' onmouseout
					}
					
					on = jQuery("#SCstar1").attr("src").replace("star0","star1");
					off = jQuery("#SCstar1").attr("src").replace("star1","star0");
					
					for(i=0;i<5;i++){
						if(newscore>i) jQuery("#SCstar" + (i+1)).attr("src",on);
						else jQuery("#SCstar" + (i+1)).attr("src",off);
					}
					jQuery("#SCnumber").text(rnumber+"x");
					//jQuery("#SC_header").css("display","none");
					jQuery("#SC_info").css("display","none");
					jQuery("#SC_thanks").css("display","block");
					jQuery("#SC_scoreheader").text(score);
				}
				//alert(server_response);
			}
		});
	});
}


/*
on=1 (onmouseover) - yellow
on=1 (onmouseoout) - previous state
number=order of the star
starState=current state
*/
function selectStar(number,on,starState) {
	jQuery(document).ready(function($) {
		if(on==1){
			// onmouseover
			// alt attribute contains current state after dash
			for(i=1;i<6;i++){
				if(i<=number) newPath = jQuery("#SCstar" + i).attr("src").replace("star0","star1");
				else newPath = jQuery("#SCstar" + i).attr("src").replace("star1","star0");
				jQuery("#SCstar" + i).attr("src",newPath);
			}
		}
		else {
			// onmouseout - get back to previous state
			for(i=1;i<6;i++){
				arr = jQuery("#SCstar" + i).attr("alt").split("-");
				if(arr[1]=="1") newPath = jQuery("#SCstar" + i).attr("src").replace("star0","star1");
				else newPath = jQuery("#SCstar" + i).attr("src").replace("star1","star0");
				jQuery("#SCstar" + i).attr("src",newPath);	
			}
		}
	});
}


/* zobrazi info u hodnoceni */
function showInfo(){
	jQuery("#SC_info").css("display","block");
}

/* skryje info u hodnoceni */
function hideInfo(){
	jQuery("#SC_info").css("display","none");
}
