 		  var base_url = './en/';
		  var img_url  = './';
          var julyFlag = false;
          var augustFlag = false;
          var dataReady = false;
          var bb_top = 0;
          var fc_top = 0;
          var ie6 = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
          var ie7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1));
                    
          
          function MM_showHideLayers() { //v9.0
			  var i,p,v,obj,args=MM_showHideLayers.arguments;
			  for (i=0; i<(args.length-2); i+=3) 
			  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
			    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
			    obj.display=v; }
			   
			}

          function apri(sUrl) {
          
          	window.open(sUrl,'newwindow');
          
          }
                
          
		    $(document).ready(function()
		      {
     
		        if (ie6){
		        	DD_belatedPNG.fix('#header');
		      		DD_belatedPNG.fix('#botbox');
		        	DD_belatedPNG.fix('#bb');
		        	DD_belatedPNG.fix('#top_press_box');
		        	DD_belatedPNG.fix('#bottom_press_box');
		            DD_belatedPNG.fix('#top_gallery_box');
		        	DD_belatedPNG.fix('#bottom_gallery_box');
		        	DD_belatedPNG.fix('.menuitem');
		        	DD_belatedPNG.fix('.number_tab');	        	
		        }	
		
			// let's get the rollovers out of the way
			$("#pressmenu img").hover(
 				function()
 				{
  					this.src = this.src.replace("_off","_on");
 				},
 				function()
 				{
  					this.src = this.src.replace("_on","_off");
 				}
			);

			$("#datesmenu img").hover(
 				function()
 				{
  					this.src = this.src.replace("_off","_on");
 				},
 				function()
 				{
  					this.src = this.src.replace("_on","_off");
 				}
			);
			
			
			bb_top = $("#bottom_bars").css("top");
			fc_top = $("#footer_container").css("top");
			
			
			$("#pressmenu img").click(
				function() {	
				    if (ie6 || ie7 ) {								
						$(".gallery").fadeOut("slow");				
						$("#pressbox").fadeIn("slow");				
						$("#box").hide();
					
					} else {
						$(".gallery").fadeOut("slow");				
						$("#pressbox").slideDown("slow");
						$("#box").slideUp("slow");
					}
					
					$("#bottom_bars").css("top",bb_top);
					$("#footer_container").css("top",fc_top);

				}
			);
			

			
			$("#datesmenu img").click(
				function() {
					
					if (ie6 || ie7 ) {								
						$(".gallery").fadeOut("slow");	
						$("#pressbox").hide();			
						$("#box").fadeIn("slow");				
					} else {
						$(".gallery").fadeOut("slow");
						$("#pressbox").slideUp("slow");
						$("#box").slideDown("slow");
					}
					
					$("#bottom_bars").css("top",bb_top);
					$("#footer_container").css("top",fc_top);
				}
			);		
			
			$("#datesmenu img").addClass("indexcursor");
			$("#pressmenu img").addClass("indexcursor");
			
		
			
			// load main XML index and extract list of matches
		        $.get(base_url + 'sitemap.xml', function(d){
      
		        $(d).find('Node').each(function(){
					
		            var $node = $(this); 
		            var level = $node.attr("level");
					var nome = $node.attr("nome");

                    if (level == 2) {

						$('#content').append("<div class='tappa'  id ='" + nome + "'>\n</div>\n" );	
			
						// now base_url / tappe / + nome + gallery + data.xml should contain the gallery
		    			//     base_url /tappe / + nome  + info + data.html should contain the info about the match
		    			parseGallery(base_url + 'tappe/' + nome + "/gallery/data.xml", nome);
		    			parseDetails(base_url + 'tappe/' + nome + "/info/data.xml",nome);	
	

					}

		        });
		    });
		    		
		// end of document/ready/function
		});
		

		// parse the gallery xml file	
		function parseGallery(url,tag_id) {
		        

				var add_this = "<!-- AddThis Button BEGIN --><a href=\"http://www.addthis.com/bookmark.php?v=250&pub=xa-4a65b83c639f32a4\" onmouseover=\"return addthis_open(this, '', '[URL]', '[TITLE]')\" onmouseout=\"addthis_close()\" onclick=\"return addthis_sendto()\"><img src=\"http://s7.addthis.com/static/btn/lg-share-en.gif\" width=\"125\" height=\"16\" alt=\"Bookmark and Share\" style=\"border:0\"/></a><script type=\"text/javascript\" src=\"http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a65b83c639f32a4\"></script><!-- AddThis Button END -->";

				//create the empty div that will hold all the images
				$('#galleries').append('<div id="gallery_' + tag_id + '" class="gallery"><div class="top_gallery_box"><span id="gallery_' + tag_id + '_title" class="gallerytitle">Match</span><div class="addthis">'+ add_this + ' </div></div><div id="gallery_content"><div id="gallery_' + tag_id + '_intro" class="galleryintro">intro</div><div id="gallery_' + tag_id + '_content" class="oflow"></div></div><div id="bottom_gallery_box"></div></div>');
				  			
			    $.get(url, function(d){		
			  
			    var data = $.xml2json(d).Item; 
			    
			    var html = "";
			    var counter = 0;
			    var num_images = data.length;
			    var image_number = 0;
			    var gallery_hr = '<div class="gallery_hr"><img src="img/pixel.gif"></div>';

			    // loop through the images
			    $.each(data, function(i,image){
									
				  var caption = image.caption_foto.textblock.text;
				  if (caption == undefined) {
				  	caption = "";
				  }
				  image_number++;
				  var image_label = "" + image_number + "/" + num_images;
				  
				  var pad_img = "";
				  
				  if (ie6) {
				  
				    pad_img = "; padding: 1px";
				    
				  
				  } 
				  
				  
				  
				   $('#gallery_'+tag_id+'_content').append('<div class="picture" style="background-image: url(\''+ img_url + image.thumb.path +'\') "><a href="' + img_url + image.big.path +'" rel="lightbox-'+tag_id+'" title="'+ caption +'" style="text-decoration: none" ><div class="number_tab">'+ image_label +'</div></a>\n' + caption + '</div>\n');
				 
				  counter++;

				  if (counter >= 4) {
				  	$('#gallery_'+tag_id+'_content').append(gallery_hr);
				  	
				  	counter = 0;
				  }
				  
				   			   
				}
				);
				
				if ((counter % 4) != 0) {
					$('#gallery_'+tag_id+'_content').append(gallery_hr);
				}	
				
				$("a[rel^='lightbox-"+tag_id+"']").slimbox({/* Put custom options here */ tag_id: 'gallery_' + tag_id + '_title' }, null, function(el) {
					
					return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
				});
					    
		    });			
		}	
			
		
		// parse the details file	
		function parseDetails(url,tag_id) {
				$('#'+tag_id).append('<div id="data_' + tag_id + '" class="details_tappa">\n</div>\n');
			    $.get(url, function(d){
				    
				    var html = "";			    	
				    var i = $.xml2json(d).Item; 
				    				    
			        
				    // keep only numbers , spaces and dashes
				    var match_result = " 0 - 0 ";  //.replace(/[^0-9. ,-]+/g, '');
				    var match_date = i.data_tappa.value;
				    var match_info = "";


					if ((i.risultato_tappa.value) != "undefined") {
						match_result = i.risultato_tappa.value;
					
					}


				    var today = new Date();
				    var de = match_date.split("/");

				    var date = new Date();
				    date.setMonth(Number(de[1])-1);
				    date.setDate(Number(de[0]));
				    date.setYear(Number(de[2]));
				    
					if ((date.getMonth() == 6) && (julyFlag == false)) {
						html += '<div class="month">July</div>';
						julyFlag = true;
						
					}  
					
					if ((date.getMonth() == 7) && (augustFlag == false)){
						html += '<div class="month">August</div>';
						augustFlag = true;
						
					} else	
						html += '<div class="empty_month"></div>';
					
					
					
					if ((i.intro_tappa.textblock.text) == "undefined" ) {
					  match_info = "";	
					
					} else {
						match_info = i.intro_tappa.textblock.text;
					}
					
					var hairline = '<div class="hairline"><img src="img/pixel.gif"/></div>';
														
					html += '<div class="data_tappa">'+  match_date +'</div>';
					html += '<div class="squadre_tappa">'+i.squadre_tappa.value+'</div>';
					html += '<div class="risultato_tappa">'+ match_result +'</div>';
					html += '<div id="tappa_'+ tag_id +'_info" class="hidden">'+match_info+'</div>';
					
					html += '<img  id ="btn_' + tag_id + '" src="img/gallery_btn.jpg" class="gallerybtn" rel="gallery_'+ tag_id +'" />';
					html += hairline;
	
					
					$('#data_'+tag_id).append(html);
					
					
					
					//if (date <= today) {
					if (true) {
						
					    $('#btn_'+ tag_id).addClass("indexcursor");
						// setup the gallery hooks
						$('#btn_'+ tag_id).click(
		 					function()
		 					{
		 					    var gallery_tag = "#" + $(this).attr("rel");
		 					    $(gallery_tag+ "_title").html("&nbsp; " + match_date + ", " + i.squadre_tappa.value + ", " + match_result);		    
		 					    $(gallery_tag+ "_intro").html(match_info);
		 					   	$(gallery_tag).fadeIn("slow", function() {
		 					   	
		 					   		var p = $(gallery_tag).outerHeight() - $("#bottom_bars").position().top - 200;
		 					   		//alert(p);
		 					   	
		 					   		$("#bottom_bars").css("top", p);
		 					   		$("#footer_container").css("top",p - 88); //88	
		 					   	
		 					   	}

		 					
		 					   	);
		 					   	
		 					   
		 					}
						);
					
					} else {
						$('#btn_'+ tag_id).removeClass("indexcursor");
					
					}
					
			
		    });
			
		}	