// JavaScript Document

//inicialitzar carousel
//$(document).ready(fades);

/*window.onload = fades;

function fades() {
	//per cada element
	for(i=1;i<=8;i++) {
		//fade in
		$("#img"+i).hide();
		$("#img"+i).fadeIn(200*i);
	}
}*/

$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img1').removeClass('loading').append(this);
		i1=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/1.jpg');
});

$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img2').removeClass('loading').append(this);
		i2=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/2.jpg');
});

$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img3').removeClass('loading').append(this);
		i3=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/3.jpg');
});

$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img4').removeClass('loading').append(this);
		i4=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/4.jpg');
});

$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img5').removeClass('loading').append(this);
		i5=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/5.jpg');
});

$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img6').removeClass('loading').append(this);
		i6=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/6.jpg');
});


$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img7').removeClass('loading').append(this);
		i7=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/7.jpg');
});

$(function () {
	var img = new Image();
	$(img).load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#img8').removeClass('loading').append(this);
		i8=$(this);
		estantotes();
		//$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'http://www.bijoulumieres.com/img/imgr.php?w=165&h=165&f=mosaic/8.jpg');
});

function estantotes() {
	if (i1&&i2&&i3&&i4&&i5&&i6&&i7&&i8)	{
		i=200;
		i1.fadeIn(1*i);
		i2.fadeIn(2*i);
		i3.fadeIn(4*i);
		i4.fadeIn(8*i);
		i5.fadeIn(1*i);
		i6.fadeIn(2*i);
		i7.fadeIn(4*i);
		i8.fadeIn(8*i);
	}
}