if (!window.mkmItemVote) {
	function mkmItemVote(strInstance, iItemId, iMaxVote) {
		var oInstance = this;
		oInstance.strInstance = strInstance;
		oInstance.iItemId = iItemId;
		oInstance.iMaxVote = iMaxVote;
		oInstance.bInitialized = false;
		oInstance.bIsWorking = false;
		oInstance.bCanVote = false;
		oInstance.bItemVoted = false;
		oInstance.bUserAuthorized = false;
		oInstance.iVotes = 0;
		oInstance.fAverageVote = 0;
		oInstance.asyncUrl = "/voti/ajax";
		oInstance.init = function() {
			oInstance.hInteractiveItemVote = document
					.getElementById("mkmInteractiveItemVote_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVoteLoader = document
					.getElementById("mkmInteractiveItemVoteLoader_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVotesCount = document
					.getElementById("mkmInteractiveItemVoteVotesCount_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVotesCountTitle = document
					.getElementById("mkmInteractiveItemVoteVotesCountTitle_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVoteForm = document
					.getElementById("mkmInteractiveItemVoteForm_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVoteResult = document
					.getElementById("mkmInteractiveItemVoteResult_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVoteResultFiller = document
					.getElementById("mkmInteractiveItemVoteResultFiller_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVoteMessage = document
					.getElementById("mkmInteractiveItemVoteMessage_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVoteVoted = document
					.getElementById("mkmInteractiveItemVoteVoted_"
							+ oInstance.strInstance);
			oInstance.hInteractiveItemVoteNotLogged = document
					.getElementById("mkmInteractiveItemVoteNotLogged_"
							+ oInstance.strInstance);
			if (oInstance.hInteractiveItemVote
					&& oInstance.hInteractiveItemVoteLoader
					&& oInstance.hInteractiveItemVotesCount
					&& oInstance.hInteractiveItemVotesCountTitle
					&& oInstance.hInteractiveItemVoteForm
					&& oInstance.hInteractiveItemVoteResult
					&& oInstance.hInteractiveItemVoteResultFiller
					&& oInstance.hInteractiveItemVoteMessage
					&& oInstance.hInteractiveItemVoteVoted
					&& oInstance.hInteractiveItemVoteNotLogged) {
				oInstance.bInitialized = true;
				oInstance.loadStats(true);
			} else {
				alert("Alcuni compontenti DHTML sono mancanti.");
			}
			return false;
		};
		oInstance.asyncCall = function(strUrl, strPostData, fCallBack) {
			var hHttpRequest = null;
			if (window.XMLHttpRequest) {
				try {
					hHttpRequest = new XMLHttpRequest();
				} catch (oErr) {
					hHttpRequest = null;
				}
			} else {
				if (window.ActiveXObject) {
					var aStrMsxhtml = new Array("Msxml2.XMLHTTP.7.0",
							"Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0",
							"Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0",
							"MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
					for ( var i = 0; i < aStrMsxhtml.length && !hHttpRequest; i++) {
						try {
							hHttpRequest = new ActiveXObject(aStrMsxhtml[i]);
						} catch (oErr) {
							hHttpRequest = null;
						}
					}
				}
			}
			if (hHttpRequest != null) {
				hHttpRequest.onreadystatechange = function() {
					if (hHttpRequest.readyState == 4) {
						fCallBack(hHttpRequest.status == 200
								&& hHttpRequest.responseText ? hHttpRequest.responseText
								: null);
					}
				};
				hHttpRequest.open(strPostData == null ? "GET" : "POST", strUrl,
						true);
				if (strPostData != null) {
					hHttpRequest.setRequestHeader("Content-Type",
							"application/x-www-form-urlencoded");
					hHttpRequest.setRequestHeader("Content-Length",
							strPostData.length);
				}
				hHttpRequest.setRequestHeader("If-Modified-Since",
						"Thu, 1 Jan 1970 00:00:00 GMT");
				hHttpRequest.setRequestHeader("X-Requested-With",
						"XMLHttpRequest");
				hHttpRequest.send(strPostData);
				return true;
			}
			fCallBack(null);
			return false;
		};
		oInstance.loadStats = function(bSilent) {
			if (oInstance.bInitialized && !oInstance.isWorking) {
				oInstance.isWorking = true;
				oInstance.hInteractiveItemVoteLoader.style.display = "";
				oInstance.hInteractiveItemVoteMessage.style.display = "none";
				oInstance.hInteractiveItemVoteVoted.style.display = "none";
				oInstance.hInteractiveItemVoteNotLogged.style.display = "none";
				oInstance.hInteractiveItemVotesCount.style.display = "none";
				oInstance.hInteractiveItemVoteForm.style.display = "none";
				if (/\bshowResult\b/
						.test(oInstance.hInteractiveItemVoteResult.className)) {
					oInstance.hInteractiveItemVoteResult.style.display = "";
					oInstance.hInteractiveItemVoteForm.style.display = "none";
				} else {
					oInstance.hInteractiveItemVoteResult.style.display = "none";
				}
				var aParams = new Array();
				aParams[aParams.length] = "rand_"
						+ Math.round(Math.random() * 999999999) + "="
						+ Math.round(Math.random() * 999999999);
				aParams[aParams.length] = "mode=0";
				aParams[aParams.length] = "item_id="
						+ encodeURIComponent(oInstance.iItemId);
				oInstance
						.asyncCall(
								oInstance.asyncUrl,
								aParams.join("&"),
								function(strResponse) {
									oInstance.hInteractiveItemVoteLoader.style.display = "none";
									oInstance.isWorking = false;
									if (strResponse != null) {
										try {
											var oResponse = eval("("
													+ strResponse + ")");
										} catch (e) {
											var oResponse = null;
										}
										if (oResponse != null
												&& typeof oResponse == "object") {
											if (oResponse.success) {
												oInstance.bCanVote = oResponse.data.can_vote ? true
														: false;
												oInstance.bItemVoted = oResponse.data.item_voted ? true
														: false;
												oInstance.bUserAuthorized = oResponse.data.user_authorized ? true
														: false;
												oInstance.iVotes = oResponse.data.votes;
												oInstance.fAverageVote = oResponse.data.average;
												oInstance.iMaxVote = oResponse.data.max_vote;
												oInstance.draw(false);
												return true;
											} else {
												if (!bSilent) {
													alert(oResponse.description);
												}
											}
										} else {
											if (!bSilent) {
												alert("Il server ha risposto con dei dati corrotti: riprovare più tardi.");
											}
										}
									} else {
										if (!bSilent) {
											alert("Il server ha risposto in modo inatteso oppure la connessione è stata annullata: riprovare più tardi.");
										}
									}
									oInstance.hInteractiveItemVote.style.display = "none";
									return false;
								});
				return true;
			}
			return false;
		};
		oInstance.draw = function(bShowMessage) {
			if (oInstance.bInitialized) {
				while (oInstance.hInteractiveItemVotesCount.firstChild) {
					oInstance.hInteractiveItemVotesCount
							.removeChild(oInstance.hInteractiveItemVotesCount.firstChild);
				}
				oInstance.hInteractiveItemVotesCount.title = oInstance.iVotes
						+ " " + (oInstance.iVotes == 1 ? "voto" : "voti")
						+ " con una media di " + oInstance.fAverageVote;
				oInstance.hInteractiveItemVotesCountTitle.title = oInstance.iVotes
						+ " "
						+ (oInstance.iVotes == 1 ? "voto" : "voti")
						+ " con una media di " + oInstance.fAverageVote;
				oInstance.hInteractiveItemVoteResult.title = oInstance.iVotes
						+ " " + (oInstance.iVotes == 1 ? "voto" : "voti")
						+ " con una media di " + oInstance.fAverageVote;
				try {
					if(current_domain != '') {
						current_domain = current_domain;
					}
				} catch(e) {
					current_domain = '';
				}
				if (current_domain == 'gamefinal') {
					oInstance.hInteractiveItemVotesCount.appendChild(document
						.createTextNode("[" + oInstance.iVotes + " " + (oInstance.iVotes == 1 ? "voto" : "voti")
						+ " con una media di " + oInstance.fAverageVote + "]"));
				} else {
					oInstance.hInteractiveItemVotesCount.appendChild(document
						.createTextNode("[" + oInstance.iVotes + " " 
						+ (oInstance.iVotes == 1 ? "voto" : "voti") + "]"));
				}

				oInstance.hInteractiveItemVoteResultFiller.style.width = oInstance.iVotes ? (Math
						.round((oInstance.fAverageVote * 100)
								/ oInstance.iMaxVote) + "%")
						: "0px";
				oInstance.hInteractiveItemVotesCount.style.display = oInstance.iVotes ? ""
						: "none";
				if (/\bshowResult\b/
						.test(oInstance.hInteractiveItemVoteResult.className)) {
					oInstance.hInteractiveItemVoteResult.style.display = "";
					oInstance.hInteractiveItemVoteForm.style.display = "none";
				} else {
					oInstance.hInteractiveItemVoteForm.style.display = oInstance.bCanVote ? ""
							: "none";
					oInstance.hInteractiveItemVoteResult.style.display = !oInstance.bCanVote ? ""
							: "none";
				}
				if (bShowMessage) {
					oInstance.hInteractiveItemVoteMessage.style.display = "";
					window
							.setTimeout(
									function() {
										oInstance.hInteractiveItemVoteMessage.style.display = "none";
									}, 2500);
				} else {
					if (!oInstance.bUserAuthorized) {
						oInstance.hInteractiveItemVoteNotLogged.style.display = "";
					} else {
						if (oInstance.bItemVoted) {
							oInstance.hInteractiveItemVoteVoted.style.display = "";
						}
					}
				}
				return true;
			}
			return false;
		};
		oInstance.vote = function(iVote) {
			if (oInstance.bInitialized && !oInstance.isWorking) {
				if (oInstance.bCanVote) {
					iVote = parseInt(iVote);
					if (!isNaN(iVote) && iVote >= 1
							&& iVote <= oInstance.iMaxVote) {
						oInstance.isWorking = true;
						oInstance.hInteractiveItemVoteLoader.style.display = "";
						var aParams = new Array();
						aParams[aParams.length] = "rand_"
								+ Math.round(Math.random() * 999999999) + "="
								+ Math.round(Math.random() * 999999999);
						aParams[aParams.length] = "mode=1";
						aParams[aParams.length] = "item_id="
								+ encodeURIComponent(oInstance.iItemId);
						aParams[aParams.length] = "vote="
								+ encodeURIComponent(iVote);
						oInstance
								.asyncCall(
										oInstance.asyncUrl,
										aParams.join("&"),
										function(strResponse) {
											oInstance.hInteractiveItemVoteLoader.style.display = "none";
											oInstance.isWorking = false;
											if (strResponse != null) {
												try {
													var oResponse = eval("("
															+ strResponse + ")");
												} catch (e) {
													var oResponse = null;
												}
												if (oResponse != null
														&& typeof oResponse == "object") {
													if (oResponse.success) {
														oInstance.bCanVote = oResponse.data.can_vote ? true
																: false;
														oInstance.bItemVoted = oResponse.data.item_voted ? true
																: false;
														oInstance.bUserAuthorized = oResponse.data.user_authorized ? true
																: false;
														oInstance.iVotes = oResponse.data.votes;
														oInstance.fAverageVote = oResponse.data.average;
														oInstance.iMaxVote = oResponse.data.max_vote;
														oInstance.draw(true);
														return true;
													} else {
														alert(oResponse.description);
													}
												} else {
													alert("Il server ha risposto con dei dati corrotti: riprovare più tardi.");
												}
											} else {
												alert("Il server ha risposto in modo inatteso oppure la connessione è stata annullata: riprovare più tardi.");
											}
											return false;
										});
					} else {
						alert("Il voto non è valido: deve essere compreso tra 1 e "
								+ oInstance.iMaxVote + ".");
					}
				} else {
					alert("Non puoi votare.");
				}
			}
			return false;
		};
	}
}



