

var
	sp = new Array(4);
	rnd = Math.floor(Math.random() * 4);
	newrnd = -1;
	ok = true;
	timp = 4000;
	
function init() {	
	for (var i=0; i<4; i++)
		sp[i]=i;
	show_sponsori();
	if (sponsori.length > 4)
		setTimeout("schimba()", timp)
}

function show_sponsori() {
	//afiseaza primii 4 sponsori
	for (var i=0; i<sp.length; i++)	{
		document.getElementById("sp"+i).src="images/sponsors/" + sponsori[sp[i]][1];
		document.getElementById("spl"+i).href=sponsori[sp[i]][0];	
	}
	//preload restul	
	if (document.images) {
		img_obj = new Image();
		for(var i=4; i<sponsori.length; i++)
			img_obj.src = "images/sponsors/" + sponsori[i][1];
	} 
}

function schimba(){		
	newrnd = Math.floor(Math.random() * 4);
	while (newrnd == rnd)
		newrnd = Math.floor(Math.random() * 4);
	rnd = newrnd;
	$("#sp"+rnd).hide('blind', '', 1000, ascunde);	
}
function ascunde() {
	var newimg;
	do {
		ok = false;
		newimg = Math.floor(Math.random() * sponsori.length);
		for (var i = 0; i < sp.length; i++) 
			if (sp[i] == newimg) {
				ok = true;				
			}
	} while (ok);	
	sp[rnd] = newimg;
	document.getElementById("sp"+rnd).src="images/sponsors/" + sponsori[newimg][1];
	document.getElementById("spl"+rnd).href=sponsori[sp[rnd]][0];	
	$("#sp"+rnd).show('blind', '', 1000);
	setTimeout("schimba()", timp);
}
