// JavaScript Document

var timers=new Array();
var bannerImg=new Array();
var loghiTimer;
var count=0;

function slide(elem,foto){
	var fotina = document.getElementById('fotinaroll');
  	var contenitore=document.getElementById(elem);
  	if(fotina!=null)contenitore.removeChild(fotina);

	contenitore=document.getElementById(elem);
	
	span=document.createElement('span');
	span.setAttribute('id','fotinaroll');
	span.innerHTML="<img src='"+foto+"' border='0' />";
	
	contenitore.appendChild(span);
}

function menu_on(menu) {
	$(".submenu").hide(0, function() {
    	$("#"+menu).show();
  	});
}

function getEvent(elem,cat,lan) {
	$.ajax({
		type: "POST",
		cache: false,
		url: "../countdown.php",
		data: "op=nextevent&categoria="+cat+"&lan="+lan,
		success: function(html){
			if(html==""){
				switch (lan) {
					case "it":
						$("#"+elem).html("Loading data...");
					break;
					case "en":
						$("#"+elem).html("Loading data...");
					break;
				}
			} else $("#"+elem).html(html);
		}
	});
}

function setTimers(arr,lan) {
	for (i=0;i<arr.length;i++){
		getEvent(arr[i].elem,arr[i].cat,lan);
		timers.push(setInterval("getEvent(\""+arr[i].elem+"\",\""+arr[i].cat+"\",\""+lan+"\")", 600000));
	}
}

$(document).ready(function() {
	clearInterval(loghiTimer);
  $('.bannerImg').each(function(index) {
    bannerImg.push($(this));
	$(this).hide();
  });
  if(bannerImg.length>0) {
		bannerImg[0].show(0,function(){
			count=0;
			loghiTimer=setInterval(slideBanner,6000);
		});
  }
});

function slideBanner(){
	oldcount=count;
	count++;
	if(count==bannerImg.length)count=0;
	bannerImg[count].fadeIn(500, "linear");
	bannerImg[oldcount].fadeOut(500, "linear");
}
function MM_openBrWindow(theURL,winname,features) { //v2.0
  var pop = window.open(theURL,winname,features);
  pop.focus();
}

