
	// ROTAB.
	var rotabimgs = new Array();
	var rotabcurrent = 0;
	var rotabinterval = 4000;
	var rotabObjectId = 0;
	var rotabCurrenFilter = 'all';
	var rotabStop;
	var rotabStopCourse;
	var rotabActive = false;
	var rotabCourseArray = new Array();
	var rotabCourseIndex = 0;
	
	function RotabInit() {
		var imgTop = $('rotab').offsetTop;
		var imgLeft = $('rotab').offsetLeft;
		var ihtml = $('rotab').innerHTML;
		for(var i = 2; i < 7; i++) {
			ihtml += '<img src=\"images/rotab' + i + '.jpg\" alt=\"Link all&#39;offerta formativa di DINAMICA\" title=\"Link all&#39;offerta formativa di DINAMICA\" />';
		}
		$('rotab').innerHTML = ihtml;
		rotabimgs = $('rotab').getElementsByTagName('img');
		for(var i = 0; i < rotabimgs.length; i++) {
			rotabimgs[i].xOpacity = 0;
			rotabimgs[i].style.top = imgTop + 'px';
			rotabimgs[i].style.left = imgLeft + 'px';
		}
		rotabimgs[0].xOpacity = .99;
		// Ottiene l'elenco delle province che propongono dei corsi.
		new Ajax.Request('/defaultsvr.cfm',
		{
			method: 'post',
			parameters: {action: 'listapro'},
			onSuccess: function(transport) {
				$('listapro').innerHTML = transport.responseText + '<input type=\"image\" onclick=\"RotabStop(); return false;\" src=\"/images/rotab_stop.gif\" alt=\"Arresta animazione\" title=\"Arresta animazione\" style=\"padding-left: 10px;\" />'  + '<input type=\"image\" onclick=\"RotabStart(); return false;\" alt=\"Avvia animazione\" title=\"Avvia animazione\" src=\"/images/rotab_start.gif\" />';
			},
			onFailure: function() {
				alert('errore');
			},
			onComplete: function(transport) {
			}
		});
		return false;
	}

	function RotabStart() {
		if (rotabActive == false) {
			GetCourses();
			setTimeout(RotabXFade, rotabinterval);
			rotabActive = true;
		}
		return false;
	}

	function RotabStop() {
		if (rotabActive == true) {
			clearTimeout(rotabStopCourse);
			clearTimeout(rotabStop);
			rotabActive = false;
		}
	}
	
	function GetCourses() {
		new Ajax.Request('/defaultsvr.cfm',
		{
			method: 'post',
			parameters: {action: 'getcourses', filter: rotabCurrenFilter},
			onSuccess: function(transport) {
				rotabCourseArray = transport.responseText.split('|');
				//rotabCourseArray = new Array;
				//var stringa = '0|Inizio|1|Mezzo|2|Fine|';
				//rotabCourseArray = stringa.split('|');
			},
			onFailure: function() {
				alert('---');
			},
			onComplete: function(transport) {
				if (rotabCourseArray.length > 0) {
					rotabCourseIndex = 0;
					rotabStopCourse = setTimeout(ShowCourses, 2000);
				}
			}
		});
	}

	function ShowCourses() {
		$('rotabtext').innerHTML = rotabCourseArray[rotabCourseIndex + 1];
		rotabObjectId = rotabCourseArray[rotabCourseIndex];
		rotabCourseIndex += 2;
		if (rotabCourseIndex >= rotabCourseArray.length - 1) {
			rotabCourseIndex = 0;
		}
		rotabStopCourse = setTimeout(ShowCourses, 2000);
	}
	
	function RotabXFade() {
		cOpacity = rotabimgs[rotabcurrent].xOpacity;
		nIndex = rotabimgs[rotabcurrent+1]?rotabcurrent+1:0;
		nOpacity = rotabimgs[nIndex].xOpacity;

		cOpacity -= .05; 
		nOpacity += .05;
		
		rotabimgs[nIndex].style.display = "block";
		rotabimgs[rotabcurrent].xOpacity = cOpacity;
		rotabimgs[nIndex].xOpacity = nOpacity;
		
		setOpacity(rotabimgs[rotabcurrent]); 
		setOpacity(rotabimgs[nIndex]);
		
		if(cOpacity <= 0) {
			rotabimgs[rotabcurrent].style.display = "none";
			rotabcurrent = nIndex;
			rotabStop = setTimeout(RotabXFade, rotabinterval);
		} else {
			rotabStop = setTimeout(RotabXFade, 50);
		}
		
		function setOpacity(obj) {
			if(obj.xOpacity>.99) {
				obj.xOpacity = .99;
				return;
			}
			obj.style.opacity = obj.xOpacity;
			obj.style.MozOpacity = obj.xOpacity;
			if (gIEVersion == 5 || gIEVersion == 6) {
				obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
			}
		}
	}

	function RotabSetFilter(codPro) {
		var msg;
		rotabCurrenFilter = codPro;
		rotabObjectId = 0;
		if (rotabCurrenFilter == 'all') {
			msg = 'Tutti i corsi...';
		}else{
			msg = 'DINAMICA a ' + rotabCurrenFilter + "...";
		}
		$('rotabtext').innerHTML = "<span style='color: #FFB200;'>" + msg + '</span>';
		clearTimeout(rotabStopCourse);
		GetCourses();
		return false;
	}

	function RotabNavigate() {
		var destUrl = '/corsi.cfm';
		if (rotabObjectId == 0) {
			window.location = destUrl + '?pr=' + rotabCurrenFilter;
		}else{
			window.location = destUrl + '?id=' + rotabObjectId + '&pr=' + rotabCurrenFilter;
		}
	}

	function GetNews() {
		new Ajax.Request('/defaultsvr.cfm',
		{
			method: 'post',
			parameters: {action: 'listnews'},
			onSuccess: function(transport) {
				$('scrollernews').innerHTML = transport.responseText;
			},
			onFailure: function() {
				//alert('errore');
			},
			onComplete: function(transport) {
					new scrollObject("scrollernews", 650, 27, "up", 5000, 1.15);
			}
		});
		return false;
	}


	/* ********************************************************************
	 * The Mighty ScrollObject
	 *   - Don't edit this if you know what's good for ya!
	 *
	 */

	//new scrollObject("scrollernews", 120, 120, "up", 5000, 1.15);

	function scrollObject(main, width, height, direct, pause, speed) {
		var self = this;
		this.main = main;
		this.width = width;
		this.height = height;
		this.direct = direct;
		this.pause = pause;
		this.speed = Math.max(1.001, Math.min((direct == "up" || direct == "down") ? height : width, speed));
		this.slope = (direct == "up" || direct == "left") ? 1 : -1;
		this.prev = this.offset = 0;
		this.curr = 1;
		this.mouse = false;

		this.scroll = function() {
			this.main = document.getElementById(this.main);
			this.main.style.overflow = "hidden";
			this.main.style.position = "relative";
			this.main.style.width = this.width + "px";
			this.main.style.height = this.height + "px";
			var b = [], c;
			while (this.main.firstChild) if ((c = this.main.removeChild(this.main.firstChild)).nodeName == "DIV") b.push(c);
			for (var x = 0; x < b.length; x++) {
				var table = document.createElement('table');
				table.cellPadding = table.cellSpacing = table.border = "0";
				table.style.position = "absolute";
				table.style.left = table.style.top = "0px";
				table.style.width = table.style.height = "100%";
				table.style.overflow = table.style.visibility = "hidden";
				var tbody = document.createElement('tbody');
				var tr = document.createElement('tr');
				var td = document.createElement('td');
				while (b[x].firstChild)
					td.appendChild(b[x].removeChild(b[x].firstChild));
				tr.appendChild(td);
				tbody.appendChild(tr);
				table.appendChild(tbody);
				this.main.appendChild(table);
			} b = c = null;
			if (this.main.childNodes.length > 1) {
				this.main.onmouseover = function() { self.mouse = true; };
				this.main.onmouseout = function() { self.mouse = false; };
				setInterval(function() {
				if (!self.offset && self.scrollLoop()) self.main.childNodes[self.curr].style.visibility = "visible";
				}, this.pause);
			} this.main.childNodes[this.prev].style.visibility = "visible";
		};

		this.scrollLoop = function() {
			if (!this.offset) {
				if (this.mouse) return false;
				this.offset = (this.direct == "up" || this.direct == "down") ? this.height : this.width;
			} else this.offset = Math.floor(this.offset / this.speed);
			if (this.direct == "up" || this.direct == "down") {
				this.main.childNodes[this.curr].style.top = (this.offset * this.slope) + "px";
				this.main.childNodes[this.prev].style.top = ((this.offset - this.height) * this.slope) + "px";
			} else {
				this.main.childNodes[this.curr].style.left = (this.offset * this.slope) + "px";
				this.main.childNodes[this.prev].style.left = ((this.offset - this.width) * this.slope) + "px";
			}
			if (!this.offset) {
				this.main.childNodes[this.prev].style.visibility = "hidden";
				this.prev = this.curr;
				if (++this.curr >= this.main.childNodes.length) this.curr = 0;
			} else setTimeout(function() { self.scrollLoop(); }, 30);
			return true;
		};
		/*if (window.addEventListener) {
		window.addEventListener('load', function() { self.scroll(); }, false); 
		} else if (window.attachEvent)
		window.attachEvent('onload', function() { self.scroll(); });*/
		self.scroll();
	}
