var cnt = 0;
var total = 0;
var imgcnt = 0;
var pcnt = 0;
var cntpic = 0;

function rotateimg(urls, imgs, wids, higs, tot, imagesToDisplay)
{
	total = tot;
	id = setInterval("imgChange('" + imgs + "', '" + urls + "', '" + wids + "', '" + higs + "', '" + imagesToDisplay + "')", 5000);
}

function imgChange(x, y, w, h, imagesToDisplay)
{
	var num =  cnt % total;
	var imgnum = imgcnt % imagesToDisplay;
	imgName = "ad" + imgnum
    anchorName = "adhref" + imgnum;
    
    newimg = x.split(",");
	newurl = y.split(",");
	newwidth = w.split(",");
	newheight = h.split(",");
	
	document.images[imgName].src = "/images/ads/" + newimg[num];
    document.images[imgName].width = newwidth[num];
    document.images[imgName].height = newheight[num];
    var currentAd = document.getElementsByName(anchorName)[0];
    currentAd.href = newurl[num];
        
   	cnt++;
	imgcnt++;
	cntpic++;
}

	function CaricaFoto(img){
	  foto1= new Image();
	  foto1.src=(img);
	  Controlla(img);
	}
	function Controlla(img){
	  if((foto1.width!=0)&&(foto1.height!=0)){
		viewFoto(img);
	  }
	  else{
		funzione="Controlla('"+img+"')";
		intervallo=setTimeout(funzione,20);
	  }
	}
	function viewFoto(img){
	  largh=foto1.width+20;
	  altez=foto1.height+20;
	  stringa="width="+largh+",height="+altez;
	  finestra=window.open(img,"",stringa);
	}
