window.onload = function() {
	for (var i = 0; i < runOnLoad.length; i++) {
		runOnLoad[i]() }
		// hide dotted :focus outlines when mouse is used but NOT when tab key is used
		if(document.getElementsByTagName) {
			for(var i in a = document.getElementsByTagName('A')) {
				a[i].onmousedown = function() {
				this.blur();
				// most browsers
				this.hideFocus = true;
				// ie
				this.style.outline = 'none';
				// mozilla
			}
			a[i].onmouseout = a[i].onmouseup = function() {
				this.blur();
				// most browsers
				this.hideFocus = false;
				// ie
				this.style.outline = null;
				// mozilla
			} 
		}
	}
}
//

function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
	if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
	} else if (test!='R') { num = parseFloat(val);
	if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
	if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
	min=test.substring(8,p); max=test.substring(p+1);
	if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
	} if (errors) if (langflag == "en") { alert("Please insert a valid email address") } else { alert("Si prega di inserire un\'indirizzo email valido") };
	document.MM_returnValue = (errors == '');
}
//
function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//
function start_slideshow(start_frame, end_frame, delay, div_pref) {
	setTimeout(switch_slides(start_frame,start_frame,end_frame, delay, div_pref), delay);
}
//
function switch_slides(frame, start_frame, end_frame, delay, div_pref) {
	return (function() {
        Effect.Fade(div_pref + frame);
        if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
       	setTimeout("Effect.Appear('" + div_pref + frame + "');", 400);
        setTimeout(switch_slides(frame, start_frame, end_frame, delay, div_pref), delay + 400);
    })
}
//
var isNav4, isNav6, isIE;
var coll = "";
var styleObj = "";
// browser detection
if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) {
		isNav4 = true;
	} else {
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) > 4) {
			isNav6 = true;
			styleObj = ".style";
		} else { 
			isIE = true;
			coll = "all.";
			styleObj = ".style";
		}
	}	
}

// returns valid object reference
function getObject(obj) {
	var theObj;
	if (isNav4) {
		theObj = eval("document." + obj);
	} else {
		if (isNav6) {
			theObj = eval("document.getElementById(" + "\"" + obj + "\"" + ")" + styleObj);
		} else {
			theObj = eval("document." + coll + obj + styleObj);
		}
	}
	return theObj;
}
//
function newsScrollOld() {
	/*
	var x1 = new Tween(getObject('news1'),'left',Tween.strongEaseOut,186,10,2,'px');
	x1.start();
	x1.onMotionFinished = function() {
		pauseScroll()
	}
	*/
	shiftBoxes()
}
//
var rollOut = true
var newsList = ["news1", "news2", "news3"]
var prevNews = 0
var nextNews = 1
var t;
var runFlag = true
var tweenRunning
var tweenSpeed = 1
//
function initScroll() {
	/*
	var x1 = new Tween(getObject('news1'),'left',Tween.strongEaseOut,186,10,2,'px');
	x1.start();
	x1.onMotionFinished = function() {
		pauseScroll()
	}
	*/
	shiftBoxes()
}
//
var rollOut = true
var newsList = ["news1", "news2", "news3"]
var prevNews = 0
var nextNews = 1
var t;
var runFlag = true
var tweenRunning
var tweenSpeed = 1
//
function shiftBoxes() {
	if (rollOut) {
		var prevXStart = 0
		var prevXEnd = -300
		var nextXStart = 300
		var nextXEnd = 0
	} else {
		var prevXStart = 300
		var prevXEnd = 0
		var nextXStart = 0
		var nextXEnd = -300
	}
	tweenRunning = true;
	rollOut = !rollOut
	
	var t1 = new Tween(getObject(newsList[prevNews]),'left',Tween.strongEaseInOut,prevXStart,prevXEnd,tweenSpeed,'px');
	t1.start();
	t1.onMotionFinished = function() {
		tweenRunning = false;
		if (runFlag) {
			repeatScroll()
		} else {
			clearTimeout(t)
		}
	}
	var t2 = new Tween(getObject(newsList[nextNews]),'left',Tween.strongEaseInOut,nextXStart,nextXEnd,tweenSpeed,'px');
	t2.start();
}
//
function repeatScroll() {
	rollOut = true
	if (prevNews == newsList.length-1) {
		prevNews = 0
		nextNews = 1
	} else {
		prevNews++
		nextNews++
		if (nextNews > (newsList.length-1)) {
			nextNews = 0
		}
	}
	t = setTimeout("shiftBoxes()",6000);
}
//
function newsScroll(option) {
	if (tweenRunning) {
		return;
	}
	clearTimeout(t)
	switch (option) {
		case 0:
			runFlag = !runFlag
			if (runFlag) {
				shiftBoxes()
			}
			break;
		case 1:
			shiftBoxes()
			break;
	}
}
var time = 0;
var duration = 10;
var begin;
var finish = 0;
var setScrollStart = true;
var scrll = "";

function goTop() {
	scrll = setTimeout("goTop()", 10);
	if (setScrollStart) {
		if (isNav4) {
			begin = top.pageYOffset;
		} else {
			if (isNav6) {
				begin = top.scrollY;
			} else {
				begin = top.document.body.scrollTop;
			}
		}
		setScrollStart = false;
	}
	// calculate the new position
	if (time < duration) {
		change = finish - begin;
		daScrollPos = scrollPos(time++, begin, change, duration);		
	} else {
		// call the function to end the scroll
		endScroll();
		daScrollPos = 0;
	}
	// scroll the page
	if (isNav4) {
		top.scrollTo(0, daScrollPos);
	} else {
		if (isNav6) {
			top.scrollTo(0, daScrollPos);
		} else {
			top.document.body.scrollTop = daScrollPos;
		}
	}
}

// ends the scroll and resets the variables to their starting positions
function endScroll() {
	clearTimeout(scrll);
	time = 0;
	setScrollStart = true;
}
// generates scroll coordinate
function scrollPos(t, b, c, d) {
	return -c*t*t/(d*d) + 2*c*t/d + b;
}
