var team_profile_base_url = "http://www.letour.fr/2008/PNC/RIDERS/us/coureurs/";
var jersey_base_url = "http://img.server86.nl/sport/wielrennen/shirts/40/";

var rosters = {"teams": [
  {"name": "GEROLSTEINER", "country": "Germany", "starting_number": "1", "team_profile_ref": "GST_us.pdf", "jersey_ref": "6372.jpg", "leader": "2",
"riders": [[0, "KOHL", "Bernhard", "Austria", 1],
           [0, "MOLETTA", "Andrea", "Italy", 1],
           [0, "REBELLIN", "Davide", "Italy", 1],
           [0, "RUSS", "Matthias", "Germany", 1],
           [0, "SCHUMACHER", "Stefan", "Germany", 1],
           [0, "STAMSNIJDER", "Tom", "Netherlands", 0],
           [0, "WESTPHAL", "Carlo", "Germany", 0],
           [0, "ZAUGG", "Oliver", "Switzerland", 1]]
 },
 {"name": "CAISSE D'EPARGNE", "country": "Spain", "starting_number": "11", "team_profile_ref": "GCE_us.pdf", "jersey_ref": "6367.jpg", "leader": "5",
"riders": [[0, "ARROYO DURAN", "David", "Spain", 1],
           [0, "CHARTEAU", "Anthony", "France", 1],
           [0, "LOPEZ GARCIA", "David", "Spain", 1],
           [0, "LOSADA ALGUACIL", "Alberto", "Spain", 1],
           [0, "PERGET", "Mathieu", "France", 1],
           [0, "PEREIRO", "Oscar", "Spain", 0],
           [0, "PORTAL", "Nicolas", "France", 1],
           [0, "SANCHEZ GIL", "Luis Leon", "Spain", 1]]
 },
  {"name": "LAMPRE", "country": "Italy", "starting_number": "21", "team_profile_ref": "LAM_us.pdf", "jersey_ref": "6374.jpg", "leader": "2",
"riders": [[0, "BONO", "Matteo", "Italy", 1],
           [0, "BOSSONI", "Paolo", "Italy", 1],
           [0, "CUNEGO", "Damiano", "Italy", 1],
           [0, "GAVAZZI", "Francesco", "Italy", 0],
           [0, "LORENZETTO", "Mirco", "Italy", 1],
           [0, "MORI", "Massimiliano", "Italy", 1],
           [0, "SPILAK", "Simon", "Slovenia", 1],
           [0, "TIRALONGO", "Paolo", "Italy", 1]]
 },
  {"name": "LIQUIGAS", "country": "Italy", "starting_number": "31", "team_profile_ref": "LIQ_us.pdf", "jersey_ref": "6401.jpg", "leader": "0",
"riders": [[0, "ALBASINI", "Michael", "Switzerland", 1],
           [0, "BERTAGNOLLI", "Leonardo", "Italy", 0],
           [0, "CARLSTR&Ouml;M", "Kjell", "Finland", 1],
           [0, "CORIONI", "Claudio", "Italy", 1],
           [0, "FRANZOI", "Enrico", "Italy", 1],
           [0, "KREUZIGER", "Roman", "Czech Republic", 1],
           [0, "KUSCHYNSKI", "Aleksandr", "Belarus", 1],
           [0, "SANTAROMITA", "Ivan", "Italy", 1]]
 },
  {"name": "SILENCE-LOTTO", "country": "Belgium", "starting_number": "41", "team_profile_ref": "PRL_us.pdf", "jersey_ref": "6378.jpg", "leader": "3",
"riders": [[0, "AERTS", "Mario", "Belgium", 0],
           [0, "BRANDT", "Christophe", "Belgium", 1],
           [0, "CIONI", "Dario David", "Italy", 0],
           [0, "EVANS", "Cadel", "Australia", 1],
           [0, "LLOYD", "Mathew", "Australia", 1],
           [0, "POPOVYCH", "Yaroslav", "Ukraine", 1],
           [0, "VAN DEN BROECK", "Jurgen", "Belgium", 1],
           [0, "VAN SUMMEREN", "Johan", "Belgium", 1]]
 },
  {"name": "TEAM CSC", "country": "Denmark", "starting_number": "51", "team_profile_ref": "CSC_us.pdf", "jersey_ref": "http://www.steephill.tv/2008/paris-nice/csc-jersey-icon.jpg", "leader": "5",
"riders": [[0, "JULICH", "Bobby", "United States", 1],
           [0, "KOLOBNEV", "Alexandr", "Russia", 1],
           [0, "KROON", "Karsten", "Netherlands", 1],
           [0, "MCGEE", "Bradley", "Australia", 0],
           [0, "MCCARTNEY", "Jason", "United States", 0],
           [0, "SCHLECK", "Frank", "Luxembourg", 1],
           [0, "S&Oslash;RENSEN", "Chris", "Denmark", 1],
           [0, "VOIGT", "Jens", "Germany", 1]]
 },
  {"name": "CR&Eacute;DIT AGRICOLE", "country": "France", "starting_number": "61", "team_profile_ref": "COF_us.pdf", "jersey_ref": "6369.jpg", "leader": "4",
"riders": [[0, "BONNET", "William", "France", 0],
           [0, "BOTCHAROV", "Alexandre", "Russia", 1],
           [0, "FOFONOV", "Dmitriy", "Kazahkstan", 1],
           [0, "GERRANS", "Simon", "Australia", 0],
           [0, "HUSHOVD", "Thor", "Norway", 1],
           [0, "LE MEVEL", "Christophe", "France", 1],
           [0, "PAURIOL", "R&eacute;mi", "France", 1],
           [0, "ROLLAND", "Pierre", "France", 1]]
 } ,
  {"name": "EUSKALTEL - EUSKADI", "country": "Spain", "starting_number": "71", "team_profile_ref": "EUS_us.pdf", "jersey_ref": "6370.jpg", "leader": "1",
"riders": [[0, "ALBIZURI ARANSOLO", "Benat", "Spain", 0],
           [0, "ANTON HERNANDEZ", "Igor", "Spain", 1],    
           [0, "APERRIBAY", "Lander", "Spain", 1],
           [0, "GALPARSORO MARTINEZ", "Dionisio", "Spain", 1],
           [0, "HERNANDEZ GUTIERREZ", "Aitor", "Spain", 1],
           [0, "IRIZAR ARANBURU", "Markel", "Spain", 1],
           [0, "VERDUGO MARCOTEGUI", "Gorka", "Spain", 1],
           [0, "ZUBELDIA AGIRRE", "Haimar", "Spain", 1]]
 },
  {"name": "FRAN&Ccedil;AISE DES JEUX", "country": "France", "starting_number": "81", "team_profile_ref": "FDJ_us.pdf", "jersey_ref": "6371.jpg", "leader": "3",
"riders": [[0, "CASAR", "Sandy", "France", 1],
           [0, "CHEREL", "Micka&euml;l", "France", 0],
           [0, "DI GREGORIO", "R&eacute;my", "France", 0],
           [0, "GILBERT", "Philippe", "Belgium", 1],
           [0, "JEGOU", "Lilian", "France", 1],
           [0, "LE BOULANGER", "Yoann", "France", 1],
           [0, "VANENDERT", "Jelle", "Belgium", 1],
           [0, "VAUGRENARD", "Beno&icirc;t", "France", 1]]
 },
  {"name": "SAUNIER DUVAL - SCOTT", "country": "Spain", "starting_number": "91", "team_profile_ref": "SDV_us.pdf", "jersey_ref": "6377.jpg", "leader": "3",
"riders": [[0, "BENITEZ ROMAN", "Jose Alberto", "Spain", 1],
           [0, "COBO ACEBO", "Juan Jose", "Spain", 1],
           [0, "DUR&Acirc;N AROCA", "Arkaitz", "Spain", 0],
           [0, "GOMEZ MARCHANTE", "Jos&eacute; Angel", "Spain", 0],
           [0, "INTXAUSTI ELORRIAGA", "Benat", "Spain", 1],
           [0, "JUFRE POU", "Josep", "Spain", 1],
           [0, "MORI", "Manuele", "Italy", 0],
           [0, "PASSERON", "Aur&eacute;lien", "France", 1]]
 },
  {"name": "BOUYGUES TELECOM", "country": "France", "starting_number": "101", "team_profile_ref": "BTL_us.pdf", "jersey_ref": "6366.jpg", "leader": "1",
"riders": [[0, "CLEMENT", "Stef", "Netherlands", 0],
           [0, "FEDRIGO", "Pierrick", "France", 0],
           [0, "FLORENCIO CABRE", "Xavier", "Spain", 1],
           [0, "GESLIN", "Anthony", "France", 1],
           [0, "PINEAU", "J&eacute;r&ocirc;me", "France", 1],
           [0, "SPRICK", "Matthieu", "France", 1],
           [0, "TROFIMOV", "Yury", "Russia", 0],
           [0, "TSCHOPP", "Johann", "Switzerland", 1]]
 },
  {"name": "HIGH ROAD", "country": "United States", "starting_number": "111", "team_profile_ref": "BTL_us.pdf", "jersey_ref": "6373.jpg", "leader": "0",
"riders": [[0, "EISEL", "Bernhard", "Austria", 1],
           [0, "GREIPEL", "Andr&eacute;", "Germany", 1],
           [0, "KLIER", "Andreas", "Germany", 1],
           [0, "KNAVEN", "Servais", "Netherlands", 1],
           [0, "LEWIS", "Craig", "United States", 1],
           [0, "POSSONI", "Morris", "Italy", 1],
           [0, "REYNES MIMO", "Vicente", "Spain", 1],
           [0, "SIEBERG", "Marcel", "Germany", 1]]
 },
  {"name": "COFIDIS, LE CR&Eacute;DIT PAR T&Eacute;L&Eacute;.", "country": "France", "starting_number": "121", "team_profile_ref": "COF_us.pdf", "jersey_ref": "6368.jpg", "leader": "0",
"riders": [[0, "CHAVANEL", "Sylvain", "France", 1],
           [0, "DUMOULIN", "Samuel", "France", 0],
           [0, "FERNANDEZ BUSTINZA", "Bingen", "Spain", 1],
           [0, "HUGUET", "Yann", "France", 1],
           [0, "MINARD", "S&eacute;bastien", "France", 1],
           [0, "MOINARD", "Ama&euml;l", "France", 1],
           [0, "MONCOUTIE", "David", "France", 1],
           [0, "MONFORT", "Maxime", "Belgium", 1]]
 },
  {"name": "RABOBANK", "country": "Netherlands", "starting_number": "131", "team_profile_ref": "RAB_us.pdf", "jersey_ref": "6376.jpg", "leader": "3",
"riders": [[0, "DE MAAR", "Marc", "Netherlands", 1],
           [0, "ELIJZEN", "Michiel", "Netherlands", 1],
           [0, "FLECHA GIANNONI", "Juan Antonio", "Spain", 1],
           [0, "GESINK", "Robert", "Netherlands", 1],
           [0, "HAYMAN", "Mathew", "Australia", 0],
           [0, "MOERENHOUT", "Koos", "Netherlands", 1],
           [0, "TANKINK", "Bram", "Netherlands", 0],
           [0, "TEN DAM", "Laurens", "Netherlands", 1]]
 },
 {"name": "AG2R - LA MONDIALE", "country": "France", "starting_number": "141", "team_profile_ref": "AGR_us.pdf", "jersey_ref": "6365.jpg", "leader": "7",
"riders": [[0, "ARRIETA LUJAMBIO", "Jos&eacute; Luis", "Spain", 1],
           [0, "CALZATI", "Sylvain", "France", 1],
           [0, "DEIGNAN", "Philip", "Ireland", 1],
           [0, "DESSEL", "Cyril", "France", 1],
           [0, "DUPONT", "Hubert", "France", 1],
           [0, "EDALEINE", "Christophe", "France", 1],
           [0, "GOUBERT", "St&eacute;phane", "France", 1],
           [0, "NOCENTINI", "Rinaldo", "Italy", 1]]
 },
  {"name": "QUICKSTEP", "country": "Belgium", "starting_number": "151", "team_profile_ref": "QSI_us.pdf", "jersey_ref": "6375.jpg", "leader": "6",
"riders": [[0, "BARREDO LLAMAZALES", "Carlos", "Spain", 1],
           [0, "CARRARA", "Matteo", "Italy", 0],
           [0, "CRETSKENS", "Wilfried", "Belgium", 1],
           [0, "EFIMKIN", "Alexander", "Russia", 1],
           [0, "GARATE", "Juan Manuel", "Spain", 1],
           [0, "HULSMANS", "Kevin", "Belgium", 1],
           [0, "STEEGMANS", "Gert", "Belgium", 1],
           [0, "TOSATTO", "Matteo", "Italy", 1]]
 },
 {"name": "AGRITUBEL", "country": "France", "starting_number": "161", "team_profile_ref": "AGR_us.pdf", "jersey_ref": "6403.jpg", "leader": "5",
"riders": [[0, "BICHOT", "Freddy", "France", 0],
           [0, "GONZALO RAMIREZ", "Eduardo", "Spain", 0],
           [0, "ISTA", "Kevin", "Belgium", 1],
           [0, "JALABERT", "Nicolas", "France", 1],
           [0, "LEQUATRE", "Geoffroy", "France", 1],
           [0, "MOREAU", "Christophe", "France", 1],
           [0, "RINERO", "Christophe", "France", 1],
           [0, "VOGONDY", "Nicolas", "France", 1]]
 },
  {"name": "TEAM MILRAM", "country": "Italy", "starting_number": "171", "team_profile_ref": "MRM_us.pdf", "jersey_ref": "6380.jpg", "leader": "3",
"riders": [[0, "EICHLER", "Markus", "Germany", 1],
           [0, "GHISALBERTI", "Sergio", "Italy", 0],
           [0, "GRABSCH", "Ralf", "Germany", 1],
           [0, "GRIVKO", "Andriy", "Ukraine", 0],
           [0, "KNEES", "Christian", "Germany", 0],
           [0, "SCHR&Ouml;DER", "Bj&ouml;rn", "Germany", 1],
           [0, "TERPSTRA", "Niki", "Netherlands", 1],
           [0, "VELITS", "Peter", "Slovakia", 1]]
 },
  {"name": "SLIPSTREAM CHIPOTLE", "country": "United States", "starting_number": "181", "team_profile_ref": "BTL_us.pdf", "jersey_ref": "6398.jpg", "leader": "4",
"riders": [[0, "EUSER", "Lucas", " United States", 1],
           [0, "FARRAR", "Tyler", "United States", 0],
           [0, "LAURENT", "Christophe", "France", 1],
           [0, "LOWE", "Trent", "Australia", 1],
           [0, "MILLAR", "David", "United Kingdom", 0],
           [0, "PATE", "Danny", "United States", 1],
           [0, "PETERSON", "Thomas", "United States", 1],
           [0, "VANDEVELDE", "Christian", "United States", 1]]
 },
  {"name": "SKIL-SHIMANO", "country": "Netherlands", "starting_number": "191", "team_profile_ref": "BTL_us.pdf", "jersey_ref": "http://www.steephill.tv/2008/paris-nice/skil-shimano-jersey-icon.jpg", "leader": "4",
"riders": [[0, "BEPPU", "Fumiyuki", "Japan", 0],
           [0, "CURVERS", "Roy", "Netherlands", 0],
           [0, "GOESINNEN", "Floris", "Netherlands", 1],
           [0, "HUPOND", "Thierry", "France", 1],
           [0, "LHOTELLERIE", "Cl&eacute;ment", "France", 1],
           [0, "TIMMER", "Albert", "Netherlands", 0],
           [0, "VEELERS", "Tom", "Netherlands", 0],
           [0, "WAGNER", "Robert", "Germany", 0]]
 }	 
 ]
};


for (var i = 0; i < rosters.teams.length; i++) {
	var team = rosters.teams[i];
	var starting_number = Number(team["starting_number"]);
	var leader = Number(team["leader"]);
	var rider = null;
	for (var j = 0; j < team["riders"].length; j++) {
		rider = team["riders"][j];
		if (leader > j)
			rider[0] = starting_number+j+1;
		else if (leader == j)
			rider[0] = starting_number;
		else
			rider[0] = starting_number+j;			
	}	
}



function format_teams() {
	for (var i = 0; i < rosters.teams.length; i++) {
		
		var team = rosters.teams[i];
		document.write('<tr><td>');
		document.write('<img src="'+((team.jersey_ref.indexOf("http")==0)? team.jersey_ref : jersey_base_url+team.jersey_ref)+'" style="margin-left:5px;margin-right:10px" border=0 width=40 align="left"/>');
		document.write('<b>'+team["name"]+'</b><br/>');
		document.write('<small>('+ team["country"] + ')</small>');
		document.write('</td></tr>');
		document.write('<tr><td><table width="325" cellspacing="0" bgcolor="#c7c7c7" style="font-family:Verdana,sans-serif;font-size:x-small;line-height:1.25em">');
		var starting_number = Number(team["starting_number"]);
		var leader = Number(team["leader"]);
		var rider_no = 0;
		var style = "";
		for (var j = 0; j < team["riders"].length; j++) {
			var rider = team["riders"][j];		
			if (rider[1].length < 1) // indicates a skipped race number
				continue;
			// rider number
			style = "";
			if (leader == j)
				style = "color:red;"
			if (rider[4] == 0)
				style = style + "text-decoration:line-through;";
			if (style.length > 0)
				style = ' style="'+ style.substring(0, style.length-1) +'"';
				
			document.write('<tr><td width=25 align=right>');
			if (starting_number > 0) { // write out the race numbers if they have been assigned
				//document.write(rider[3] == 0 ? new String(starting_number+j).strike() : (starting_number+j));
document.write('<a style="text-decoration:none" href="http://www.letour.fr/2008/PNC/RIDERS/us/coureurs/');
				/*if (leader > j)
					rider_no = starting_number+j+1;
				else if (leader == j)
					rider_no = starting_number;
				else
					rider_no = starting_number+j;*/
					
				document.write('' + rider[0] + '.html" onclick="click_track_explicit(this.href);NewWindow(this.href, \'photo player\', 570, 300, \'no\'); return false;">');
				document.write('' + rider[0] + '</a>');
					
				
			}
			document.write('&nbsp;</td>');
			//if ((rider[0].length + rider[1].length) > 30)
				//document.write('<small>');
			// rider last name and first name
			document.write('<td' + style + ' ><b>' + rider[1] + '</b> ' + rider[2] + '</td>');
			// rider country
			document.write('<td' + style + ' width="90">' + rider[3] + '</td></tr>');			
		}
		document.write('</table></td></tr>');
	}
}