document.write('<script src="js/prototype.js" type="text/javascript"></script>');
document.write('<script src="js/scriptaculous.js" type="text/javascript"></script>');
document.write('<script src="js/colorPicker.js" type="text/javascript"></script>');



var RX = {
	
	init: function() {
	
		this.lang = 'it';
				
		if($('consoleBoxTab')) RX.Tabs.init(RX.getUrlParams('defaultTab') || 'Riepilogo');
		RX.Effects.initPlayersMenu();
		this.pollingStart();
	
	},
	
	reportBadMessage: function(id, elem) 
	{
		elem.down().src = 'i/btn-report-message-disabled.gif';
		new Ajax.Request("ajaxAction.php?request=reportBadMessage&id=" + id, {
			onSuccess: function(res) {
				if (res.responseText == "OK") 
					alert("Grazie per la segnalazione!");
				else 
					alert("Errore tecnico, riprova piu' tardi");
			}
		});
	},
	
	getLocationAndAppend: function(append, param) {
		var loc = window.location.href;
		if(loc.endsWith('#')) loc = loc.truncate(loc.length-1, '');
		if (param == true) {
			if (loc.indexOf('?') > -1) 
				return loc + '&' + append;
			else
				return loc + '?' + append;
		}
		if(append != null) return loc+append;
	},
	
	showCampionatiArchiviati: function()
	{
		this.popup('archivioCampionati.php', 'campionati', 500, 400);
	},
	
	forceBanners: function() 
	{
		alert("Particolari momenti di lentezza del server o della rete o impostazioni di sicurezza dell'utente\npotrebbero rendere impossibile la visualizzazione dei banner.\n\nIl sistema provera' ora a ricaricarli.")
		new Ajax.Updater($('BannerBox'), 'mostraBanner.php');
	},
	
	cancellaUtente: function(Obj, id)
	{
		if(confirm('Sei sicuro di voler cancellare il modo definitivo il tuo utente da RigoriX?')) {
			// Ok, prima conferma data. Ora devo madnare una mail e inserire a DB.
			new Ajax.Updater(Obj, 'ajaxAction.php?request=cancellaUtente&id_utente=' + id);
		}
	},
	
	pollingStart: function() {
		var intID = setInterval(function(){
			// Richiesta di sfide
			new Ajax.Request("http://www.rigorix.com/getNumNewSfide.php", {onSuccess: RX.handleResponse_getSfide});
		}, 60000);
	},
  
	handleResponse_getSfide: function(ajax){
		var sfide = ajax.responseText.split("|");
		var sfideRicevute = Number(sfide[0].split(":")[1]);
		var sfideConcluse = Number(sfide[1].split(":")[1]);
		
		if((sfideRicevute != 0 && sfideRicevute != "0") || (sfideConcluse != 0 && sfideConcluse != "0")) {
			RX.Effects.newChallanges(sfideRicevute,sfideConcluse);
		}
	},
	
	newSfidePop: function(msg) {
		//alert(msg);
		window.location.href = 'lanciaSfida.php?sfidato=' + msg;
	},
	
	popup: function(url, tit, w, h) {
		var latosx = Math.floor((screen.width-w)/2);
		var latosup = Math.floor((screen.height-h)/2);
		var newWin = window.open(url, tit, 'left='+latosx+',top='+latosup+',width='+w+',height='+h+',toolbar=0,resizable=0,scrollbars=no');
		newWin.focus();
	},
	
	popupScrollbar: function(url, tit, w, h) {
		var latosx = Math.floor((screen.width-w)/2);
		var latosup = Math.floor((screen.height-h)/2);
		var newWin = window.open(url, tit, 'left='+latosx+',top='+latosup+',width='+w+',height='+h+',toolbar=0,resizable=0,scrollbars=yes');
		newWin.focus();
	},
	
	removeBan: function(obj) {
		this.banRemoving = obj;
		new Ajax.Request('ajaxAction.php?request=removeBan&userID='+obj.id, {
			onSuccess:RX.removeBan_action
		});
	},
	
	removeBan_action: function(ajax) {
		Element.remove(RX.banRemoving.parentNode);
	},
	
	writeFlash: function(src, w, h, flashVars) {
		var my_var = '<object type="application/x-shockwave-flash" data="' + src + '" width="' + w + '" height="' + h + '">';
		if(flashVars != null) my_var += '<param name="flashvars" value="' + flashVars + '" />';
		my_var += '<param name="movie" value="' + src + '" />';
		my_var += '<param name="quality" value="high" />';
		my_var += '<param name="wmode" value="transparent" />';
		my_var += '</object>';
		document.write(my_var);
	},
	
	getUrlParams: function(paramName) {
		var url = window.location.href;
		if(url.indexOf(paramName) != -1 && url.indexOf('?') != -1 ) {
			var paramsList = url.substr(url.indexOf("?"));
			var params = paramsList.split("&");
			for ( var i = 0; i < params.length; i++ ) {
				
				if (params[i].indexOf(paramName + "=") > -1 ) {
					return params[i].split("=")[1];
				}
			
			}
			
		} else return false;
	}, 
	
	getUserDetails: function(input, byString) {
		Element.setStyle($('schedaUtente'), {
			padding: '6px',
			border: '2px solid #e3e3e3',
			margin: '0 0 10px 0',
			display: 'block'
		});
		$('schedaUtente').innerHTML = "Caricando la scheda utente...";
		if(byString)
            var userName = input;
		else
            var userName = input.value
		new Ajax.Request('ajaxAction.php?request=getUserDetails&userName='+userName, {
			onSuccess:RX.getUserDetails_action,
			encoding: 'iso-8859-1',
			requestHeaders: 'text/html; charset=iso-8859-1'
		});
	},
	
	getUserFace: function(userName) {
		new Ajax.Updater('schedaUtente', 'ajaxAction.php?request=getMascotteFull&userName='+userName);
	},
	
	getUltimoVincitoreFace: function(userName) {
		new Ajax.Updater('schedaUtente', 'ajaxAction.php?request=getMascotteFullVincitore');
	},
	
    checkMascotte: function()
    {
        if($('mascotteChecker')) {
            var chk = $F('mascotteChecker').split(',');
            if($('setup_maglia').down().src.indexOf('maglia_' + chk[0]) == -1) {
                new Ajax.Updater('mascotteScreen', 'ajaxAction.php?request=getMascotte&userName='+chk[3]);
                setTimeout(function() {
                    $('mascotteScreen').style.visibility = 'visible';    
                }, 1000)
                return 'OK';
            } else
                $('mascotteScreen').style.visibility = 'visible';
        } else
            return false;
    },
    
	getUserDetails_action: function(ajax) {
		if(ajax.responseText == 'KO') 
			$('schedaUtente').innerHTML = "<span style='color:red'><strong>L'utente inserito non esiste!</strong></span>";
		else {
            $('schedaUtente').innerHTML = ajax.responseText;
            var intID_checker = setInterval(function(){
                if(RX.checkMascotte() == 'OK')
                    clearInterval(intID_checker);
            }, 1000);
		}
	},
	
	checkUserExists: function(input) {
		new Ajax.Request('ajaxAction.php?request=checkUserExists&userName='+input.value, {
			onSuccess:RX.GameSet.checkUserExists_action
		});
	},
	
	checkUserName: function(input, f) {
		new Ajax.Request('ajaxAction.php?request=checkUserExists&userName='+input.value, {
			onSuccess:RX.checkUserName_action
		});
	},
	
	checkUserName_action: function(ajax) {
		if(ajax.responseText == "OK") return true;
		else return false;
	},
	
	banUser: function(userName) {
		new Ajax.Request('ajaxAction.php?request=checkUserExists&userName='+userName.value, {
			onSuccess:RX.banUser_action
		});
	},
	
	banUser_action: function(ajax) {
		if(ajax.responseText == 'true') {
			$('formBanUser').submit();
		} else {
			alert("Il nome utente non esiste");
		}
	},
    
    backToGame: function() {
        window.open('areaPersonale.php');
        setInterval(function() {
            window.close();
        }, 500);
    },
	
	backToGameFromFlash: function() {
        window.open('areaPersonale.php');
        setInterval(function() {
            window.close();
        }, 150);
    },
	
	backDirectToGameFromFlash: function() {
        window.close();
    },
	
	backToLink: function(l) {
        window.open(l);
        setInterval(function() {
            window.close();
        }, 500);
    },
	
	getFastRisultato: function(a, ids)
	{
		var parent = a.parentNode;
		Element.remove(a);
		new Ajax.Request('ajaxAction.php?request=getFastRisultato&ids='+ids, {
			onSuccess: function(ajax) {
				parent.innerHTML += ajax.responseText;
			}
		});
	}
	
}

RX.Tabs = {
	
	activeTabContent: false,
	activeTab: false,
	status: 'idle',
	tabsArray: new Array('tab_Gioca', 'tab_Riepilogo', 'tab_Sfide', 'tab_Messaggi', 'tab_DatiPersonali', 'tab_Ricarica', 'tab_Guadagna', 'tab_Help', 'tab_Consiglia'),
	
	init: function(firstTab) {
	
	},
	
	setActiveTab: function(tab, obj) {
		
		Element.up(tab).childElements().each(function(a) {
			if(a.tagName == 'A') 
				a.removeClassName('on');
		});
		$$('.tabContentOn')[0].className = 'tabContent';
		tab.addClassName('on');
		$(obj).className = 'tabContentOn'
	
	}
	
};

RX.GameSet = {
	
	init: function() {
		
		for(var i=0; i<5; i++) {
			
			var shootBox = this.buildShootBox(i+1);
			var keepBox = this.buildKeepBox(i+1);
			$('gameSetPanel').appendChild(shootBox);
			$('gameSetPanel').appendChild(keepBox);
			$('gameSetPanel').appendChild(Builder.node('BR', {clear: 'both'}));
			
			if($('setSfidante_input'))
				new Ajax.Autocompleter('setSfidante_input', 'sfidanteChoices', 'ajaxAction.php?request=getUserList', { minChars: 2, paramName: 'userName'});
			
		}
		
	},
	
	setRandomSequence: function(serie)
	{
		var supers = 0;
		var seq = new String('');
		if(serie == "A") supers = 3;
		if(serie == "B") supers = 2;
		if(serie == "C") supers = 1;
		for (var i=0; i<5; i++) {
			var rand = Math.round(Math.random() * 2);
			seq += rand + "|";
			
			if((supers - i) > 0) 
				var extra = Math.round(Math.random() * 2);
			else
				var extra = '';
			var n = Math.round(Math.random() * 2);
			while(n == extra)
				n = Math.round(Math.random() * 2);
			seq += extra + String(n).toString();
			if((i+1) < 5)
				seq += '|';
		}
		$('defaultSeq').value = seq;
//		RX.GameSet.action.specialKeeps = 0;
		this.setDefaultSequende();
	},
	
	setDefaultSequende: function() {
		if($('defaultSeq') && $('defaultSeq').value != "") {
			var seq = $('defaultSeq').value;
			seq = seq.split('|');
			var loop = 0;
			for(var i=0; i<5; i++) {
				// Tiro
				RX.GameSet.action.palloneClick($('gameSetBox_tiro_'+(i+1)).getElementsByTagName('a')[seq[i+loop]]);
				if(seq[i+loop+1].length > 1) {
					RX.GameSet.action.portiereClick($('gameSetBox_parata_'+(i+1)).getElementsByTagName('a')[seq[i+loop+1].substring(0,1)]);
					RX.GameSet.action.portiereClick($('gameSetBox_parata_'+(i+1)).getElementsByTagName('a')[seq[i+loop+1].substring(1,2)]);
				}
				else RX.GameSet.action.portiereClick($('gameSetBox_parata_'+(i+1)).getElementsByTagName('a')[seq[i+loop+1]]);
				loop++;
			}
		} else alert("Devi prima impostare una sequenza predefinita");
	},
	
	kicksKeepsAfterPareggio: function(nomePlayer) {
		RX.backToGame();
        /*
         opener.externalCall('window.location.href="areaPersonale.php?activeTab=tab_Gioca&sfidato='+nomePlayer+'"');
		window.close();
		*/
	},
	
	closeSfidaWin: function() {
		RX.backToGame();
	},
	
	saveSequence: function(f) {
		var seq = f.tiro1.value+"|"+f.parata1.value+"|"+f.tiro2.value+"|"+f.parata2.value+"|"+f.tiro3.value+"|"+f.parata3.value+"|"+f.tiro4.value+"|"+f.parata4.value+"|"+f.tiro5.value+"|"+f.parata5.value;
		if(this.checkSubmit(f, true)) {
			new Ajax.Request('ajaxAction.php?request=saveUserSequence&form='+seq, {
				onSuccess:RX.GameSet.saveSequence_action
			});
		}
	},
	
	saveSequence_action: function(ajax) {
		if($('btnSaveSeq')) {
			$('btnSaveSeq').src = 'i/btnSalvato.gif';
			$('btnSaveSeq').parentNode.onclick = function(){}
		}
	},
	
	checkUserExists_action: function(answer) {
		
		if(answer.responseText == 'false') {
			$('setSfidante_input').style.color = 'red';
			alert(RX.Text[RX.lang].userDoesntExist($('setSfidante_input').value));
			$('setSfidante_input').focus();
		} else {
			$('setSfidante_input').style.color = '#000';
		}
		
	},

	
	checkSubmit: function (f, seqOnly, bannerId, userId, bannerUrl, openWindow) {
		
		var status = true;

		for(var i=1; i<= 5; i++) {
			
			if(f['tiro' + i].value == "" && status) {
				
				$('gameSetBox_tiro_' + i).style.border = '2px solid #f00';
				alert("Devi impostare tutti i tiri per poter lanciare la sfida!");
				status = false;
				
			} else if(f['parata' + i].value == "" && status) {
				
				$('gameSetBox_tiro_' + i).style.border = '0';
				$('gameSetBox_parata_' + i).style.border = '2px solid #f00';
				alert("Devi impostare tutte le parate per poter lanciare la sfida!");
				status = false;
				
			} else $('gameSetBox_parata_' + i).style.border = '0';
						
		}

		if($('setSfidante_input') == "") {
			alert("Devi selezionare un utente per poter lanciare una sfida");
			$('setSfidante_input').focus();
			status = false;
		}
		//if(status) alert(f.serialize());



		//controllo che il banner sia stato cliccato
		
		if (!document.getElementById('id_banner')){
			alert('Devi cliccare su un banner per poter lanciare una sfida');
			status = false;
		}

		f.id_banner.value=bannerId;
		f.id_utente.value=userId;
		f.banner_url.value=bannerUrl;
		f.action='ospite.php';
				
		if(status) {
            window.open('rigorix_popup.php', 'rigorix_popup', 'width=660,height=500,directories=0,location=0,menubar=0,status=0,toolbar=0');
            f.submit();
        }
		return status;
		
	},
	
	buildShootBox: function(n) {
		
		var shootBox = Builder.node('DIV', {className: 'gameSetBox', id: 'gameSetBox_tiro_' + n}, [
			Builder.node('H3', {title: 'tiro'}, 'Tiro ' + n),
			Builder.node('INPUT', {type: 'hidden', name: 'tiro' + n, value: ''}),
			Builder.node('A', {className: 'palloneSx_game', value: '0'}, [
				Builder.node('IMG', {src: 'i/lanciaSfide_pallone.png', style: 'width: 21px; height: 20px', className: 'png'})
			]),
			Builder.node('A', {className: 'palloneCenter_game', value: '1'}, [
				Builder.node('IMG', {src: 'i/lanciaSfide_pallone.png', style: 'width: 21px; height: 20px', className: 'png'})
			]),
			Builder.node('A', {className: 'palloneDx_game', value: '2'}, [
				Builder.node('IMG', {src: 'i/lanciaSfide_pallone.png', style: 'width: 21px; height: 20px', className: 'png'})
			])
		]);
		for(var i=0; i<shootBox.childNodes.length; i++) {
			
			var elem = shootBox.childNodes[i];
			if(elem.tagName == 'A') {
				elem.onmouseover = function() { RX.GameSet.action.palloneOver(this); }
				elem.onmouseout = function() { RX.GameSet.action.palloneOut(this); }
				elem.onclick = function() { RX.GameSet.action.palloneClick(this); }
				Element.setOpacity(elem, 0.6);
			}
			
		}
		
		return shootBox;
		
	},
	
	buildKeepBox: function(n) {
		
		var keepBox = Builder.node('DIV', {className: 'gameSetBox', id: 'gameSetBox_parata_' + n}, [
			Builder.node('H3', {title: 'parata'}, 'Parata ' + n),
			Builder.node('INPUT', {type: 'hidden', name: 'parata' + n, value: ''}),
			Builder.node('A', {className: 'portiereSx_game', value: '0'}, [
				Builder.node('IMG', {src: 'i/lanciaSfide_portiereSx.png', style: 'width: 50px; height: 39px', className: 'png'})
			]),
			Builder.node('A', {className: 'portiereCenter_game', value: '1'}, [
				Builder.node('IMG', {src: 'i/lanciaSfide_portiere.png', style: 'width: 27px; height: 47px', className: 'png'})
			]),
			Builder.node('A', {className: 'portiereDx_game', value: '2'}, [
				Builder.node('IMG', {src: 'i/lanciaSfide_portiereDx.png', style: 'width: 50px; height: 39px', className: 'png'})
			])
		]);
		keepBox.keepsArray = new Array();
		
		for(var i=0; i<keepBox.childNodes.length; i++) {
			
			var elem = keepBox.childNodes[i];
			if(elem.tagName == 'A') {
				elem.onmouseover = function() { RX.GameSet.action.portiereOver(this); }
				elem.onmouseout = function() { RX.GameSet.action.portiereOut(this); }
				elem.onclick = function() { RX.GameSet.action.portiereClick(this); }
			}
		}
		
		return keepBox;
		
	}
	
}

RX.GameSet.action = {
	
	portiereSrc: {
		posizione0: 'lanciaSfide_portiereSx',
		posizione1: 'lanciaSfide_portiere',
		posizione2: 'lanciaSfide_portiereDx'
	},
	
	portiereOver: function(obj) {

		obj.firstChild.src = 'i/' + this.portiereSrc['posizione' + obj.getAttribute('value')] + '_on.png';
		obj.style.cursor = 'pointer'
		
	},
	
	portiereOut: function(obj) {
		
		obj.firstChild.src = 'i/' + this.portiereSrc['posizione' + obj.getAttribute('value')] + '.png';
		
	},
	
	portiereClick: function(obj) {
		if(!obj.parentNode.keepsArray) obj.parentNode.keepsArray = new Array();
		if(obj.parentNode.keepsArray.length == 2) var specialKeep = true;
		this.resetPortiere(obj);
		if(obj.parentNode.keepsArray.length == 1 && !specialKeep) {
			this.specialKeeps--;
			obj.parentNode.specialKeep = true;
		}
		obj.onmouseover = null;
		obj.onmouseout = null;
		obj.onclick = null;
		obj.firstChild.src = 'i/' + this.portiereSrc['posizione' + obj.getAttribute('value')] + '_on.png';
		//obj.style.border = '2px solid #FFF';
//		obj.parentNode.getElementsByTagName('INPUT')[0].value = obj.getAttribute('value');
		obj.parentNode.keepsArray.push(obj);
		obj.parentNode.getElementsByTagName('INPUT')[0].value = '';
		obj.parentNode.keepsArray.each(function(elem){
			obj.parentNode.getElementsByTagName('INPUT')[0].value += elem.getAttribute('value');
		});
		
	},
	
	resetPortiere: function(obj) {
		
		for(var i=0; i<3; i++) {
			var lnk = obj.parentNode.getElementsByTagName('a')[i];
			if(
				obj.parentNode.keepsArray.indexOf(lnk) != -1 && (
			   		(
					 	this.specialKeeps == 0 &&
						lnk.parentNode.specialKeep != true
					) || (
						lnk == obj.parentNode.keepsArray[0] &&
						obj.parentNode.keepsArray.length == 2
					)
				)
			) {
			
				lnk.parentNode.keepsArray = lnk.parentNode.keepsArray.without(lnk);
				lnk.style.border = '0';
				lnk.firstChild.src = 'i/' + this.portiereSrc['posizione' + lnk.getAttribute('value')] + '.png';
				lnk.onmouseover = function() { RX.GameSet.action.portiereOver(this); }
				lnk.onmouseout = function() { RX.GameSet.action.portiereOut(this); }
				lnk.onclick = function() { RX.GameSet.action.portiereClick(this); }
				lnk.parentNode.keepsArray = lnk.parentNode.keepsArray.without(lnk);
			}
			
		}
		
	},
	
	palloneOver: function(obj) { 
		
		Element.setOpacity(obj, 1); 
		obj.style.cursor = 'pointer';
	},
	
	palloneOut: function(obj) { Element.setOpacity(obj, 0.6); },
	
	palloneClick: function(obj) {
		
		this.resetPallone(obj);
		
		obj.onmouseover = null;
		obj.onmouseout = null;
		obj.onclick = null;
		obj.parentNode.getElementsByTagName('INPUT')[0].value = obj.getAttribute('value');
		//obj.setStyle({border: '2px solid #FFF'});
		Element.setOpacity(obj, 1);
		
	},
	
	resetPallone: function(obj) {
		
		for(var i=0; i<obj.parentNode.getElementsByTagName('a').length; i++) {
			
			var lnk = obj.parentNode.getElementsByTagName('a')[i];
			Element.setOpacity(lnk, 0.6);
			lnk.setStyle({border: '0'});
			lnk.onmouseover = function() { RX.GameSet.action.palloneOver(this); }
			lnk.onmouseout = function() { RX.GameSet.action.palloneOut(this); }
			lnk.onclick = function() { RX.GameSet.action.palloneClick(this); }
			
		}
		
	}
	
}

RX.Effects = {
	
	newChallanges: function(a, b) {
		if($('boxUtente')) {
			var tot = Number(Number(a) + Number(b));
			new Effect.Shake('boxUtente')
			new Effect.Pulsate('nsfide');
			$('nsfide').style.color = 'red';
			$('nsfide').style.fontWeight = 'bold';
			$('totSfide').innerHTML = tot;
			var intID = setInterval(function(){
				clearInterval(intID);
				$('nsfide').style.color = '#2e95bd';
				$('nsfide').style.fontWeight = 'normal';
			}, 5000);
		}
	},
	
	setUserColor: function(sel) {
		$(sel.id.split('_handler')[0]).style.background = sel.value;
		sel.parentNode.getElementsByTagName('div')[0].style.background = sel.value;
	},
	
	setDefaultColor: function(sel, col) {
		$(sel).style.background = col;
		$(sel + '_handler').parentNode.getElementsByTagName('div')[0].style.background = col;
	},
	
	setUserNumber: function() {
		if(isNaN($F('numero_maglia_handler'))) {
			alert('Il numero di maglia non puo\' contenere lettere');
			$('numero_maglia_handler').focus();
		} else {
			$('setup_numero').innerHTML = $F('numero_maglia_handler');
			$('setup_numero_shadow').innerHTML = $F('numero_maglia_handler');
		}
	}, 
	
	setUserShirtType: function(t) {
		Element.remove($('setup_maglia').cleanWhitespace().firstChild);
		var maglia = Builder.node('IMG', {src: 'i/maschera_maglia_' + t + '.png', className: 'png', style: 'width:227px; height:136px'});
		$('setup_maglia').appendChild(maglia);
		$('tipo_maglia_handler').value = t;
		
//		$('setup_maglia').cleanWhitespace().firstChild.src = 'i/maschera_maglia_' + t + '.png';
		
		
	},
	
	initPlayersMenu: function() {
		var playersLink = $$('A.playerLink');
		for(var i=0; i<playersLink.length; i++) {
			playersLink[i].onmouseover = function() {
				this.style.position = 'relative';
				var menu = Builder.node('A', {id: 'btnSfidaMenu', className: 'playersMenu'});
				menu.innerHTML = '<img src="i/btn_sfida.png" class="png" style="width:84px; height: 39px">'
				this.appendChild(menu)
			}
			playersLink[i].onmouseout = function() {
				Element.remove('btnSfidaMenu');
			}
		}
	},
	
	initRoundedBoxes: function() {
		var roundedBox = $$('DIV.roundedBox');
		for(var i=0; i<roundedBox.length; i++) {
						
			var boxProperties = {
				innerHTML: roundedBox[i].innerHTML,
				padding: roundedBox[i].style.padding,
				offsetHeight: roundedBox[i].offsetHeight,
				offsetWidth: roundedBox[i].offsetWidth,
				topGap: 0,
				bottomGap: 0,
				leftGap: 0
			}
			if(document.all) {
				boxProperties.topGap = 2;
				boxProperties.bottomGap = -500;
				boxProperties.leftGap = 25;
			}
			roundedBox[i].innerHTML = '';
			
			roundedBox[i].style.position = 'relative';
			roundedBox[i].style.padding = 0;
			roundedBox[i].style.margin = 0;
			
			var tl = Builder.node('DIV', { className: 'boxCorners', style: 'top: '+(boxProperties.topGap-2)+'px; left: -2px'}, [
				Builder.node('IMG', {src: 'i/roundedBoxCornerMatrix.png', style: 'position: relative; width: 17px; height: 19px', className: 'png'})
			]);
			roundedBox[i].appendChild(tl);
			var tr = Builder.node('DIV', { className: 'boxCorners', style: 'top: '+(boxProperties.topGap-2)+'px; right: '+(boxProperties.leftGap-2)+'px'}, [
				Builder.node('IMG', {src: 'i/roundedBoxCornerMatrix.png', style: 'left: -9px; position: relative; width: 17px; height: 19px', className: 'png'})
			]);
			roundedBox[i].appendChild(tr);
			var bl = Builder.node('DIV', { className: 'boxCorners', style: 'bottom: ' + (- 2 + boxProperties.bottomGap) + 'px; left: -2px'}, [
				Builder.node('IMG', {src: 'i/roundedBoxCornerMatrix.png', style: 'position: relative; top: -10px; width: 17px; height: 19px', className: 'png'})
			]);
			tl.parentNode.appendChild(bl);
			var br = Builder.node('DIV', { className: 'boxCorners', style: 'bottom: ' + (- 2 + boxProperties.bottomGap) + 'px; right: '+(boxProperties.leftGap-2)+'px'}, [
				Builder.node('IMG', {src: 'i/roundedBoxCornerMatrix.png', style: 'position: relative; top: -10px; left: -9px; width: 17px; height: 19px', className: 'png'})
			]);
			roundedBox[i].appendChild(br);
			
			var content = Builder.node('DIV', {style: 'padding: 10px'});
			content.innerHTML = boxProperties.innerHTML;
			roundedBox[i].appendChild(content);
		}
	}
	
}

RX.Text = {
	
	it: {
		
		userDoesntExist: function(userName) {
			return "L'utente " + userName + " non esiste. Selezionare un utente registrato. ";
		}
		
	},
	
	en: {
		
		userDoesntExist: function(userName) {
			return userName + " isn't an existing user. Please select a registered username.";
		}
		
	}
	
}

var UserPanel = {
	
	maxHeight: 	300,
	
	init: function() 
	{
		if ( $('utenti-attivi-win').down("ul").getHeight() > UserPanel.maxHeight) 
				$('utenti-attivi-win').down("ul").setStyle ({ height: UserPanel.maxHeight + "px" });
		if ( $('utenti-online-win').down("ul").getHeight() > UserPanel.maxHeight) 
			$('utenti-online-win').down("ul").setStyle ({ height: UserPanel.maxHeight + "px" });
			
		$('userbox').setStyle ({ top: "-" + ($('userbox-content').getHeight() + 5) + "px"});
		$('userbox').setStyle ({ visibility: "visible"});
		
		// Apertura
		$$('.userbox-opener')[0].observe ("click", function() {
			$('userbox').morph ({
				top: '-10px'
			});
			if ($("user-panel-novita")) {
				Element.remove("user-panel-novita");
				if ( id_utente != "" )
					new Ajax.Request ("ajaxAction.php?request=setNovitaUserPanelVisto&id_utente=" + id_utente);
			}
		});
		
		// Chiusura
		$$('.userbox-closer')[0].observe ("click", function() {
			$('userbox').morph ({ top: "-" + ($('userbox-content').getHeight() + 5) + "px" });
		});
		
		// Apertura in popup
		$$('.userbox-popup')[0].observe ("click", function() {
			UserPanel.popupVersion ();
		});
		
		// Gestione freccia "novità"
		if ($('user-panel-novita')) {
			$('user-panel-novita').setStyle( { visibility: "visible"});
			this.moveNewDown(); 
		}
	},
	
	moveNewDown: function()
	{
		new Effect.Move('user-panel-novita', { x: 0, y: 30, duration: .5, mode: 'relative', afterFinish: function() { UserPanel.moveNewUp(); } });
	},
	
	moveNewUp: function()
	{
		new Effect.Move('user-panel-novita', { x: 0, y: -30, duration: .5, mode: 'relative', afterFinish: function() { UserPanel.moveNewDown(); } });
	},
	
	popupVersion: function() 
	{
		Element.remove('userbox');
		window.name = "RigorixMain";
		RX.popup ("user-panel-popup.php", "Statoutenti", 450, 500);
	}
	
}


function externalCall(f) {
	eval(f);
}


window.onload = function() {
	RX.init();
	
}
