var actualBanner = 1;
var cacheIndex = 1;
window.onload = init;



function init() {
	setTimeout('fadeIn(' + actualBanner + ');', 1000);
	setInterval('changePicture();', 7000);
}

function changePicture() {
	var picture = $('#main-picture');
	var id = picture.attr('name');
	
	picture.fadeOut(1500, function() {
		++id;
		if(id > 3) id = 1;
	
		picture.attr('name', id);
		picture.attr('src', '/images/pictures/' + id + '.jpg');
	
		picture.fadeIn(1500);
	
	});
	

	
}

function fadeOut(i) { 
	obj = document.getElementById('banner' + i);
	if(cacheIndex < 50) {
		obj.style.opacity =  1 - ((cacheIndex * 2) / 100);
		cacheIndex = cacheIndex + 1;
		
		setTimeout('fadeOut(' + i + ')', 8);
	} else if(cacheIndex == 50) {
		next = i + 1;
		if(next > 3) {
			actualBanner = 1;
			next = 1;
		}
		obj.style.opacity = 1;
		obj.style.display = 'none';
		cacheIndex = 1;
		setTimeout('fadeIn(' + next + ');', 600);
	}
}
function fadeIn(i) {
	obj = document.getElementById('banner' + i);
	obj.style.display = 'block';
	if(cacheIndex < 50) {
		obj.style.opacity = (cacheIndex * 2) / 100;
		cacheIndex = cacheIndex + 1;
		
		setTimeout('fadeIn(' + i + ')', 10);
	} else if(cacheIndex == 50) {
		obj.style.opacity = 1;
		cacheIndex = 1;
		if(i == 3) {
			setTimeout('fadeOut(' + i + ');', 7000);
		} else {
			setTimeout('fadeOut(' + i + ');', 4000);
		}
	}
}

