		
		var bg_w = 0;
		var cur_w = 0;
		var scroll_pause = 0;
		var cross_counter = 1;
		var cross_direction = 1;
		var cross_pause = 0;
		var random_pause = 1;
		var cross_photo = 0;
		var background_total_width = 14453;
		var photo_array = [];
		var last_photo = "";
		var prev_photo = "s01";
		var prev_photo_count = "s01";
		var autocross_interval = 8000;




		google.load("jquery", "1");

		google.setOnLoadCallback(function(){



			$.each( video, function(video, title){
				$("#video-lenta").append('<li><img src="./video/'+video+'.jpg" onclick="show_video(\''+video+'\')" id="video'+video+'" rel="'+title+'" /></li>');
			});

			 $.each( bg, function(){

				$("#lenta").append('<img src="./background/'+this+'.jpg" />');

			});
			$("#lenta img").each(function(){
				cur_w = $(this).width();
				bg_w += cur_w;
			});
			bg_w = bg_w - cur_w;
			bg_w = background_total_width;
			// scrolID = setInterval( scrol_bg, 40);
			crossID = setInterval( crossfade_bg, 6000);			
			autocrossID = setInterval( show_random_photo, autocross_interval);
			clearInterval( autocrossID);

			// pre-output initial photo
			// alert ("<img src='./photos/"+prev_photo+".jpg' height='99%'>");
			// $("#photo-box-1").html("<img src='./photos/"+prev_photo+".jpg' height='99%'>");
			// $("#photo-box-2").html("<img src='./photos/"+prev_photo+".jpg' height='99%'>");

			
			var div2 = $('div#video-block'),
				ul2 = $('ul#video-lenta'),
				ulPadding2 = 15;
			
			var divWidth2 = div2.width();
			div2.css({overflow: 'hidden'});
			var lastLi2 = ul2.find('li:last-child');
			
			div2.mousemove(function(e){
				var ulWidth = lastLi2[0].offsetLeft + lastLi2.outerWidth() + ulPadding2 + ulPadding2;
				var left = (e.pageX - div2.offset().left) * (ulWidth-divWidth2) / divWidth2;
				div2.scrollLeft(left);
			});			
			


			
		});
		function show_random_photo (){

//			clearInterval (crossID);
//			show_photo ( photo_array [ Math.floor( Math.random( ) * (photo_array.length) ) ] );

		    var next_photo = 0;
			var max = photo_array.length;
			for(var i=0; i<=max; i=i+1)
			{
				if( photo_array[i] == prev_photo) 
				{
					if ( i < max - 1)
					{
						next_photo = i + 1;
					}
					else
					{
						next_photo = 0;
					}

				}
			}
			show_photo ( photo_array [ next_photo ] );



		}

		function click_piercing()
		{

			open_photo_page ();
			clearInterval (autocrossID);
			open_text_page ("piercing");

		}

		function show_photo(photo){

			$("#cross-bg").hide();

			clearInterval (autocrossID);

			var fade1 = $('#photo-box-1');
			var fade2 = $('#photo-box-2');

			if (cross_photo == 0)
			{
			
			  $("#photo-box-1").html("<img src='./photos/"+prev_photo+".jpg' height='99%'>");
			  $("#photo-box-2").html("<img src='./photos/"+photo+".jpg' height='99%'>");
			

			  fade2.fadeIn(3000);					  

			  if (fade2.is(':animated'))
			  {
				  fade2.stop().fadeTo(3000, 1);
			  }
			  else
			  {
				  fade1.fadeOut(3000);			
			  }

			  cross_photo = 1;
			}
			else
			{
			  $("#photo-box-2").html("<img src='./photos/"+prev_photo+".jpg' height='99%'>");
			  $("#photo-box-1").html("<img src='./photos/"+photo+".jpg' height='99%'>");
			  $("#photo-box-2").show();

			  fade2.fadeOut(3000);
			  fade1.fadeIn(3000);			
			  cross_photo = 0;

			 }
 			prev_photo = photo;

			autocrossID = setInterval( show_random_photo, autocross_interval);


			data = $("#photo" + photo).attr("rel");
			$("#small-title").html(data);
			$("#small-title2").html(data);
			$("#big-title").html(data);
			$("#big-title2").html(data);
	
		}

		function show_photo_still(photo){

			$('#wrapper').hide();
			$("#cross-bg").hide();
//			$('#photo-box').hide();

			clearInterval (autocrossID);

			var fade1 = $('#photo-box-1');
			var fade2 = $('#photo-box-2');

			if (cross_photo == 0)
			{
			
			  $("#photo-box-1").html("<img src='./photos/"+prev_photo+".jpg' height='99%'>");
			  $("#photo-box-2").html("<img src='./photos/"+photo+".jpg' height='99%'>");
			

			  fade2.fadeIn(3000);					  

			  if (fade2.is(':animated'))
			  {
				  fade2.stop().fadeTo(3000, 1);
			  }
			  else
			  {
				  fade1.fadeOut(3000);			
			  }

			  cross_photo = 1;
			}
			else
			{
			  $("#photo-box-2").html("<img src='./photos/"+prev_photo+".jpg' height='99%'>");
			  $("#photo-box-1").html("<img src='./photos/"+photo+".jpg' height='99%'>");
			  $("#photo-box-2").show();

			  fade2.fadeOut(3000);
			  fade1.fadeIn(3000);			
			  cross_photo = 0;

			 }
 			prev_photo = photo;

			// autocrossID = setInterval( show_random_photo, autocross_interval);


			data = $("#photo" + photo).attr("rel");
			$("#small-title").html(data);
			$("#small-title2").html(data);
			$("#big-title").html(data);
			$("#big-title2").html(data);
	
		}


		function show_video(video){
			//$("#video-box").html("<a href='./video/"+video+".flv' id='player'></a>").show();
			//flowplayer("player", "./flowplayer/flowplayer-3.1.5.swf");

			var so = new SWFObject("./video/player.swf",video,"480","360","7","#404040");
			so.addVariable("file", video+".flv");
			so.addVariable("image", "bodybag-splash.jpg");
			so.addVariable("autostart", "true");
			so.write("video-box");

			data = $("#video" + video).attr("rel");
			$("#small-title").html(data);
			$("#small-title2").html(data);
			$("#big-title").html(data);
			$("#big-title2").html(data);
		}
		
		function scrol_bg(){
			cur_m = $("#scroll-bg").css("marginLeft");
			if (cur_m==NaN || cur_m == "auto") cur_m = 0;
			new_m = parseInt(cur_m) - 1 * speed;
			if (new_m < (0 - bg_w) || new_m >= 0 ) speed = 0 - speed;
			$("#scroll-bg").css("marginLeft", new_m+"px");
		}

		function crossfade_bg(){
			$("#lenta").append('<img src="./background/3.jpg" />');
			// $("#scroll-bg img").fadeTo (300, 0)
			// $("#cross-bg-1").fadeOut (300)
			// $("#cross-bg-2").fadeTo (300, 1.0)
			// on hovering over, find the element we want to fade *up*
			if (cross_direction == 1)
			{
			  cross_counter = cross_counter+1; if (cross_counter==10)
			  {
				  cross_direction=0;
			  }
			  var fade = $('#cross-bg-'+cross_counter);
			  if (fade.is(':animated')) {
				  // ...take it's current opacity back up to 1
				  fade.stop().fadeTo(1000, 1);
				} else {
				  // fade in quickly
				  fade.fadeIn(1000);
				}

			}

			 else	{
			  cross_counter = cross_counter-1; if (cross_counter==1)
			  {
				  cross_direction=1;

			  }

				 var fade = $('#cross-bg-'+(cross_counter+1));
				 if (fade.is(':animated')) {
				  fade.stop().fadeTo(1000, 0);
				} else {
				  // fade away slowly
				  fade.fadeOut(1000);
				}
	

			}


		} // crossfade_bg
		

		function open_text_page(page){
		
			$("#nav_dovesiamo").css("text-decoration", 'none');
			$("#nav_chisiamo").css("text-decoration", 'none');
			$("#nav_piercing").css("text-decoration", 'none');
			$("#nav_photo").css("text-decoration", 'none');
			$("#nav_cartoline").css("text-decoration", 'none');
			$("#nav_certificati").css("text-decoration", 'none');

			$("#nav_video").css("text-decoration", 'none');
			$("#nav_link").css("text-decoration", 'none');

			if (page == "dove"){ $('#wrapper').hide(); $("#cross-bg").show(); $("#nav_dovesiamo").css("text-decoration", 'underline');}
			if (page == "chi") {$('#wrapper').hide();  $("#cross-bg").show(); $("#nav_chisiamo").css("text-decoration", 'underline');}
			if (page == "chi_slow") {$('#wrapper').hide();  $("#cross-bg").show(); $("#nav_chisiamo").css("text-decoration", 'underline');}
			if (page == "piercing"){$("#nav_piercing").css("text-decoration", 'underline');}
			if (page == "link"){$("#nav_link").css("text-decoration", 'underline');}

			$("#bottom-menu").show();
			$("#email-link").hide();
			$(".content_block").hide();
			$("#piercing-text").hide();
			if ( page == "contatti")
			{
				$("#main-text").show();
				$("#cross-bg").show();
			}


			if (page != "contatti"){ $("#main-text").hide();}

			$("#piercing-menu").hide();

			if (page == "dove")
			{
				$("#content-block-1").html($("#dove-top").html());
				$("#content-block-2").html($("#dove-bottom").html());
				$("#content-block-1").show();
				$("#content-block-2").show();
			}
			else
			{
				
				if (page=="piercing")
				{
					$("#piercing-text").show();
					$("#piercing-menu").show();
					show_photo_still("s01", 1);

				}
				else
				{
					$("#content-block").html($("#"+page).html());
					$("#content-block").show();
				}
			}
			$("#overlay").show();
			$("#scroll-bg").show();
			$("#home-link").show();

			clearInterval (crossID);
			clearInterval (autocrossID);


		}
		function open_home_page(page){


			clearInterval (autocrossID);
			crossID = setInterval( crossfade_bg, 6000);
			piercing_page_active = 0;
			$("#cross-bg").show();

			$("#nav_dovesiamo").css("text-decoration", 'none');
			$("#nav_chisiamo").css("text-decoration", 'none');
			$("#nav_piercing").css("text-decoration", 'none');
			$("#nav_photo").css("text-decoration", 'none');
			$("#nav_cartoline").css("text-decoration", 'none');
			$("#nav_certificati").css("text-decoration", 'none');
			$("#nav_video").css("text-decoration", 'none');
			$("#nav_link").css("text-decoration", 'none');

			$('#wrapper').hide();
			$("#email-link").show();
			$(".content_block").hide();
			$("#piercing-text").hide();
			$("#scroll-bg").show();
			$("#main-text").show();
			$("#small-title").html("");
			$("#small-title2").html("");
			$("#big-title").html("");
			$("#big-title2").html("");
			$("#bottom-menu").hide();
			$("#email-link").show();
			$("#home-link").hide();
			$("#piercing-menu").hide();
			$("#home-link").hide();
		}
		function open_photo_page(page){

			$("#photo-lenta").html ("");
			while (photo_array.length>0) {photo_array.pop();}
			if (page == "photos" )
			{
				prev_photo = "s01";
				prev_photo_count = "s01";
				$.each( photos, function(img, title){
					$("#photo-lenta").append('<li><img src="./photos/'+img+'_th.jpg" onclick="show_photo(\''+img+'\')" id="photo'+img+'" rel="'+title+'" /></li>');
					photo_array.push (img);
				});
				$("#nav_photo").css("text-decoration", 'underline');
				$("#nav_cartoline").css("text-decoration", 'none');
				$("#nav_certificati").css("text-decoration", 'none');

			}

			if (page == "photos2" )
			{
				prev_photo = "c01";
				prev_photo_count = "c01";

				$.each( photos2, function(img, title){
					$("#photo-lenta").append('<li><img src="./photos/'+img+'_th.jpg" onclick="show_photo(\''+img+'\')" id="photo'+img+'" rel="'+title+'" /></li>');
					photo_array.push (img);
				});
				$("#nav_cartoline").css("text-decoration", 'underline');
				$("#nav_photo").css("text-decoration", 'none');
				$("#nav_certificati").css("text-decoration", 'none');

			}

			if (page == "photos3" )
			{
				prev_photo = "e01";
				prev_photo_count = "e01";

				$.each( photos3, function(img, title){
					$("#photo-lenta").append('<li><img src="./photos/'+img+'_th.jpg" onclick="show_photo(\''+img+'\')" id="photo'+img+'" rel="'+title+'" /></li>');
					photo_array.push (img);
				});
				$("#nav_certificati").css("text-decoration", 'underline');
				$("#nav_cartoline").css("text-decoration", 'none');
				$("#nav_photo").css("text-decoration", 'none');

			}


			var div = $('div#photo-block'),
				ul = $('ul#photo-lenta'),
				ulPadding = 15;
			
			var divWidth = div.width();
			div.css({overflow: 'hidden'});
			var lastLi = ul.find('li:last-child');
			
			div.mousemove(function(e){
				var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding + ulPadding;
				var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
				div.scrollLeft(left);
			});			

			$('#wrapper').hide();
			$("#nav_dovesiamo").css("text-decoration", 'none');
			$("#nav_chisiamo").css("text-decoration", 'none');
			$("#nav_video").css("text-decoration", 'none');
			$("#nav_piercing").css("text-decoration", 'none');
			$("#nav_link").css("text-decoration", 'none');

			$("#bottom-menu").show();
			$("#email-link").hide();
			$("#home-link").show();
			$(".content_block").hide();
			$("#piercing-text").hide();
			$("#photo-block").show();
			$("#photo-box").show();
			$("#small-title").show();
			$("#small-title2").show();
			$("#big-title").show();
			$("#big-title2").show();
			$("#small-title").html("");
			$("#small-title2").html("");
			$("#big-title").html("");
			$("#big-title2").html("");
			$("#piercing-menu").hide();

			show_photo(prev_photo);

		}



		function open_video_page(){
			clearInterval (autocrossID);
			photo_page_active = 0;
			$("#nav_dovesiamo").css("text-decoration", 'none');
			$("#nav_chisiamo").css("text-decoration", 'none');
			$("#nav_photo").css("text-decoration", 'none');
			$("#nav_cartoline").css("text-decoration", 'none');
			$("#nav_certificati").css("text-decoration", 'none');
			$("#nav_video").css("text-decoration", 'underline');
			$("#nav_piercing").css("text-decoration", 'none');
			$("#nav_link").css("text-decoration", 'none');
			$("#bottom-menu").show();
			$("#email-link").hide();
			$('#wrapper').show();
			$("#scroll-bg").hide();
			$("#cross-bg").hide();
			$(".content_block").hide();
			$("#piercing-text").hide();
			$("#video-block").show();
			$("#video-box").show();
			$("#small-title").show();
			$("#small-title2").show();
			$("#big-title").show();
			$("#big-title2").show();
			$("#small-title").html("");
			$("#small-title2").html("");
			$("#big-title").html("");
			$("#big-title2").html("");
			$("#piercing-menu").hide();	
			$("#home-link").show();			
		}

		function scroll_anchor(n){
			document.getElementById("piercing-text").scrollTop = document.getElementById(n).offsetTop;
		}

		function popupform(myform, windowname)
		{
			if (! window.focus)return true;
			window.open('', windowname, 'left=100,top=100,height=200,width=400,scrollbars=yes');
			myform.target=windowname;
			return true;
		}
