function ini(codi) {
	//codi == 0 --> normal
	//codi == 1 --> el path del background ha d baixar un nivell més
	var amplada = screen.width;
	var background_path = "";

	if (amplada <=800) //800 x 600, la imatge fa 385 d'alçada
		background_path = "../img/background_800.jpg";
	else {
		if (amplada >= 1280) //1280 x 800, la imatge fa 560 d'alçada
			background_path = "../img/background_1280.jpg";
		else //1024 x 768, la imatge fa 600 d'alçada
			background_path = "../img/background_1024.jpg";
	}
	
	if (codi == 1)
		background_path = "../" + background_path;

	document.body.background = background_path;
}

/*****************************************************************************************/
/***   MOSTRAR IMATGES   *****************************************************************/
/*****************************************************************************************/
function mostrar_thumbnails(cursa, num_fotos_bbg, num_fotos_altres, num_fotos_nens) {
	var path;
	var step;
	var amplada = screen.width;
	fotos_de_costat = 5;
	if (amplada < 1280)
		fotos_de_costat = 4;
	if (amplada < 1024)
		fotos_de_costat = 3;
	var fotos_en_linia;
	
	var num_elems = new Array(3);
	num_elems[0] = num_fotos_bbg;
	num_elems[1] = num_fotos_altres;
	num_elems[2] = num_fotos_nens;
	var nom_elems = new Array(3);
	nom_elems[0] = "Pilotos&nbsp;BBG";
	nom_elems[1] = "Otros&nbsp;pilotos";
	nom_elems[2] = "Pilotos&nbsp;infantiles";
	var nom_carpeta = new Array(3);
	nom_carpeta[0] = "bbg";
	nom_carpeta[1] = "altres";
	nom_carpeta[2] = "nens";
	var i = 0;
	while (i < 3) {
		document.write("<div class=titol_apartat>" + nom_elems[i] + "</div>");
		document.write("<table border=0 cellpadding=0 cellspacing=15 align=center>");
		step = 0;
		var fotos_en_linia = 0;
		while (step < num_elems[i]) {
			step++;
			if (fotos_en_linia == 0)
				document.write("<tr>");
			document.write("<td>");
			path = "../../img/curses/" + cursa + "/" + nom_carpeta[i] + "/";
			mostrar_thumbnail_amb_ombra(path, step, num_elems[i], nom_elems[i]);
			document.write("</td>");
			fotos_en_linia++;
			if (fotos_de_costat == fotos_en_linia) {
				document.write("</tr>");
				fotos_en_linia = 0;
			}
		}
		if (fotos_en_linia == 0)
			document.write("</table>");
		else
			document.write("</tr></table>");
		i++;
	}
}

function mostrar_thumbnail_amb_ombra(path, pos, num_elems, nom) {
	document.write("<table border=0 cellpadding=0 cellspacing=0 align=center><tr>");
	document.write("<td><a href=javascript:mostrar_imatge('" + path + "'," + pos + "," + num_elems + ",'" + nom + "');><img src=" + path + "petites/" + pos + ".jpg border=0></a></td>");
	document.write("<td valign=top background=../../img/sombres/right.bmp>");
	document.write("<img src=../../img/blanc.bmp width=8 height=6><br>");
	document.write("<img src=../../img/sombres/top_right.bmp width=8 height=8><br>");
	document.write("</td>");
	document.write("</tr><tr>");
	document.write("<td valign=top background=../../img/sombres/bottom.bmp>");
	document.write("<img src=../../img/blanc.bmp width=6 height=8>");
	document.write("<img src=../../img/sombres/bottom_left.bmp width=8 height=8>");
	document.write("</td><td valign=top>");
	document.write("<img src=../../img/sombres/corner.bmp width=8 height=8></td>");
	document.write("</tr></table>");
}

function mostrar_imatge(path, pos, num_elems, nom) {
	var amplada_popup = 600;
	var alcada_foto = 450;
	var alcada_extra = 35;	//pels botonets de baix...
	alcada_popup = alcada_foto + alcada_extra + 29; //29 és l'alçada del mini_logo
	var altura_pantalla = screen.height;
	var distancia_superior = ((altura_pantalla - alcada_popup) / 2) - 30; //aqt 30 és per evitar la barra d'inici de windows
	var amplada_pantalla = screen.width;
	var distancia_esquerra = (amplada_pantalla - amplada_popup) / 2;

	nova_pagina = '<html><head><title>BBGracing</title><link href="../../includes/general.css" rel="stylesheet" type="text/css">';
	nova_pagina += '<link href="../../includes/fotos_cataleg.css" rel="stylesheet" type="text/css">';
	nova_pagina += '<script language="JavaScript" src="../../includes/funcions.js"></script></head><body><img src=../../img/mini_logo.jpg>';
	nova_pagina += '<img name=foto src="' + path + 'grans/' + pos + '.jpg" width = ' + amplada_popup + ' height = ' + alcada_foto + '>';
	nova_pagina += '<div id=pujar><form><table border=0 cellpadding=0 cellspacing=0 width=50% align=center><tr>';
	nova_pagina += '<td align=center><a href=javascript:imatge_anterior("' + path + '","' + nom + '",' + num_elems + ');><img src=../../img/arrow-left.gif border=0></a></td>';
	nova_pagina += '<td align=center><input type=text name=text value="' + nom + ':  ' + pos + ' / ' + num_elems + '"></td>';
	nova_pagina += '<td align=center><a href=javascript:imatge_seguent("' + path + '","' + nom + '",' + num_elems + ');><img src=../../img/arrow-right.gif border=0></a></td>';
	nova_pagina += '</tr></table>';
	nova_pagina += '<input type=hidden name=pos value="' + pos + '"><input type=hidden name=grup></form></div>';
	nova_pagina += '<br><br><br><br><br><br><br><br><br><br><br><br><br><br></body></html>';
	
	popup = window.open("", "", "menu = no, scrollbars = no, resize = no, status = no, width = " + amplada_popup + ", height = " + alcada_popup + ", top = " + distancia_superior + ", left = " + distancia_esquerra);
	popup.document.write(nova_pagina);
}

function imatge_anterior(path, nom, num_elems) {
	var actual = self.document.forms[0].elements['pos'].value;
	if (actual == 1)
		actual = num_elems;
	else
		actual--;
		
	document.foto.src = path + 'grans/' + actual + '.jpg';
	self.document.forms[0].elements['pos'].value = actual;
	//posem el text a la casella del mig
	self.document.forms[0].elements['text'].value = nom + ':  ' + actual + ' / ' + num_elems;
}

function imatge_seguent(path, nom, num_elems) {
	var actual = self.document.forms[0].elements['pos'].value;
	if (actual == num_elems)
		actual = 1;
	else
		actual++;
	document.foto.src = path + 'grans/' + actual + '.jpg';
	self.document.forms[0].elements['pos'].value = actual;
	//posem el text a la casella del mig
	self.document.forms[0].elements['text'].value = nom + ':  ' + actual + ' / ' + num_elems;
}
