var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

// 1 parametro: id dell'oggetto sul quale applicare l'effetto
// 2 parametro: valore di opacità
function setOpacity(id, opacity) {
 
  var element = document.getElementById(id);
 
  if(document.all) // se sto usando internet explorer
    element.style.filter = "alpha(opacity=\"" + opacity + "\")";
  else
    element.style.opacity = opacity / 100;
 
}

// 1 parametro: id dell'oggetto sul quale applicare l'effetto
// 2 parametro: tempo dell'animazione
function fadeIn_l(divID, time) {
 
  var speed = Math.round(time / 100); //arrotonda il valore della divisione
  var frame = 0;
 
  for(fade = 0; fade<101; fade++) {
    setTimeout("setOpacity('"+divID+"', "+fade+")", (speed * frame));
    frame++;
  }
 
}

function fadeOut_l(divID, time) {
 
  var speed = Math.round(time / 100); //arrotonda il valore della divisione
  var frame = 0;
 
  for(fade = 100; fade>0; fade--) {
    setTimeout("setOpacity('"+divID+"', "+fade+")", (speed * frame));
    frame++;
  }
 
}

function direttaIn () {	
var x=document.getElementById('headbar1');
var y=15;
var z=0;
var a=document.getElementById('headbar');
var b=1;

if (document.all) {x.style.zIndex=y;a.style.zIndex=b;}
else {
x.style.zIndex=y;
x.style.opacity=z;
fadeIn_l ('headbar1', 200);
a.style.zIndex=b;}
}

function direttaOut () {
var x=document.getElementById('headbar');
var y=15;
var z=0;
var a=document.getElementById('headbar1');
var b=1;
if (document.all) {x.style.zIndex=y;a.style.zIndex=b;}
else {
x.style.zIndex=y;
x.style.opacity=z;
fadeIn_l ('headbar', 200);
a.style.zIndex=b;}
}

function button_over1(cur) {
if (document.getElementById && document.getElementsByTagName){
		var c=document.getElementById('bottone1').getElementsByTagName("img");
		var d=c[0];
		d.setAttribute("src", "CeD_over.png");
		var e=document.getElementById('bottone2').getElementsByTagName("img");
		var f=e[0];
		f.setAttribute("src", "CeD_out.png");
}
}

function button_over2(cur) {
if (document.getElementById && document.getElementsByTagName){
		var c=document.getElementById('bottone2').getElementsByTagName("img");
		var d=c[0];
		d.setAttribute("src", "CeD_over.png");
		var e=document.getElementById('bottone1').getElementsByTagName("img");
		var f=e[0];
		f.setAttribute("src", "CeD_out.png");
}
}

////////////////////////////////////////////////////////
///////////////SELETTORI NOTIZIE E SEZIONI//////////////
////////////////////////////////////////////////////////


/* ARRAY PER LE NOTIZIE */
var titoli= new Array();
var nomiVideo= new Array();
var date= new Array();
var nomiPrev= new Array();
var counterArray=0;

function notizia (titolo, nomeVideo, data, nomePrev) {
titoli[counterArray]=titolo;
nomiVideo[counterArray]=nomeVideo;
date[counterArray]=data;
nomiPrev[counterArray]=nomePrev;
counterArray++;
} 

function riversa () {
titoli.reverse();
nomiVideo.reverse();
date.reverse();
nomiPrev.reverse();
}

/* BOX LI PER LE NOTIZIE */

function PrevNext(divID) {
	var divScorr=document.getElementById(divID);
	var prec=document.createElement('a');
	
}

function panelNews(Div, larghezza, altezza, conNews, numNews) {
	if (document.getElementById && document.createElement && document.appendChild) {			
			var a=document.getElementById(Div);
			var l=0;
		for (w=0; w<numNews; w++) {
			var b=document.createElement('ul');
			a.appendChild(b);
			var p=b.getElementsByTagName('li');
			for (j=0; p.length<conNews && l<numNews; j++) {
				var c=document.createElement('li');
				c.style.width=larghezza+"px";
				c.style.height=altezza+"px";
				var linka=document.createElement('a');
				linka.setAttribute("href", "#");
				linka.onclick=function () {window.scrollTo(0, 0)}
				var h=document.createElement('div');
				h.style.position="relative";
				h.style.width="100%";
				h.style.height="100%";
				var d=document.createElement('div');
				d.style.position="relative";
				d.style.top="0px";
				d.style.width="100%";
				d.style.fontSize="10px";
				d.style.fontFamily="Verdana";
				d.style.color="#333333";
				d.style.textAlign="left";
				d.style.backgroundColor="#CCCCCC";
				dat=date[l];
				d.innerHTML="<b>&bull;"+dat+"<b/>";
				var e=document.createElement('div'); e.id
				e.style.position="relative";
				e.style.top="2px";
				e.style.width="90px";
				e.style.height="68px";
				e.style.margin="auto";
				e.style.border="2px #000000 solid";
				e.style.borderTopColor="#CCCCCC";
				e.style.borderRightColor="#111111";
				e.style.borderLeftColor="#333333";
				e.style.borderBottomColor="#000000";
				var anteprima=document.createElement('img');
				anteprima.setAttribute("src", nomiPrev[l]);
				anteprima.setAttribute("width", "90");
				anteprima.setAttribute("height", "68");
				anteprima.setAttribute("border", "0");
				e.appendChild(anteprima);
				var f=document.createElement('div');
				f.style.position="absolute";
				f.style.bottom="-28px";
				f.style.width="100%";
				f.style.color="#FFFFFF";
				f.style.fontSize="10px";
				f.style.fontFamily="Verdana";
				f.style.backgroundColor="#C1272D";
				title=titoli[l];
				if(title.length>43){title=title.substr(0, 37)+"...";}
				f.innerHTML="<b>"+title+"<b/>";
				linka.appendChild(h);
				b.appendChild(c);
				c.appendChild(linka);
				h.appendChild(d);
				h.appendChild(e);
				h.appendChild(f);
				w++;
				l++;
		}
	  	w--;
	  }
	}
}

function tempo() {
var x=new Date();
h=x.getHours();
m=x.getMinutes();
s=x.getSeconds();
if(s<=9) s="0"+s;
if(m<=9) m="0"+m;
if(h<=9) h="0"+h;
time=h+":"+m+":"+s;
document.getElementById('dataora').innerHTML="<b>Giorno: "+x.getDate()+"/"+(x.getMonth()+1)+"/"+x.getFullYear()+" - Ora: "+time+"</b>";
setTimeout("tempo()",1000); }


function videoPlayerHome(playlist) {
	var video = new SWFObject('player.swf','mpl','1000','571','9');
	video.addParam('allowfullscreen','true');
	video.addParam('allowscriptaccess','always');
	video.addVariable('file',''+playlist+'');
	video.addVariable("overstretch","fit");
	video.addVariable("shuffle","false");
	video.addVariable("thumbsinplaylist","true");
	video.addVariable('playlistsize','345');
	video.addVariable('playlist','right');
	video.addVariable('backcolor','333333');
	video.addVariable('frontcolor','FFFFFF');
	video.addVariable('lightcolor','CCCCCC');
	video.addVariable('screencolor','000000');
	video.addVariable('autostart','true');
	video.addVariable('skin', 'kleur.swf');
	video.write('videocontainer');
}

function videoPlayer(playlist) {
	var video = new SWFObject('player.swf','mpl','1000','571','9');
	video.addParam('allowfullscreen','true');
	video.addParam('allowscriptaccess','always');
	video.addVariable('file',''+playlist+'');
	video.addVariable("overstretch","fit");
	video.addVariable("shuffle","false");
	video.addVariable("thumbsinplaylist","true");
	video.addVariable('playlistsize','345');
	video.addVariable('playlist','right');
	video.addVariable('backcolor','333333');
	video.addVariable('frontcolor','FFFFFF');
	video.addVariable('lightcolor','CCCCCC');
	video.addVariable('screencolor','000000');
	video.addVariable('autostart','false');
	video.addVariable('skin', 'kleur.swf');
	video.write('videocontainer');
}


function scorrisezione() {
		$('#scorrimento div').click(function(){
		var index = $("#scorrimento div").index(this);
		$('#contenitore').animate({"marginLeft" : -i*1000 + "px"}); // multiply by height+top/bottom padding/margin/border
		return false;
		});
}

function news() {
		$('#lista').animate({"marginTop" : -q*20 + "px"}, 1000, 'easeOutQuint'); // multiply by height+top/bottom padding/margin/border
		w=w-20;
		q++;
		y=$('#lista').find("li").length;
		y1=((y+2)/2)*(-20);
		if (y1==w) {
			$('#lista').animate({"marginTop" : 20 + "px"}, 0, 'easeOutQuint'); // multiply by height+top/bottom padding/margin/border
			$('#lista').animate({"marginTop" : 0 + "px"}, 1000, 'easeOutQuint'); // multiply by height+top/bottom padding/margin/border
			q=0; w=0;
		}
		setTimeout ("news()", 8000);
}

